DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5

kmem_zalloc(D3)


kmem_zalloc -- allocate and clear space from kernel free memory

Synopsis

   #include <sys/types.h>
   #include <sys/kmem.h>
   #include <sys/ddi.h>
   

void *kmem_zalloc(size_t size, int flag);

Description

kmem_zalloc allocates size bytes of kernel memory, clears the memory by filling it with zeros, and returns a pointer to the allocated memory.

Arguments


size
Number of bytes to allocate.

flag
Specifies whether the caller is willing to sleep waiting for 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_zalloc will return NULL if the specified amount of memory is not immediately available.

Return values

Upon successful completion, kmem_zalloc( ) returns a pointer to the allocated memory. If KM_NOSLEEP is specified and sufficient memory is not immediately available, kmem_zalloc( ) returns a NULL pointer. If size is set to 0, kmem_zalloc( ) returns NULL, regardless of the value of flag.

The address returned by a successful call to kmem_zalloc is word-aligned.

Usage

Drivers should not assume that memory allocated by kmem_zalloc( ) 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 context.

If flag is set to KM_SLEEP, user context.

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp

Differences between versions

In versions 1, 2, 3, 4, 5, and 5mp, the memory returned by kmem_zalloc is DMA-able; that is, it will satisfy worst-case DMA-ability requirements on systems with restricted DMA; see phys_dmasize of physreq(D4). In versions 1, 2, 3, and 4, the memory returned will also be physically contiguous, if possible (guaranteed if size is less than or equal to ptob(1)). For other versions, there are no guarantees on the memory properties.

kmem_zalloc( ) is also supported on SCO OpenServer, but memory allocated is DMA-able (contiguous) unless the KM_NO_DMA flag is specified

Beginning with DDI version 8, memory with specific physical properties can be allocated with the kmem_alloc_phys(D3) function. Beginning with DDI version 6, memory with specific physical properties can be obtained through kmem_alloc_physreq(D3), or kmem_zalloc_physreq(D3). In DDI version 5, contiguous memory with specific physical properties can be obtained through kmem_alloc_physcontig(D3).

References

kmem_alloc(D3), kmem_alloc_physcontig(D3), kmem_alloc_physreq(D3), kmem_free(D3), kmem_free_physcontig(D3), kmem_zalloc_physreq(D3)

``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