These are kernel versions of the functions in malloc(2). They
allocate memory with Quickfit with an allocator from Kernighan
& Ritchie. The allocation is currently fixed, but could call physalloc(9nix)
in the future. All but smalloc (which calls sleep(9)) may safely
be called by interrupt handlers.
Malloc returns a pointer to a block of at least size bytes, initialised
to zero. The block is suitably aligned for storage of any type
of object. The call malloc(0) returns a valid pointer rather than
null. Mallocz is similar, but only clears the memory if clr is
Smalloc returns a pointer to a block of size bytes, initialised
to zero. If the memory is not immediately available, smalloc retries
every 100 milliseconds until the memory is acquired.
Mallocalign allocates a block of at least n bytes of memory respecting
alignment contraints. If align is non–zero, the returned pointer
is aligned to be equal to offset modulo align. If span is non–zero,
the n byte block allocated will not span a span–byte boundary.
Realloc changes the size of the block pointed to by p to size
bytes, if possible without moving the data, and returns a pointer
to the block. The contents are unchanged up to the lesser of old
and new sizes, and any new space allocated is initialised to zero.
Realloc takes on special meanings when one or both
arguments are zero:|
means malloc(size); returns a pointer to the newly–allocated memory|
means free(ptr); returns null|
Calloc returns a pointer to a block of memory of at least n*szelem
bytes, initialised to zero. New code should use mallocz instead.
The argument to free is a pointer to a block of memory allocated
by one of the routines above, which is returned to the allocation
pool, or a null pointer, which is ignored.
When a block is allocated, sometimes there is some extra unused
space at the end. Msize grows the block to encompass this unused
space and returns the new number of bytes that may be used.
The memory allocator does not maintain ``malloc tag'' and the
``realloc tag'', but the functions setmalloctag, getmalloctag,
setrealloctag, and getrealloctag are provided for compaibility
with the pool(2) library.
Mallocinit must be called before malloc is used. Mallocsummary
prints a short summary of the allocator's state on the console.