ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


IOMemoryDescriptor

Inherits from:
Declared In:

Overview

An abstract base class defining common methods for describing physical or virtual memory.

Discussion

The IOMemoryDescriptor object represents a buffer or range of memory, specified as one or more physical or virtual address ranges. It contains methods to return the memory's physically contiguous segments (fragments), for use with the IOMemoryCursor, and methods to map the memory into any address space with caching and placed mapping options.

Some of the methods in this class require parameters of type task_t. This type refers to a Mach task, which is a unit of resource ownership that consists of a virtual address space, a port-right namespace, and at least one thread. In Mac OS X, each process is based on a Mach task and one or more Mach threads. For more information on the composition of a Mach task and its relationship with Mach threads, see "Tasks and Threads".

The value of the task_t parameter depends on the task into which the memory is being mapped. If the kernel's task is the target of the memory mapping, use the global value kernel_task (note that the definition of kernel_task is automatically included when you #include this header file). To map memory into the task currently running in the kernel, use current_task() to get the task_t value that represents the currently running task.

Note that if current_task() is called from a user client method running in the kernel, it returns the currently running user process, which may or may not be the user process that initiated the user client. To map memory into the task of the user process that initiatied the user client, use the task_t value that was passed into IOUserClient::initWithTask.

To learn more about the virtual memory system in Mac OS X, see "Memory Management in Mac OS X".



Functions

complete

Completes processing of the memory after an I/O transfer finishes.

createMappingInTask

Maps a IOMemoryDescriptor into a task.

getDirection

Accessor to get the direction the memory descriptor was created with.

getLength

Accessor to get the length of the memory descriptor (over all its ranges).

getPhysicalAddress

Returns the physical address of the first byte in the memory.

getPhysicalSegment

Breaks a memory descriptor into its physically contiguous segments.

getTag

Accessor to the retrieve the tag for the memory descriptor.

initWithAddress(vm_address_t, IOByteCount, IODirection, task_t)

Initializes or reinitializes an IOMemoryDescriptor to describe one virtual range of the specified map.

initWithAddress(void *, IOByteCount, IODirection)

Initializes or reinitializes an IOMemoryDescriptor to describe one virtual range of the kernel task.

initWithOptions

Master initializer for all variants of memory descriptors (for a more complete description see withOptions ).

initWithPhysicalAddress

Initializes or reinitializes an IOMemoryDescriptor to describe one physical range.

initWithPhysicalRanges

Initializes or reinitializes an IOMemoryDescriptor to describe one or more physical ranges.

initWithRanges

Initializes or reinitializes an IOMemoryDescriptor to describe one or more virtual ranges.

map(IOOptionBits)

Maps a IOMemoryDescriptor into the kernel map.

map(task_t, IOVirtualAddress, IOOptionBits, IOByteCount, IOByteCount)

Maps a IOMemoryDescriptor into a task - deprecated, only safe for 32 bit tasks. Use createMappingInTask instead.

performOperation

Performs an operation on the memory descriptor's memory.

prepare

Prepares the memory for an I/O transfer.

readBytes

Copy data from the memory descriptor's buffer to the specified buffer.

setMapping

Establishes an already existing mapping.

setPurgeable

Controls the purgeable status of a memory descriptor's memory.

setTag

Set the tag for the memory descriptor.

withAddress(vm_address_t, IOByteCount, IODirection, task_t)

Creates an IOMemoryDescriptor to describe one virtual range of the specified map.

withAddress(void *, IOByteCount, IODirection)

Creates an IOMemoryDescriptor to describe one virtual range of the kernel task.

withAddressRange

Create an IOMemoryDescriptor to describe one virtual range of the specified map.

withAddressRanges

Create an IOMemoryDescriptor to describe one or more virtual ranges.

withOptions

Master initialiser for all variants of memory descriptors.

withPersistentMemoryDescriptor

Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.

withPhysicalAddress

Creates an IOMemoryDescriptor to describe one physical range.

withPhysicalRanges

Creates an IOMemoryDescriptor to describe one or more physical ranges.

withRanges

Create an IOMemoryDescriptor to describe one or more virtual ranges.

withSubRange

Creates an IOMemoryDescriptor to describe a subrange of an existing descriptor.

writeBytes

Copy data to the memory descriptor's buffer from the specified buffer.


complete


