EFI: Implement malloc with {Allocate/Free}Pool()
authorMatt Fleming <matt.fleming@intel.com>
Wed, 14 Dec 2011 22:01:56 +0000 (22:01 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Fri, 16 Dec 2011 16:36:29 +0000 (16:36 +0000)
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
core/mem/malloc.c

index 2908943..d22813d 100644 (file)
@@ -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. */
 }
index d27fc27..dcb5a94 100644 (file)
@@ -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)