From owner-svn-src-head@freebsd.org Thu Aug 31 17:32:20 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3C297E02942; Thu, 31 Aug 2017 17:32:20 +0000 (UTC) (envelope-from imp@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 mx1.freebsd.org (Postfix) with ESMTPS id 128A81BFE; Thu, 31 Aug 2017 17:32:20 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7VHWJwk037300; Thu, 31 Aug 2017 17:32:19 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7VHWJme037299; Thu, 31 Aug 2017 17:32:19 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201708311732.v7VHWJme037299@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 31 Aug 2017 17:32:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323064 - head/sys/boot/efi/boot1 X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/boot/efi/boot1 X-SVN-Commit-Revision: 323064 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.23 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: Thu, 31 Aug 2017 17:32:20 -0000 Author: imp Date: Thu Aug 31 17:32:19 2017 New Revision: 323064 URL: https://svnweb.freebsd.org/changeset/base/323064 Log: Exit rather than panic for most errors. In the FreeBSD UEFI boot protocol, boot1.efi exits back to UEFI if it can't boot the image for most reasons (so that further items in the EFI boot manger list can be tried). Rename panic to efi_panic, make it static and give it an extra status argument. Exit back to UEFI with that status argument so the next loader can be tried. Use malloc/free exclusively instead of mixing malloc/free and AllocatePool/FreePool. The code is smaller. Sponsored by: Netflix Modified: head/sys/boot/efi/boot1/boot1.c Modified: head/sys/boot/efi/boot1/boot1.c ============================================================================== --- head/sys/boot/efi/boot1/boot1.c Thu Aug 31 17:32:14 2017 (r323063) +++ head/sys/boot/efi/boot1/boot1.c Thu Aug 31 17:32:19 2017 (r323064) @@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$"); #include "boot_module.h" #include "paths.h" +static void efi_panic(EFI_STATUS s, const char *fmt, ...) __dead2 __printflike(2, 3); + static const boot_module_t *boot_modules[] = { #ifdef EFI_ZFS_BOOT @@ -275,11 +277,9 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B /* Run through each module, see if it can load this partition */ for (i = 0; i < NUM_BOOT_MODULES; i++) { - if ((status = BS->AllocatePool(EfiLoaderData, - sizeof(*devinfo), (void **)&devinfo)) != - EFI_SUCCESS) { - DPRINTF("\nFailed to allocate devinfo (%lu)\n", - EFI_ERROR_CODE(status)); + devinfo = malloc(sizeof(*devinfo)); + if (devinfo == NULL) { + DPRINTF("\nFailed to allocate devinfo\n"); continue; } devinfo->dev = blkio; @@ -292,7 +292,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, B status = boot_modules[i]->probe(devinfo); if (status == EFI_SUCCESS) return (EFI_SUCCESS); - (void)BS->FreePool(devinfo); + free(devinfo); } return (EFI_UNSUPPORTED); @@ -411,10 +411,10 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) /* Get all the device handles */ hsize = (UINTN)NUM_HANDLES_INIT * sizeof(EFI_HANDLE); - if ((status = BS->AllocatePool(EfiLoaderData, hsize, (void **)&handles)) - != EFI_SUCCESS) - panic("Failed to allocate %d handles (%lu)", NUM_HANDLES_INIT, - EFI_ERROR_CODE(status)); + handles = malloc(hsize); + if (handles == NULL) { + printf("Failed to allocate %d handles\n", NUM_HANDLES_INIT); + } status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL, &hsize, handles); @@ -422,21 +422,19 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) case EFI_SUCCESS: break; case EFI_BUFFER_TOO_SMALL: - (void)BS->FreePool(handles); - if ((status = BS->AllocatePool(EfiLoaderData, hsize, - (void **)&handles)) != EFI_SUCCESS) { - panic("Failed to allocate %zu handles (%lu)", hsize / - sizeof(*handles), EFI_ERROR_CODE(status)); - } + free(handles); + handles = malloc(hsize); + if (handles == NULL) + efi_panic(EFI_OUT_OF_RESOURCES, "Failed to allocate %d handles\n", + NUM_HANDLES_INIT); status = BS->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL, &hsize, handles); if (status != EFI_SUCCESS) - panic("Failed to get device handles (%lu)\n", - EFI_ERROR_CODE(status)); + efi_panic(status, "Failed to get device handles\n"); break; default: - panic("Failed to get device handles (%lu)", - EFI_ERROR_CODE(status)); + efi_panic(status, "Failed to get device handles\n"); + break; } /* Scan all partitions, probing with all modules. */ @@ -457,7 +455,7 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) try_boot(); /* If we get here, we're out of luck... */ - panic("No bootable partitions found!"); + efi_panic(EFI_LOAD_ERROR, "No bootable partitions found!"); } /* @@ -479,8 +477,12 @@ add_device(dev_info_t **devinfop, dev_info_t *devinfo) dev->next = devinfo; } -void -panic(const char *fmt, ...) +/* + * OK. We totally give up. Exit back to EFI with a sensible status so + * it can try the next option on the list. + */ +static void +efi_panic(EFI_STATUS s, const char *fmt, ...) { va_list ap; @@ -490,7 +492,7 @@ panic(const char *fmt, ...) va_end(ap); printf("\n"); - while (1) {} + BS->Exit(IH, s, 0, NULL); } void