[syslinux:firmware] EFI: Implement malloc with {Allocate/Free}Pool ()

syslinux-bot for Matt Fleming matt.fleming at intel.com
Fri Nov 9 09:06:09 PST 2012


Commit-ID:  da5675bb1b93493959379c108c5d02ee9285a3ef
Gitweb:     http://www.syslinux.org/commit/da5675bb1b93493959379c108c5d02ee9285a3ef
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Wed, 14 Dec 2011 22:01:56 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 16 Dec 2011 16:36:29 +0000

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.

---
 core/mem/free.c   |    4 ++++
 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 2908943..d22813d 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 d27fc27..dcb5a94 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)


More information about the Syslinux-commits mailing list