From owner-svn-src-head@freebsd.org Tue Jun 30 21:48:59 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ABFA8356E67; Tue, 30 Jun 2020 21:48:59 +0000 (UTC) (envelope-from tsoome@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49xJ0C49Xkz41Dx; Tue, 30 Jun 2020 21:48:59 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 594DD1E9B0; Tue, 30 Jun 2020 21:48:59 +0000 (UTC) (envelope-from tsoome@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05ULmxf3033113; Tue, 30 Jun 2020 21:48:59 GMT (envelope-from tsoome@FreeBSD.org) Received: (from tsoome@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05ULmxOR033112; Tue, 30 Jun 2020 21:48:59 GMT (envelope-from tsoome@FreeBSD.org) Message-Id: <202006302148.05ULmxOR033112@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: tsoome set sender to tsoome@FreeBSD.org using -f From: Toomas Soome Date: Tue, 30 Jun 2020 21:48:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362812 - head/stand/efi/boot1 X-SVN-Group: head X-SVN-Commit-Author: tsoome X-SVN-Commit-Paths: head/stand/efi/boot1 X-SVN-Commit-Revision: 362812 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2020 21:48:59 -0000 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); }