From 5ec08cb84abbceace3d3382000f48a8d2d7ca30e Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 16 Nov 2022 15:03:33 +0100 Subject: [PATCH] Implement PeGetSubSystem() routine --- xtldr/includes/blmod.h | 2 ++ xtldr/modules/pecoff/includes/pecoff.h | 4 ++++ xtldr/modules/pecoff/pecoff.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/xtldr/includes/blmod.h b/xtldr/includes/blmod.h index 66f415a..cc45a30 100644 --- a/xtldr/includes/blmod.h +++ b/xtldr/includes/blmod.h @@ -22,6 +22,7 @@ typedef struct _XT_PECOFFF_IMAGE_PROTOCOL XT_PECOFF_IMAGE_PROTOCOL, *PXT_PECOFF_ /* Pointers to the routines provided by the modules */ typedef EFI_STATUS (*PXT_BOOTPROTO_BOOT_SYSTEM)(IN PXT_BOOT_PROTOCOL_PARAMETERS Parameters); typedef EFI_STATUS (*PXT_PECOFF_GET_ENTRY_POINT)(IN PPECOFF_IMAGE_CONTEXT Image, OUT PVOID *EntryPoint); +typedef EFI_STATUS (*PXT_PECOFF_GET_SUBSYSTEM)(IN PPECOFF_IMAGE_CONTEXT Image, OUT PUSHORT SubSystem); typedef EFI_STATUS (*PXT_PECOFF_LOAD_IMAGE)(IN PEFI_FILE_HANDLE FileHandle, IN LOADER_MEMORY_TYPE MemoryType, IN PVOID VirtualAddress, OUT PPECOFF_IMAGE_CONTEXT *Image); typedef EFI_STATUS (*PXT_PECOFF_RELOCATE_IMAGE)(IN PPECOFF_IMAGE_CONTEXT Image, IN EFI_VIRTUAL_ADDRESS Address); @@ -49,6 +50,7 @@ typedef struct _XT_BOOT_PROTOCOL_PARAMETERS typedef struct _XT_PECOFFF_IMAGE_PROTOCOL { PXT_PECOFF_GET_ENTRY_POINT GetEntryPoint; + PXT_PECOFF_GET_SUBSYSTEM GetSubSystem; PXT_PECOFF_LOAD_IMAGE Load; PXT_PECOFF_RELOCATE_IMAGE Relocate; } XT_PECOFF_IMAGE_PROTOCOL, *PXT_PECOFF_IMAGE_PROTOCOL; diff --git a/xtldr/modules/pecoff/includes/pecoff.h b/xtldr/modules/pecoff/includes/pecoff.h index 885f885..1c61de1 100644 --- a/xtldr/modules/pecoff/includes/pecoff.h +++ b/xtldr/modules/pecoff/includes/pecoff.h @@ -17,6 +17,10 @@ EFI_STATUS PeGetEntryPoint(IN PPECOFF_IMAGE_CONTEXT Image, OUT PVOID *EntryPoint); +EFI_STATUS +PeGetSubSystem(IN PPECOFF_IMAGE_CONTEXT Image, + OUT PUSHORT SubSystem); + EFI_STATUS PeLoadImage(IN PEFI_FILE_HANDLE FileHandle, IN LOADER_MEMORY_TYPE MemoryType, diff --git a/xtldr/modules/pecoff/pecoff.c b/xtldr/modules/pecoff/pecoff.c index a815232..3992223 100644 --- a/xtldr/modules/pecoff/pecoff.c +++ b/xtldr/modules/pecoff/pecoff.c @@ -50,6 +50,27 @@ PeGetEntryPoint(IN PPECOFF_IMAGE_CONTEXT Image, return STATUS_EFI_SUCCESS; } +/** + * Returns an information about subsystem that is required to run PE/COFF image. + * + * @param Image + * A pointer to the PE/COFF context structure representing the loaded image. + * + * @param SubSystem + * A pointer to the memory area storing a value defined for the 'subsystem' field of the image. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +EFI_STATUS +PeGetSubSystem(IN PPECOFF_IMAGE_CONTEXT Image, + OUT PUSHORT SubSystem) +{ + *SubSystem = Image->PeHeader->OptionalHeader.Subsystem; + return STATUS_EFI_SUCCESS; +} + /** * Loads a PE/COFF image file. * @@ -526,6 +547,7 @@ BlXtLdrModuleMain(IN EFI_HANDLE ImageHandle, /* Set routines available via PE/COFF image protocol */ XtPeCoffProtocol.GetEntryPoint = PeGetEntryPoint; + XtPeCoffProtocol.GetSubSystem = PeGetSubSystem; XtPeCoffProtocol.Load = PeLoadImage; XtPeCoffProtocol.Relocate = PeRelocateImage;