From e7b3598311c4b002417ac6364093cfab218ced88 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 30 Jun 2023 13:24:57 -0400 Subject: Move some stuff around This moves some things around to help with loader protocol changes: - Move replacements.c to loader-proto.c - likewise with replacements.h - move the SHIM_IMAGE_LOADER decl to loader-proto.h - move the LoadImage / StartImage interface setup to an init function - move shim_load_image() / shim_start_image() to loader-proto.c Signed-off-by: Peter Jones --- shim.c | 91 ++---------------------------------------------------------------- 1 file changed, 2 insertions(+), 89 deletions(-) (limited to 'shim.c') diff --git a/shim.c b/shim.c index 60b5e720..98462aa0 100644 --- a/shim.c +++ b/shim.c @@ -1314,7 +1314,6 @@ init_openssl(void) } static SHIM_LOCK shim_lock_interface; -static SHIM_IMAGE_LOADER shim_image_loader_interface; static EFI_HANDLE shim_lock_handle; EFI_STATUS @@ -1344,6 +1343,8 @@ install_shim_protocols(void) if (!EFI_ERROR(efi_status)) uninstall_shim_protocols(); + init_image_loader(); + /* * Install the protocol */ @@ -1915,91 +1916,6 @@ devel_egress(devel_egress_action action UNUSED) #endif } -static EFI_STATUS EFIAPI -shim_load_image(IN BOOLEAN BootPolicy, IN EFI_HANDLE ParentImageHandle, - IN EFI_DEVICE_PATH *FilePath, IN VOID *SourceBuffer, - IN UINTN SourceSize, OUT EFI_HANDLE *ImageHandle) -{ - SHIM_LOADED_IMAGE *image; - EFI_STATUS efi_status; - - (void)FilePath; - - if (BootPolicy || !SourceBuffer || !SourceSize) - return EFI_UNSUPPORTED; - - image = AllocatePool(sizeof(*image)); - if (!image) - return EFI_OUT_OF_RESOURCES; - - SetMem(image, sizeof(*image), 0); - - image->li.Revision = 0x1000; - image->li.ParentHandle = ParentImageHandle; - image->li.SystemTable = systab; - - efi_status = handle_image(SourceBuffer, SourceSize, &image->li, - &image->entry_point, &image->alloc_address, - &image->alloc_pages); - if (EFI_ERROR(efi_status)) - goto free_image; - - *ImageHandle = NULL; - efi_status = BS->InstallMultipleProtocolInterfaces(ImageHandle, - &SHIM_LOADED_IMAGE_GUID, image, - &EFI_LOADED_IMAGE_GUID, &image->li, - NULL); - if (EFI_ERROR(efi_status)) - goto free_alloc; - - return EFI_SUCCESS; - -free_alloc: - BS->FreePages(image->alloc_address, image->alloc_pages); -free_image: - FreePool(image); - return efi_status; -} - -static EFI_STATUS EFIAPI -shim_start_image(IN EFI_HANDLE ImageHandle, OUT UINTN *ExitDataSize, - OUT CHAR16 **ExitData OPTIONAL) -{ - SHIM_LOADED_IMAGE *image; - EFI_STATUS efi_status; - - efi_status = BS->HandleProtocol(ImageHandle, &SHIM_LOADED_IMAGE_GUID, - (void **)&image); - if (EFI_ERROR(efi_status) || image->started) - return EFI_INVALID_PARAMETER; - - if (!setjmp(image->longjmp_buf)) { - image->started = true; - efi_status = - image->entry_point(ImageHandle, image->li.SystemTable); - } else { - if (ExitData) { - *ExitDataSize = image->exit_data_size; - *ExitData = (CHAR16 *)image->exit_data; - } - efi_status = image->exit_status; - } - - // - // We only support EFI applications, so we can unload and free the - // image unconditionally. - // - BS->UninstallMultipleProtocolInterfaces(ImageHandle, - &EFI_LOADED_IMAGE_GUID, image, - &SHIM_LOADED_IMAGE_GUID, &image->li, - NULL); - - BS->FreePages(image->alloc_address, image->alloc_pages); - FreePool(image); - - return efi_status; -} - EFI_STATUS efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab) { @@ -2043,9 +1959,6 @@ efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab) shim_lock_interface.Hash = shim_hash; shim_lock_interface.Context = shim_read_header; - shim_image_loader_interface.LoadImage = shim_load_image; - shim_image_loader_interface.StartImage = shim_start_image; - systab = passed_systab; image_handle = global_image_handle = passed_image_handle; -- cgit v1.2.3