Completes processing of the memory after an I/O transfer finishes.

public

virtual IOReturn complete( IODirection forDirection = kIODirectionNone) = 0;
Parameters
forDirection

DEPRECATED The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.

Return Value

An IOReturn code.

Discussion

This method should not be called unless a prepare was previously issued; the prepare and complete() must occur in pairs, before and after an I/O transfer involving pageable memory. In 10.3 or greater systems the direction argument to complete is not longer respected. The direction is totally determined at prepare time.


createMappingInTask


Maps a IOMemoryDescriptor into a task.

public

IOMemoryMap * createMappingInTask( task_t intoTask, mach_vm_address_t atAddress, IOOptionBits options, mach_vm_size_t offset = 0, mach_vm_size_t length = 0 );
Parameters
intoTask

Sets the target task for the mapping. To map into the kernel's task, pass kernel_task. To map into the task currently running in the kernel, use the task_t value returned by current_task(). When calling this method from a user client method running in the kernel, pass the task_t value that was passed into IOUserClient::initWithTask to map into the user process that initiated the user client.

atAddress

If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.

options

Mapping options are defined in IOTypes.h,
kIOMapAnywhere should be passed if the mapping can be created anywhere. If not set, the atAddress parameter sets the location of the mapping, if it is available in the target map.
kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.
kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.
kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.
kIOMapReference will only succeed if the mapping already exists, and the IOMemoryMap object is just an extra reference, ie. no new mapping will be created.
kIOMapUnique allows a special kind of mapping to be created that may be used with the IOMemoryMap::redirect() API. These mappings will not be shared as is the default - there will always be a unique mapping created for the caller, not an existing mapping with an extra reference.

offset

Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.

length

Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.

Return Value

A reference to an IOMemoryMap object representing the mapping, which can supply the virtual address of the mapping and other information. The mapping may be shared with multiple callers - multiple maps are avoided if a compatible one exists. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping. The IOMemoryMap instance also retains the IOMemoryDescriptor it maps while it exists.

Discussion

This is the general purpose method to map all or part of the memory described by a memory descriptor into a task at any available address, or at a fixed address if possible. Caching & read-only options may be set for the mapping. The mapping is represented as a returned reference to a IOMemoryMap object, which may be shared if the mapping is compatible with an existing mapping of the IOMemoryDescriptor. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping.


getDirection


Accessor to get the direction the memory descriptor was created with.

public

virtual IODirection getDirection() const;
Return Value

The direction.

Discussion

This method returns the direction the memory descriptor was created with.


getLength


Accessor to get the length of the memory descriptor (over all its ranges).

public

virtual IOByteCount getLength() const;
Return Value

The byte count.

Discussion

This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.


getPhysicalAddress


Returns the physical address of the first byte in the memory.

public

IOPhysicalAddress getPhysicalAddress();
Return Value

A physical address.

Discussion

This method returns the physical address of the first byte in the memory. It is most useful on memory known to be physically contiguous.


getPhysicalSegment


Breaks a memory descriptor into its physically contiguous segments.

public

virtual IOPhysicalAddress getPhysicalSegment( IOByteCount offset, IOByteCount *length) = 0;
Parameters
offset

A byte offset into the memory whose physical address to return.

length

If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.

Return Value

A physical address, or zero if the offset is beyond the length of the memory.

Discussion

This method returns the physical address of the byte at the given offset into the memory, and optionally the length of the physically contiguous segment from that offset.


getTag


Accessor to the retrieve the tag for the memory descriptor.

public

virtual IOOptionBits getTag( void );
Return Value

The tag.

Discussion

This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.


initWithAddress(vm_address_t, IOByteCount, IODirection, task_t)


Initializes or reinitializes an IOMemoryDescriptor to describe one virtual range of the specified map.

public

virtual bool initWithAddress( vm_address_t address, IOByteCount withLength, IODirection withDirection, task_t withTask) = 0;
Parameters
address

The virtual address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

withTask

The task the virtual range is mapped into. To map into the kernel's task, pass kernel_task. To map into the task currently running in the kernel, use the task_t value returned by current_task(). When calling this method from a user client method running in the kernel, pass the task_t value that was passed into IOUserClient::initWithTask to map into the user process that initiated the user client.

Return Value

true on success, false on failure.

Discussion

This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.


initWithAddress(void *, IOByteCount, IODirection)


