.TH kmem_alloc() "" "" "DDI/DKI Kernel Routine"
.PC "Allocate space from kernel free memory"
.B "#include <sys/types.h>"
.B "#include <sys/kmem.h>"
\fBvoid *kmem_alloc(\fIbytes\^\fB, \fIflag\^\fB)\fR
\fBsize_t \fIbytes\^\fB; int \fIflag\^\fB;\fR
.PP
.B kmem_alloc()
allocates
.I bytes
of kernel memory.
.PP
.I flag
indicates whether the driver can sleep while waiting for memory.
.B KM_SLEEP
indicates that the driver will sleep, if necessary,
until the requested amount of memory is available; therefore,
.B kmem_alloc()
waits until
.I bytes
of memory is available.
.B KM_NOSLEEP
indicates that it will not sleep; therefore,
.B kmem_alloc()
returns NULL if the requested amount of memory is not available immediately.
.PP
.B kmem_alloc()
returns a pointer to the newly allocated memory.
If
.I flag
is set to
.B KM_NOSLEEP
and
.I bytes
of memory is not available, it returns NULL.
It always returns NULL if you set
.I bytes
to zero.
.SH "See Also"
.B
DDI/DKI kernel routines,
kmem_free(),
kmem_zalloc()
.R
.SH Notes
.B kmem_alloc()
has base level only if
.I flag
equals
.BR KM_SLEEP ;
it has base or interrupt level if
.I flag
equals
.BR KM_NOSLEEP .
It can sleep if
.I flag
is set to
.BR KM_SLEEP .
.PP
A driver can hold a driver-defined basic lock or read/write lock across
a call to this function if
.I flag
is
.BR KM_NOSLEEP ,
but may not hold it if
.I flag
is
.BR KM_SLEEP .
It can hold a driver-defined sleep lock regardless of the value of
.IR flag .
