[umalloc] Formalise the user memory allocation API

This commit is contained in:
Michael Brown
2008-10-13 04:32:11 +01:00
parent 6554b79ff9
commit 831e4cfc27
7 changed files with 95 additions and 30 deletions

View File

@@ -6,7 +6,7 @@
* @{
*/
#define ERRFILE_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
#define ERRFILE_memtop_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
#define ERRFILE_memmap ( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 )
#define ERRFILE_pnpbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 )
#define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )

View File

@@ -0,0 +1,12 @@
#ifndef _BITS_UMALLOC_H
#define _BITS_UMALLOC_H
/** @file
*
* i386-specific user memory allocation API implementations
*
*/
#include <gpxe/memtop_umalloc.h>
#endif /* _BITS_UMALLOC_H */

View File

@@ -0,0 +1,16 @@
#ifndef _GPXE_MEMTOP_UMALLOC_H
#define _GPXE_MEMTOP_UMALLOC_H
/** @file
*
* External memory allocation
*
*/
#ifdef UMALLOC_MEMTOP
#define UMALLOC_PREFIX_memtop
#else
#define UMALLOC_PREFIX_memtop __memtop_
#endif
#endif /* _GPXE_MEMTOP_UMALLOC_H */

View File

@@ -36,9 +36,6 @@
/** Equivalent of NOWHERE for user pointers */
#define UNOWHERE ( ~UNULL )
/** Start of Etherboot text, as defined by the linker */
extern char _text[];
/** An external memory block */
struct external_memory {
/** Size of this memory block (excluding this header) */
@@ -135,7 +132,7 @@ static void ecollect_free ( void ) {
* Calling realloc() with a new size of zero is a valid way to free a
* memory block.
*/
userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
struct external_memory extmem;
userptr_t new = ptr;
size_t align;
@@ -200,25 +197,4 @@ userptr_t urealloc ( userptr_t ptr, size_t new_size ) {
return ( new_size ? new : UNOWHERE );
}
/**
* Allocate external memory
*
* @v size Requested size
* @ret ptr Memory, or UNULL
*
* Memory is guaranteed to be aligned to a page boundary.
*/
userptr_t umalloc ( size_t size ) {
return urealloc ( UNULL, size );
}
/**
* Free external memory
*
* @v ptr Memory allocated by umalloc(), or UNULL
*
* If @c ptr is UNULL, no action is taken.
*/
void ufree ( userptr_t ptr ) {
urealloc ( ptr, 0 );
}
PROVIDE_UMALLOC ( memtop, urealloc, memtop_urealloc );