Initializes or reinitializes an IOMemoryDescriptor to describe one virtual range of the kernel task.

public

virtual bool initWithAddress( void *address, IOByteCount withLength, IODirection withDirection) = 0;
Parameters
address

The virtual address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

Return Value

true on success, false on failure.

Discussion

This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other I/O Kit classes, although it is supported here.


initWithOptions


Master initializer for all variants of memory descriptors (for a more complete description see withOptions).

public

virtual bool initWithOptions( void *buffers, UInt32 count, UInt32 offset, task_t task, IOOptionBits options, IOMapper *mapper = 0);
Return Value

true on success, false on failure.

Discussion

Note this function can be used to re-init a previously created memory descriptor.


initWithPhysicalAddress


Initializes or reinitializes an IOMemoryDescriptor to describe one physical range.

public

virtual bool initWithPhysicalAddress( IOPhysicalAddress address, IOByteCount withLength, IODirection withDirection ) = 0;
Parameters
address

The physical address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

Return Value

true on success, false on failure.

Discussion

This method initializes an IOMemoryDescriptor for memory consisting of a single physical memory range. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other I/O Kit classes, although it is supported here.


initWithPhysicalRanges


Initializes or reinitializes an IOMemoryDescriptor to describe one or more physical ranges.

public

virtual bool initWithPhysicalRanges( IOPhysicalRange *ranges, UInt32 withCount, IODirection withDirection, bool asReference = false) = 0;
Parameters
ranges

An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.

withCount

The member count of the ranges array.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

asReference

If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.

Return Value

true on success, false on failure.

Discussion

This method initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other I/O Kit classes, although it is supported here.


initWithRanges


Initializes or reinitializes an IOMemoryDescriptor to describe one or more virtual ranges.

public

virtual bool initWithRanges( IOVirtualRange *ranges, UInt32 withCount, IODirection withDirection, task_t withTask, bool asReference = false) = 0;
Parameters
ranges

An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.

withCount

The member count of the ranges array.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

withTask

The task each of the virtual ranges are mapped into. To map into the kernel's task, pass kernel_task. To map into the task currently running in the kernel, use the task_t value returned by current_task(). When calling this method from a user client method running in the kernel, pass the task_t value that was passed into IOUserClient::initWithTask to map into the user process that initiated the user client.

asReference

If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.

Return Value

true on success, false on failure.

Discussion

This method initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task. An IOMemoryDescriptor can be re-used by calling address, IOByteCount withLength, IODirection withDirection, task_t withTask) initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other I/O Kit classes, although it is supported here.


map(IOOptionBits)


Maps a IOMemoryDescriptor into the kernel map.

public

virtual IOMemoryMap * map( IOOptionBits options = 0 );
Parameters
options

Mapping options as in the full version of the createMappingInTask method, with kIOMapAnywhere assumed.

Return Value

See the full version of the createMappingInTask method.

Discussion

This is a shortcut method to map all the memory described by a memory descriptor into the kernel map at any available address. See the full version of the createMappingInTask method for further details.


map(task_t, IOVirtualAddress, IOOptionBits, IOByteCount, IOByteCount)


Maps a IOMemoryDescriptor into a task - deprecated, only safe for 32 bit tasks. Use createMappingInTask instead.

public

virtual IOMemoryMap * map( task_t intoTask, IOVirtualAddress atAddress, IOOptionBits options, IOByteCount offset = 0, IOByteCount length = 0 );
Parameters
intoTask

Sets the target task for the mapping. Pass kernel_task for the kernel address space.

atAddress

If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.

options

Mapping options are defined in IOTypes.h,
kIOMapAnywhere should be passed if the mapping can be created anywhere. If not set, the atAddress parameter sets the location of the mapping, if it is available in the target map.
kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.
kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.
kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.
kIOMapReference will only succeed if the mapping already exists, and the IOMemoryMap object is just an extra reference, ie. no new mapping will be created.
kIOMapUnique allows a special kind of mapping to be created that may be used with the IOMemoryMap::redirect() API. These mappings will not be shared as is the default - there will always be a unique mapping created for the caller, not an existing mapping with an extra reference.

offset

Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.

length

Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.

Return Value

A reference to an IOMemoryMap object representing the mapping, which can supply the virtual address of the mapping and other information. The mapping may be shared with multiple callers - multiple maps are avoided if a compatible one exists. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping. The IOMemoryMap instance also retains the IOMemoryDescriptor it maps while it exists.

