diff options
| author | Michael Brown | 2007-01-12 04:28:03 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-12 04:28:03 +0100 |
| commit | 77b7640af4acef9a121e6be9db980a28c59cdeea (patch) | |
| tree | a89c86abb0d5b3d58aea7662c70d778876fe930f /src | |
| parent | Quick and dirty test for emalloc() (diff) | |
| download | ipxe-77b7640af4acef9a121e6be9db980a28c59cdeea.tar.gz ipxe-77b7640af4acef9a121e6be9db980a28c59cdeea.tar.xz ipxe-77b7640af4acef9a121e6be9db980a28c59cdeea.zip | |
Fix the only bug (which was to use DBGC() in place of DBG()!) and add 4kB
alignment.
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/i386/core/emalloc.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/arch/i386/core/emalloc.c b/src/arch/i386/core/emalloc.c index bca35bc15..550e686b8 100644 --- a/src/arch/i386/core/emalloc.c +++ b/src/arch/i386/core/emalloc.c @@ -27,6 +27,9 @@ #include <gpxe/hidemem.h> #include <gpxe/emalloc.h> +/** Alignment of external allocated memory */ +#define EM_ALIGN ( 4 * 1024 ) + /** Equivalent of NOWHERE for user pointers */ #define UNOWHERE ( ~UNULL ) @@ -80,6 +83,7 @@ static void ecollect_free ( void ) { userptr_t erealloc ( userptr_t ptr, size_t new_size ) { struct external_memory extmem; userptr_t new = ptr; + size_t align; /* Initialise external memory allocator if necessary */ if ( ! bottom ) @@ -93,8 +97,8 @@ userptr_t erealloc ( userptr_t ptr, size_t new_size ) { } else { /* Create a zero-length block */ ptr = bottom = userptr_add ( bottom, -sizeof ( extmem ) ); - DBGC ( "EXTMEM allocating [%lx,%lx)\n", - user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) ); + DBG ( "EXTMEM allocating [%lx,%lx)\n", + user_to_phys ( ptr, 0 ), user_to_phys ( ptr, 0 ) ); extmem.size = 0; } extmem.used = ( new_size > 0 ); @@ -103,6 +107,9 @@ userptr_t erealloc ( userptr_t ptr, size_t new_size ) { if ( ptr == bottom ) { /* Update block */ new = userptr_add ( ptr, - ( new_size - extmem.size ) ); + align = ( user_to_phys ( new, 0 ) & ( EM_ALIGN - 1 ) ); + new_size += align; + new = userptr_add ( new, -align ); DBG ( "EXTMEM expanding [%lx,%lx) to [%lx,%lx)\n", user_to_phys ( ptr, 0 ), user_to_phys ( ptr, extmem.size ), |
