8 * Dynamic memory allocation
12 extern void * alloc_memblock ( size_t size
, size_t align
);
13 extern void free_memblock ( void *ptr
, size_t size
);
14 extern void * malloc ( size_t size
);
15 extern void free ( void *ptr
);
16 extern void mpopulate ( void *start
, size_t len
);
17 extern void mdumpfree ( void );
20 * Allocate memory for DMA
22 * @v size Requested size
23 * @v align Physical alignment
24 * @ret ptr Memory, or NULL
26 * Allocates physically-aligned memory for DMA.
28 * @c align must be a power of two. @c size may not be zero.
30 static inline void * malloc_dma ( size_t size
, size_t phys_align
) {
31 return alloc_memblock ( size
, phys_align
);
35 * Free memory allocated with malloc_dma()
37 * @v ptr Memory allocated by malloc_dma(), or NULL
38 * @v size Size of memory, as passed to malloc_dma()
40 * Memory allocated with malloc_dma() can only be freed with
41 * free_dma(); it cannot be freed with the standard free().
43 * If @c ptr is NULL, no action is taken.
45 static inline void free_dma ( void *ptr
, size_t size
) {
46 free_memblock ( ptr
, size
);
50 * Allocate cleared memory
52 * @v nmemb Number of members
53 * @v size Size of each member
54 * @ret ptr Allocated memory
56 * Allocate memory as per malloc(), and zero it.
58 * Note that malloc() and calloc() are identical, in the interests of
59 * reducing code size. Callers should not, however, rely on malloc()
60 * clearing memory, since this behaviour may change in future.
62 static inline void * calloc ( size_t nmemb
, size_t size
) {
63 return malloc ( nmemb
* size
);
66 #endif /* _MALLOC_H */