Discussion

This is the general purpose method to map all or part of the memory described by a memory descriptor into a task at any available address, or at a fixed address if possible. Caching & read-only options may be set for the mapping. The mapping is represented as a returned reference to a IOMemoryMap object, which may be shared if the mapping is compatible with an existing mapping of the IOMemoryDescriptor. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping.


performOperation


Performs an operation on the memory descriptor's memory.

public

virtual IOReturn performOperation( IOOptionBits options, IOByteCount offset, IOByteCount length );
Parameters
options

The operation to perform on the memory:
kIOMemoryIncoherentIOFlush - pass this option to store to memory and flush any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.
kIOMemoryIncoherentIOStore - pass this option to store to memory any data in the processor cache for the memory range, with synchronization to ensure the data has passed through all levels of processor cache. It may not be supported on all architectures. This type of flush may be used for non-coherent I/O such as AGP - it is NOT required for PCI coherent operations. The memory descriptor must have been previously prepared.

offset

A byte offset into the memory descriptor's memory.

length

The length of the data range.

Return Value

An IOReturn code.

Discussion

This method performs some operation on a range of the memory descriptor's memory. When a memory descriptor's memory is not mapped, it should be more efficient to use this method than mapping the memory to perform the operation virtually.


prepare


Prepares the memory for an I/O transfer.

public

virtual IOReturn prepare( IODirection forDirection = kIODirectionNone) = 0;
Parameters
forDirection

The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.

Return Value

An IOReturn code.

Discussion

This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer. The complete method completes the processing of the memory after the I/O transfer finishes. Note that the prepare call is not thread safe and it is expected that the client will more easily be able to guarantee single threading a particular memory descriptor.


readBytes


Copy data from the memory descriptor's buffer to the specified buffer.

public

virtual IOByteCount readBytes( IOByteCount offset, void *bytes, IOByteCount withLength);
Parameters
offset

A byte offset into the memory descriptor's memory.

bytes

The caller supplied buffer to copy the data to.

withLength

The length of the data to copy.

Return Value

The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor.

Discussion

This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer. The memory descriptor MUST have the kIODirectionOut direcction bit set and be prepared. kIODirectionOut means that this memory descriptor will be output to an external device, so readBytes is used to get memory into a local buffer for a PIO transfer to the device.


setMapping


Establishes an already existing mapping.

public

virtual IOMemoryMap * setMapping( task_t task, IOVirtualAddress mapAddress, IOOptionBits options = 0 );
Parameters
task

Address space in which the mapping exists.

mapAddress

Virtual address of the mapping.

options

Caching and read-only attributes of the mapping.

Return Value

A IOMemoryMap object created to represent the mapping.

Discussion

This method tells the IOMemoryDescriptor about a mapping that exists, but was created elsewhere. It allows later callers of the map method to share this externally created mapping. The IOMemoryMap object returned is created to represent it. This method is not commonly needed.


setPurgeable


Controls the purgeable status of a memory descriptor's memory.

public

virtual IOReturn setPurgeable( IOOptionBits newState, IOOptionBits *oldState );
Parameters
newState

The desired new purgeable state of the memory:
kIOMemoryPurgeableKeepCurrent - make no changes to the memory's purgeable state.
kIOMemoryPurgeableVolatile - make the memory volatile - the memory may be reclaimed by the VM system without saving its contents to backing store.
kIOMemoryPurgeableNonVolatile - make the memory nonvolatile - the memory is treated as with usual allocations and must be saved to backing store if paged.
kIOMemoryPurgeableEmpty - make the memory volatile, and discard any pages allocated to it.

oldState

If non-NULL, the previous purgeable state of the memory is returned here:
kIOMemoryPurgeableNonVolatile - the memory was nonvolatile.
kIOMemoryPurgeableVolatile - the memory was volatile but its content has not been discarded by the VM system.
kIOMemoryPurgeableEmpty - the memory was volatile and has been discarded by the VM system.

Return Value

An IOReturn code.

Discussion

