3 malloc, mallocz, smalloc, realloc, free, msize, secalloc, secfree, setmalloctag, setrealloctag, getmalloctag, getrealloctag \- kernel memory allocator
7 void* malloc(ulong size)
10 void* mallocalign(ulong size, ulong align, long offset, ulong span)
13 void* mallocz(ulong size, int clr)
16 void* smalloc(ulong size)
19 void* realloc(void *p, ulong size)
25 ulong msize(void *ptr)
28 void* secalloc(ulong size)
31 void secfree(void *ptr)
34 void setmalloctag(void *ptr, ulong tag)
37 ulong getmalloctag(void *ptr)
40 void setrealloctag(void *ptr, ulong tag)
43 ulong getrealloctag(void *ptr)
46 These are kernel versions of the functions in
48 They allocate memory from the
54 which in turn replenishes the pool as required by calling
60 may safely be called by interrupt handlers.
63 returns a pointer to a block of at least
65 bytes, initialised to zero.
66 The block is suitably aligned for storage of any type of object.
69 returns a valid pointer rather than null.
71 is similar, but only clears the memory if
76 returns a pointer to a block of
78 bytes, initialised to zero.
79 If the memory is not immediately available,
81 retries every 100 milliseconds until the memory is acquired.
84 allocates a block of at least
86 bytes of memory respecting alignment contraints.
90 the returned pointer is aligned to be equal to
99 byte block allocated will not span a
104 changes the size of the block pointed to by
109 if possible without moving the data,
110 and returns a pointer to the block.
111 The contents are unchanged up to the lesser of old and new sizes,
112 and any new space allocated is initialised to zero.
114 takes on special meanings when one or both arguments are zero:
116 .B "realloc(0,\ size)
119 returns a pointer to the newly-allocated memory
132 is a pointer to a block of memory allocated by one of the routines above, which
133 is returned to the allocation pool, or a null pointer, which is ignored.
135 When a block is allocated, sometimes there is some extra unused space at the end.
137 grows the block to encompass this unused space and returns the new number
138 of bytes that may be used.
143 are security-aware functions that use a pool flagged by
147 which fills every allocated block with garbage before and after its
148 use, to prevent leakage.
150 The memory allocator maintains two word-sized fields
151 associated with each block, the ``malloc tag'' and the ``realloc tag''.
152 By convention, the malloc tag is the PC that allocated the block,
153 and the realloc tag the PC that last reallocated the block.
154 These may be set or examined with
160 When allocating blocks directly with
164 these tags will be set properly.
165 If a custom allocator wrapper is used,
166 the allocator wrapper can set the tags
167 itself (usually by passing the result of
171 to provide more useful information about
172 the source of allocation.
174 .B /sys/src/9/port/alloc.c
178 return a null pointer if space is unavailable.
179 If the allocated blocks have no malloc or realloc tags,