From nobody Fri Oct 8 06:10:55 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7644A12D386B; Fri, 8 Oct 2021 06:11:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HQd9N61Rzz3L0T; Fri, 8 Oct 2021 06:11:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3070521E24; Fri, 8 Oct 2021 06:10:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1986Athb007355; Fri, 8 Oct 2021 06:10:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1986At3Q007354; Fri, 8 Oct 2021 06:10:55 GMT (envelope-from git) Date: Fri, 8 Oct 2021 06:10:55 GMT Message-Id: <202110080610.1986At3Q007354@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: fbeb08184407 - stable/12 - boot1.efi: use malloc family from libsa List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: fbeb08184407c1d8824790fd51410f9e8f200522 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=fbeb08184407c1d8824790fd51410f9e8f200522 commit fbeb08184407c1d8824790fd51410f9e8f200522 Author: Toomas Soome AuthorDate: 2020-06-30 21:48:58 +0000 Commit: Kyle Evans CommitDate: 2021-10-08 05:24:26 +0000 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. (cherry picked from commit 12c470af750672c4847af20cc8e2a736aab7db78) --- stand/efi/boot1/boot1.c | 52 +++++++++++++++---------------------------------- 1 file 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); }