#include <strings.h>
#include <io.h>
#include <gpxe/list.h>
-#include <malloc.h>
+#include <gpxe/malloc.h>
/** @file
*
/** List of free memory blocks */
static LIST_HEAD ( free_blocks );
+/** Total amount of free memory */
+size_t freemem;
+
/**
* Allocate a memory block
*
*/
if ( pre_size < MIN_MEMBLOCK_SIZE )
list_del ( &pre->list );
+ /* Update total free memory */
+ freemem -= size;
+ /* Return allocated block */
DBG ( "Allocated [%p,%p)\n", block,
( ( ( void * ) block ) + size ) );
return block;
freeing->size += block->size;
list_del ( &block->list );
}
+
+ /* Update free memory counter */
+ freemem += size;
}
/**
-#ifndef _MALLOC_H
-#define _MALLOC_H
+#ifndef _GPXE_MALLOC_H
+#define _GPXE_MALLOC_H
#include <stdint.h>
/*
* Prototypes for the standard functions (malloc() et al) are in
- * stdlib.h. Include <malloc.h> only if you need the non-standard
- * functions, such as malloc_dma().
+ * 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 );
free_memblock ( ptr, size );
}
-#endif /* _MALLOC_H */
+#endif /* _GPXE_MALLOC_H */