aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@FreeBSD.org>2020-06-30 21:48:58 +0000
committerToomas Soome <tsoome@FreeBSD.org>2020-06-30 21:48:58 +0000
commit12c470af750672c4847af20cc8e2a736aab7db78 (patch)
tree5e934c7b07209c61e5e80f35bd8009045ed436c6
parentebc22d04956625fd351d57d791171a6e0c653c45 (diff)
downloadsrc-12c470af750672c4847af20cc8e2a736aab7db78.tar.gz
src-12c470af750672c4847af20cc8e2a736aab7db78.zip
boot1.efi: use malloc family from libsa
The zfs reader development did reach to the point where linking boot1, we will get errors about duplicate symbols Malloc, Free, Calloc. We can just use libsa version, just as loader.efi does. The only concern is, libsa zalloc is using fixed size heap region, I did pick 64MB as other stage instances are using, but this size is likely not optimal. In any case, with limited memory setups, we should boot loader.efi directly. Sponsored by: Netflix, Klara Inc.
Notes
Notes: svn path=/head/; revision=362812
-rw-r--r--stand/efi/boot1/boot1.c52
1 files changed, 16 insertions, 36 deletions
diff --git a/stand/efi/boot1/boot1.c b/stand/efi/boot1/boot1.c
index 22bff7f10fba..088821ecd1f8 100644
--- a/stand/efi/boot1/boot1.c
+++ b/stand/efi/boot1/boot1.c
@@ -53,42 +53,8 @@ static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
-/*
- * Provide Malloc / Free / Calloc backed by EFIs AllocatePool / FreePool which ensures
- * memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from
- * EFI methods.
- */
-
-void *
-Malloc(size_t len, const char *file __unused, int line __unused)
-{
- void *out;
-
- if (BS->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
- return (out);
-
- return (NULL);
-}
-
-void
-Free(void *buf, const char *file __unused, int line __unused)
-{
- if (buf != NULL)
- (void)BS->FreePool(buf);
-}
-
-void *
-Calloc(size_t n1, size_t n2, const char *file, int line)
-{
- size_t bytes;
- void *res;
-
- bytes = n1 * n2;
- if ((res = Malloc(bytes, file, line)) != NULL)
- bzero(res, bytes);
-
- return (res);
-}
+static EFI_PHYSICAL_ADDRESS heap;
+static UINTN heapsize;
/*
* try_boot only returns if it fails to load the loader. If it succeeds
@@ -201,6 +167,18 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
BS = ST->BootServices;
RS = ST->RuntimeServices;
+ heapsize = 64 * 1024 * 1024;
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
+ EFI_SIZE_TO_PAGES(heapsize), &heap);
+ if (status != EFI_SUCCESS) {
+ ST->ConOut->OutputString(ST->ConOut,
+ __DECONST(CHAR16 *,
+ L"Failed to allocate memory for heap.\r\n"));
+ BS->Exit(IH, status, 0, NULL);
+ }
+
+ setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize));
+
/* Set up the console, so printf works. */
status = BS->LocateProtocol(&ConsoleControlGUID, NULL,
(VOID **)&ConsoleControl);
@@ -296,6 +274,8 @@ add_device(dev_info_t **devinfop, dev_info_t *devinfo)
void
efi_exit(EFI_STATUS s)
{
+
+ BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
BS->Exit(IH, s, 0, NULL);
}