mirror of https://github.com/ipxe/ipxe.git
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.pull/1/head
parent
5ff23aa406
commit
6d4e37cf42
|
@ -1,4 +1,4 @@
|
||||||
#include <malloc.h>
|
#include <gpxe/malloc.h>
|
||||||
#include <gpxe/heap.h>
|
#include <gpxe/heap.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <gpxe/list.h>
|
#include <gpxe/list.h>
|
||||||
#include <malloc.h>
|
#include <gpxe/malloc.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
*
|
*
|
||||||
|
@ -69,6 +69,9 @@ struct autosized_block {
|
||||||
/** List of free memory blocks */
|
/** List of free memory blocks */
|
||||||
static LIST_HEAD ( free_blocks );
|
static LIST_HEAD ( free_blocks );
|
||||||
|
|
||||||
|
/** Total amount of free memory */
|
||||||
|
size_t freemem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a memory block
|
* Allocate a memory block
|
||||||
*
|
*
|
||||||
|
@ -134,6 +137,9 @@ void * alloc_memblock ( size_t size, size_t align ) {
|
||||||
*/
|
*/
|
||||||
if ( pre_size < MIN_MEMBLOCK_SIZE )
|
if ( pre_size < MIN_MEMBLOCK_SIZE )
|
||||||
list_del ( &pre->list );
|
list_del ( &pre->list );
|
||||||
|
/* Update total free memory */
|
||||||
|
freemem -= size;
|
||||||
|
/* Return allocated block */
|
||||||
DBG ( "Allocated [%p,%p)\n", block,
|
DBG ( "Allocated [%p,%p)\n", block,
|
||||||
( ( ( void * ) block ) + size ) );
|
( ( ( void * ) block ) + size ) );
|
||||||
return block;
|
return block;
|
||||||
|
@ -206,6 +212,9 @@ void free_memblock ( void *ptr, size_t size ) {
|
||||||
freeing->size += block->size;
|
freeing->size += block->size;
|
||||||
list_del ( &block->list );
|
list_del ( &block->list );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update free memory counter */
|
||||||
|
freemem += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _MALLOC_H
|
#ifndef _GPXE_MALLOC_H
|
||||||
#define _MALLOC_H
|
#define _GPXE_MALLOC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prototypes for the standard functions (malloc() et al) are in
|
* Prototypes for the standard functions (malloc() et al) are in
|
||||||
* stdlib.h. Include <malloc.h> only if you need the non-standard
|
* stdlib.h. Include <gpxe/malloc.h> only if you need the
|
||||||
* functions, such as malloc_dma().
|
* non-standard functions, such as malloc_dma().
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern size_t freemem;
|
||||||
|
|
||||||
extern void * alloc_memblock ( size_t size, size_t align );
|
extern void * alloc_memblock ( size_t size, size_t align );
|
||||||
extern void free_memblock ( void *ptr, size_t size );
|
extern void free_memblock ( void *ptr, size_t size );
|
||||||
extern void mpopulate ( void *start, size_t len );
|
extern void mpopulate ( void *start, size_t len );
|
||||||
|
@ -52,4 +54,4 @@ static inline void free_dma ( void *ptr, size_t size ) {
|
||||||
free_memblock ( ptr, size );
|
free_memblock ( ptr, size );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _MALLOC_H */
|
#endif /* _GPXE_MALLOC_H */
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <malloc.h>
|
#include <gpxe/malloc.h>
|
||||||
#include <gpxe/pkbuff.h>
|
#include <gpxe/pkbuff.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
|
Loading…
Reference in New Issue