Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jun 2020 21:48:59 +0000 (UTC)
From:      Toomas Soome <tsoome@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r362812 - head/stand/efi/boot1
Message-ID:  <202006302148.05ULmxOR033112@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tsoome
Date: Tue Jun 30 21:48:58 2020
New Revision: 362812
URL: https://svnweb.freebsd.org/changeset/base/362812

Log:
  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.

Modified:
  head/stand/efi/boot1/boot1.c

Modified: head/stand/efi/boot1/boot1.c
==============================================================================
--- head/stand/efi/boot1/boot1.c	Tue Jun 30 21:40:34 2020	(r362811)
+++ head/stand/efi/boot1/boot1.c	Tue Jun 30 21:48:58 2020	(r362812)
@@ -53,43 +53,9 @@ 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.
- */
+static EFI_PHYSICAL_ADDRESS heap;
+static UINTN heapsize;
 
-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);
-}
-
 /*
  * try_boot only returns if it fails to load the loader. If it succeeds
  * it simply boots, otherwise it returns the status of last EFI call.
@@ -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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006302148.05ULmxOR033112>