Buffers may be allocated with the ability to have their purgeable status changed - IOBufferMemoryDescriptor with the kIOMemoryPurgeable option, VM_FLAGS_PURGEABLE may be passed to vm_allocate() in user space to allocate such buffers. The purgeable status of such a buffer may be controlled with setPurgeable. The process of making a purgeable memory descriptor non-volatile and determining its previous state is atomic - if a purgeable memory descriptor is made nonvolatile and the old state is returned as kIOMemoryPurgeableVolatile, then the memory's previous contents are completely intact and will remain so until the memory is made volatile again. If the old state is returned as kIOMemoryPurgeableEmpty then the memory was reclaimed while it was in a volatile state and its previous contents have been lost.


setTag


Set the tag for the memory descriptor.

public

virtual void setTag( IOOptionBits tag );
Parameters
tag

The tag.

Discussion

This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.


withAddress(vm_address_t, IOByteCount, IODirection, task_t)


Creates an IOMemoryDescriptor to describe one virtual range of the specified map.

public

static IOMemoryDescriptor * withAddress( vm_address_t address, IOByteCount withLength, IODirection withDirection, task_t withTask);
Parameters
address

The virtual address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

withTask

The task the virtual range is mapped into. To map into the kernel's task, pass kernel_task. To map into the task currently running in the kernel, use the task_t value returned by current_task(). When calling this method from a user client method running in the kernel, pass the task_t value that was passed into IOUserClient::initWithTask to map into the user process that initiated the user client.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.


withAddress(void *, IOByteCount, IODirection)


Creates an IOMemoryDescriptor to describe one virtual range of the kernel task.

public

static IOMemoryDescriptor * withAddress( void *address, IOByteCount withLength, IODirection withDirection);
Parameters
address

The virtual address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.


withAddressRange


Create an IOMemoryDescriptor to describe one virtual range of the specified map.

public

static IOMemoryDescriptor * withAddressRange( mach_vm_address_t address, mach_vm_size_t length, IOOptionBits options, task_t task);
Parameters
address

The virtual address of the first byte in the memory.

withLength

The length of memory.

options

kIOMemoryDirectionMask (options:direction) This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

task

The task the virtual ranges are mapped into. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.


withAddressRanges


Create an IOMemoryDescriptor to describe one or more virtual ranges.

public

static IOMemoryDescriptor * withAddressRanges( IOAddressRange *ranges, UInt32 rangeCount, IOOptionBits options, task_t withTask);
Parameters
ranges

An array of IOAddressRange structures which specify the virtual ranges in the specified map which make up the memory to be described. IOAddressRange is the 64bit version of IOVirtualRange.

rangeCount

The member count of the ranges array.

options

kIOMemoryDirectionMask (options:direction) This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures. kIOMemoryAsReference For options:type = Virtual or Physical this indicate that the memory descriptor need not copy the ranges array into local memory. This is an optimisation to try to minimise unnecessary allocations.

task

The task each of the virtual ranges are mapped into. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api.


withOptions


Master initialiser for all variants of memory descriptors.

public

static IOMemoryDescriptor *withOptions( void *buffers, UInt32 count, UInt32 offset, task_t task, IOOptionBits options, IOMapper *mapper = 0);
Parameters
buffers

A pointer to an array of IOVirtualRanges or IOPhysicalRanges if the options:type is Virtual or Physical. For type UPL it is a upl_t returned by the mach/memory_object_types.h apis, primarily used internally by the UBC.

count

options:type = Virtual or Physical count contains a count of the number of entires in the buffers array. For options:type = UPL this field contains a total length.

offset

Only used when options:type = UPL, in which case this field contains an offset for the memory within the buffers upl.

task

Only used options:type = Virtual, The task each of the virtual ranges are mapped into.

options

kIOMemoryDirectionMask (options:direction) This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures. kIOMemoryTypeMask (options:type) kIOMemoryTypeVirtual, kIOMemoryTypePhysical, kIOMemoryTypeUPL Indicates that what type of memory basic memory descriptor to use. This sub-field also controls the interpretation of the buffers, count, offset & task parameters. kIOMemoryAsReference For options:type = Virtual or Physical this indicate that the memory descriptor need not copy the ranges array into local memory. This is an optimisation to try to minimise unnecessary allocations. kIOMemoryBufferPageable Only used by the IOBufferMemoryDescriptor as an indication that the kernel virtual memory is in fact pageable and we need to use the kernel pageable submap rather than the default map. kIOMemoryNoAutoPrepare Indicates that the temporary AutoPrepare of kernel_task memory should not be performed.

