allocate space from kernel free memory
void *kmem_alloc(size_t size, int flag);
kmem_alloc allocates size bytes of kernel
memory and returns a pointer to the allocated memory.
If flag is set to KM_SLEEP, the caller will sleep
if necessary until the specified amount of memory is available.
If flag is set to KM_NOSLEEP, the caller will not sleep,
but kmem_alloc will return NULL if the specified amount
of memory is not immediately available.
Number of bytes to allocate.
Specifies whether the caller is willing to sleep waiting for memory.
Upon successful completion,
returns a pointer to the allocated memory.
If KM_NOSLEEP is specified
and sufficient memory is not immediately available,
returns a NULL pointer.
If size is set to 0,
kmem_alloc returns NULL,
regardless of the value of flag.
The address returned by a successful call to
Drivers should not assume that memory allocated by
is usable for DMA operations,
nor should drivers assume that the memory has any specific
physical properties such as starting address alignment,
physical address range, or physical contiguity.
Context and synchronization
If flag is set to KM_NOSLEEP,
non-blockable, initialization, or interrupt
If flag is set to KM_SLEEP,
1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp
Differences between versions
In DDI versions 1, 2, 3, 4, 5, and 5mp,
the memory returned by
is all below 16MB
and thus in the range for 24-bit DMA.
In other words, it satisfies worst-case DMA-ability requirements
on systems with restricted DMA;
In versions 1, 2, 3, and 4,
the memory returned is also physically contiguous,
which is required for DMA
that does not utilize scatter/gather.
For other versions, there are no guarantees on the memory properties.
Beginning with DDI version 6,
memory with specific physical properties can be obtained through
In DDI version 5,
contiguous memory with specific physical properties
can be obtained through
The DDI 6, 6mp, 7, and 7mp versions
do not know about memory greater than 4GB
so the memory allocated by all forms of the
function is below 4GB.
SCO OpenServer ODDI compatibility
On SCO OpenServer, memory allocated with
is always below the 16MB boundary
unless the KM_NO_DMA flag is specified.
Only memory that will be accessed by
ISA DMA devices
needs to be below the 16MB boundary,
so when porting from SVR5 to SCO OpenServer,
you should usually specify the KM_NO_DMA flag to
Memory allocated by the SCO OpenServer
may or may not be contiguous.
``Memory allocation'' in HDK Technical Reference
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005