diff options
| author | Michael Brown | 2007-01-18 21:11:04 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-18 21:11:04 +0100 |
| commit | 6d4e37cf42a16c1e0b2393efe4902a2030907dbe (patch) | |
| tree | aa880f0549e7a70ff913183099ba17db056aad47 /src/include/gpxe | |
| parent | Include stdlib.h rather than malloc.h (diff) | |
| download | ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.tar.gz ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.tar.xz ipxe-6d4e37cf42a16c1e0b2393efe4902a2030907dbe.zip | |
Move include/malloc.h to include/gpxe/malloc.h, since everything in there
is now gPXE-specific. (The standard malloc() et al have been in stdlib.h
for a while).
Add free memory counter.
Diffstat (limited to 'src/include/gpxe')
| -rw-r--r-- | src/include/gpxe/malloc.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/include/gpxe/malloc.h b/src/include/gpxe/malloc.h new file mode 100644 index 000000000..0e18f6a35 --- /dev/null +++ b/src/include/gpxe/malloc.h @@ -0,0 +1,57 @@ +#ifndef _GPXE_MALLOC_H +#define _GPXE_MALLOC_H + +#include <stdint.h> + +/** @file + * + * Dynamic memory allocation + * + */ + +/* + * Prototypes for the standard functions (malloc() et al) are in + * stdlib.h. Include <gpxe/malloc.h> only if you need the + * non-standard functions, such as malloc_dma(). + * + */ +#include <stdlib.h> + +extern size_t freemem; + +extern void * alloc_memblock ( size_t size, size_t align ); +extern void free_memblock ( void *ptr, size_t size ); +extern void mpopulate ( void *start, size_t len ); +extern void mdumpfree ( void ); + +/** + * Allocate memory for DMA + * + * @v size Requested size + * @v align Physical alignment + * @ret ptr Memory, or NULL + * + * Allocates physically-aligned memory for DMA. + * + * @c align must be a power of two. @c size may not be zero. + */ +static inline void * malloc_dma ( size_t size, size_t phys_align ) { + return alloc_memblock ( size, phys_align ); +} + +/** + * Free memory allocated with malloc_dma() + * + * @v ptr Memory allocated by malloc_dma(), or NULL + * @v size Size of memory, as passed to malloc_dma() + * + * Memory allocated with malloc_dma() can only be freed with + * free_dma(); it cannot be freed with the standard free(). + * + * If @c ptr is NULL, no action is taken. + */ +static inline void free_dma ( void *ptr, size_t size ) { + free_memblock ( ptr, size ); +} + +#endif /* _GPXE_MALLOC_H */ |