mapper

Which IOMapper should be used to map the in-memory physical addresses into I/O space addresses. Defaults to 0 which indicates that the system mapper is to be used, if present.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory it has three main variants: Virtual, Physical & mach UPL. These variants are selected with the options parameter, see below. This memory descriptor needs to be prepared before it can be used to extract data from the memory described. However we temporarily have setup a mechanism that automatically prepares kernel_task memory descriptors at creation time.


withPersistentMemoryDescriptor


Copy constructor that generates a new memory descriptor if the backing memory for the same task's virtual address and length has changed.

public

static IOMemoryDescriptor * withPersistentMemoryDescriptor( IOMemoryDescriptor *originalMD);
Return Value

Either the original memory descriptor with an additional retain or a new memory descriptor, 0 for a bad original memory descriptor or some other resource shortage.

Discussion

If the original memory descriptor's address and length is still backed by the same real memory, i.e. the user hasn't deallocated and the reallocated memory at the same address then the original memory descriptor is returned with a additional reference. Otherwise we build a totally new memory descriptor with the same characteristics as the previous one but with a new view of the vm. Note that it is not legal to call this function with anything except an IOGeneralMemoryDescriptor that was created with the kIOMemoryPersistent option.


withPhysicalAddress


Creates an IOMemoryDescriptor to describe one physical range.

public

static IOMemoryDescriptor * withPhysicalAddress( IOPhysicalAddress address, IOByteCount withLength, IODirection withDirection );
Parameters
address

The physical address of the first byte in the memory.

withLength

The length of memory.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.


withPhysicalRanges


Creates an IOMemoryDescriptor to describe one or more physical ranges.

public

static IOMemoryDescriptor * withPhysicalRanges( IOPhysicalRange *ranges, UInt32 withCount, IODirection withDirection, bool asReference = false);
Parameters
ranges

An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.

withCount

The member count of the ranges array.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

asReference

If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.


withRanges


Create an IOMemoryDescriptor to describe one or more virtual ranges.

public

static IOMemoryDescriptor * withRanges( IOVirtualRange *ranges, UInt32 withCount, IODirection withDirection, task_t withTask, bool asReference = false);
Parameters
ranges

An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.

withCount

The member count of the ranges array.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.

withTask

The task each of the virtual ranges are mapped into. To map into the kernel's task, pass kernel_task. To map into the task currently running in the kernel, use the task_t value returned by current_task(). When calling this method from a user client method running in the kernel, pass the task_t value that was passed into IOUserClient::initWithTask to map into the user process that initiated the user client.

asReference

If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task.


withSubRange


Creates an IOMemoryDescriptor to describe a subrange of an existing descriptor.

public

static IOMemoryDescriptor * withSubRange( IOMemoryDescriptor *of, IOByteCount offset, IOByteCount length, IODirection withDirection);
Parameters
of

The parent IOMemoryDescriptor of which a subrange is to be used for the new descriptor, which will be retained by the subrange IOMemoryDescriptor.

offset

A byte offset into the parent memory descriptor's memory.

length

The length of the subrange.

withDirection

An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures. This is used over the direction of the parent descriptor.

Return Value

The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure.

Discussion

This method creates and initializes an IOMemoryDescriptor for memory consisting of a subrange of the specified memory descriptor. The parent memory descriptor is retained by the new descriptor.


writeBytes


Copy data to the memory descriptor's buffer from the specified buffer.

public

virtual IOByteCount writeBytes( IOByteCount offset, const void * bytes, IOByteCount withLength);
Parameters
offset

A byte offset into the memory descriptor's memory.

bytes

The caller supplied buffer to copy the data from.

withLength

The length of the data to copy.

Return Value

The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor.

Discussion

This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer. The memory descriptor MUST have the kIODirectionIn direcction bit set and be prepared. kIODirectionIn means that this memory descriptor will be input from an external device, so writeBytes is used to write memory into the descriptor for PIO drivers.

Structs and Unions


ExpansionData


protected

struct ExpansionData { void *devicePager; unsigned int pagerContig:1; unsigned int unused:31; IOMemoryDescriptor *memory; };
Discussion

This structure will be used to expand the capablilties of this class in the future.

Member Data


reserved


protected

ExpansionData * reserved;
Discussion

Reserved for future use. (Internal use only)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19