diff options
author | Matt Fleming <matt.fleming@intel.com> | 2011-12-14 22:01:56 +0000 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2011-12-16 16:36:29 +0000 |
commit | da5675bb1b93493959379c108c5d02ee9285a3ef (patch) | |
tree | 4e28b7c4ec5b6e3b4b5116bce0bdc17276520c47 | |
parent | 4567631499532d5515abbaeffe792ca50bba6be5 (diff) | |
download | syslinux-da5675bb1b93493959379c108c5d02ee9285a3ef.tar.gz syslinux-da5675bb1b93493959379c108c5d02ee9285a3ef.tar.xz syslinux-da5675bb1b93493959379c108c5d02ee9285a3ef.zip |
EFI: Implement malloc with {Allocate/Free}Pool()
We actually need to AllocatePool() the memory we want, otherwise the
firmware can use it behind our backs. Since EFI firmware doesn't
provide an interface for allocating memory at a specific address if
the requested size isn't a multiple of PAGE_SIZE, use the pool
functions.
-rw-r--r-- | core/mem/free.c | 4 | ||||
-rw-r--r-- | core/mem/malloc.c | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/core/mem/free.c b/core/mem/free.c index 2908943b..d22813d4 100644 --- a/core/mem/free.c +++ b/core/mem/free.c @@ -75,6 +75,9 @@ void free(void *ptr) if ( !ptr ) return; +#ifdef SYSLINUX_EFI + FreePool(ptr); +#else ah = (struct free_arena_header *) ((struct arena_header *)ptr - 1); @@ -83,6 +86,7 @@ void free(void *ptr) #endif __free_block(ah); +#endif /* Here we could insert code to return memory to the system. */ } diff --git a/core/mem/malloc.c b/core/mem/malloc.c index d27fc270..dcb5a942 100644 --- a/core/mem/malloc.c +++ b/core/mem/malloc.c @@ -69,6 +69,9 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag) dprintf("_malloc(%zu, %u, %u) @ %p = ", size, heap, tag, __builtin_return_address(0)); +#ifdef SYSLINUX_EFI + p = AllocatePool(size); +#else if (size) { /* Add the obligatory arena header, and round up */ size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK; @@ -81,6 +84,7 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag) } } } +#endif dprintf("%p\n", p); return p; @@ -109,6 +113,11 @@ void *realloc(void *ptr, size_t size) void *newptr; size_t newsize, oldsize, xsize; +#ifdef SYSLINUX_EFI + newptr = AllocatePool(size); + memcpy(newptr, ptr, size); + FreePool(ptr); +#else if (!ptr) return malloc(size); @@ -200,6 +209,7 @@ void *realloc(void *ptr, size_t size) return newptr; } } +#endif } void *zalloc(size_t size) |