forked from xt-sys/exectos
Implement PeGetFileSize(), PeGetImageSize() and PeUnloadImage() routines
This commit is contained in:
parent
17c50ea912
commit
a57ae020fa
@ -110,12 +110,15 @@ typedef EFI_STATUS (*PBL_ACPI_GET_SMBIOS3_TABLE)(OUT PVOID *SmBiosTable);
|
||||
typedef EFI_STATUS (*PBL_ACPI_GET_XSDP_TABLE)(OUT PVOID *AcpiTable);
|
||||
typedef EFI_STATUS (*PBL_BOOTPROTO_BOOT_SYSTEM)(IN PXTBL_BOOT_PARAMETERS Parameters);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_ENTRY_POINT)(IN PVOID ImagePointer, OUT PVOID *EntryPoint);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_FILE_SIZE)(IN PVOID ImagePointer, OUT PULONGLONG FileSize);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_IMAGE_SIZE)(IN PVOID ImagePointer, OUT PUINT ImageSize);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_MACHINE_TYPE)(IN PVOID ImagePointer, OUT PUSHORT MachineType);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_SECTION)(IN PVOID ImagePointer, IN PCHAR SectionName, OUT PULONG *RawData);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_SUBSYSTEM)(IN PVOID ImagePointer, OUT PUSHORT SubSystem);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_GET_VERSION)(IN PVOID ImagePointer, OUT PUSHORT Version);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_LOAD_IMAGE)(IN PEFI_FILE_HANDLE FileHandle, IN LOADER_MEMORY_TYPE MemoryType, IN PVOID VirtualAddress, OUT PVOID *ImagePointer);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_RELOCATE_IMAGE)(IN PVOID ImagePointer, IN EFI_VIRTUAL_ADDRESS Address);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_UNLOAD_IMAGE)(IN PVOID ImagePointer);
|
||||
typedef EFI_STATUS (*PBL_EXECIMAGE_VERIFY_IMAGE)(IN PVOID ImagePointer);
|
||||
typedef EFI_STATUS (*PBL_FRAMEBUFFER_GET_DISPLAY_DRIVER)(OUT PEFI_GRAPHICS_PROTOCOL Protocol);
|
||||
typedef EFI_STATUS (*PBL_FRAMEBUFFER_GET_DISPLAY_INFORMATION)(OUT PXTBL_FRAMEBUFFER_INFORMATION FbInfo);
|
||||
@ -290,12 +293,15 @@ typedef struct _XTBL_BOOT_PROTOCOL
|
||||
typedef struct _XTBL_EXECUTABLE_IMAGE_PROTOCOL
|
||||
{
|
||||
PBL_EXECIMAGE_GET_ENTRY_POINT GetEntryPoint;
|
||||
PBL_EXECIMAGE_GET_FILE_SIZE GetFileSize;
|
||||
PBL_EXECIMAGE_GET_IMAGE_SIZE GetImageSize;
|
||||
PBL_EXECIMAGE_GET_MACHINE_TYPE GetMachineType;
|
||||
PBL_EXECIMAGE_GET_SECTION GetSection;
|
||||
PBL_EXECIMAGE_GET_SUBSYSTEM GetSubSystem;
|
||||
PBL_EXECIMAGE_GET_VERSION GetVersion;
|
||||
PBL_EXECIMAGE_LOAD_IMAGE LoadImage;
|
||||
PBL_EXECIMAGE_RELOCATE_IMAGE RelocateImage;
|
||||
PBL_EXECIMAGE_UNLOAD_IMAGE UnloadImage;
|
||||
PBL_EXECIMAGE_VERIFY_IMAGE VerifyImage;
|
||||
} XTBL_EXECUTABLE_IMAGE_PROTOCOL, *PXTBL_EXECUTABLE_IMAGE_PROTOCOL;
|
||||
|
||||
|
@ -19,6 +19,16 @@ EFI_STATUS
|
||||
PeGetEntryPoint(IN PVOID ImagePointer,
|
||||
OUT PVOID *EntryPoint);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeGetFileSize(IN PVOID ImagePointer,
|
||||
OUT PULONGLONG FileSize);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeGetImageSize(IN PVOID ImagePointer,
|
||||
OUT PUINT ImageSize);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeGetMachineType(IN PVOID ImagePointer,
|
||||
@ -52,6 +62,10 @@ EFI_STATUS
|
||||
PeRelocateImage(IN PVOID ImagePointer,
|
||||
IN EFI_VIRTUAL_ADDRESS Address);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeUnloadImage(IN PVOID ImagePointer);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeVerifyImage(IN PVOID ImagePointer);
|
||||
|
@ -47,6 +47,76 @@ PeGetEntryPoint(IN PVOID ImagePointer,
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the loaded PE/COFF file.
|
||||
*
|
||||
* @param ImagePointer
|
||||
* Supplies a pointer to the PE/COFF context structure representing the loaded image.
|
||||
*
|
||||
* @param ImageSize
|
||||
* Supplies a pointer to the memory area where file size will be stored.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeGetFileSize(IN PVOID ImagePointer,
|
||||
OUT PULONGLONG FileSize)
|
||||
{
|
||||
PPECOFF_IMAGE_CONTEXT Image;
|
||||
|
||||
/* Get PE/COFF image pointer*/
|
||||
Image = ImagePointer;
|
||||
|
||||
/* Validate input data */
|
||||
if(!Image || !Image->ImageSize)
|
||||
{
|
||||
/* Invalid parameter passed */
|
||||
return STATUS_EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Get image size and return success */
|
||||
*FileSize = Image->FileSize;
|
||||
return STATUS_EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the loaded PE/COFF image.
|
||||
*
|
||||
* @param ImagePointer
|
||||
* Supplies a pointer to the PE/COFF context structure representing the loaded image.
|
||||
*
|
||||
* @param ImageSize
|
||||
* Supplies a pointer to the memory area where image size will be stored.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeGetImageSize(IN PVOID ImagePointer,
|
||||
OUT PUINT ImageSize)
|
||||
{
|
||||
PPECOFF_IMAGE_CONTEXT Image;
|
||||
|
||||
/* Get PE/COFF image pointer*/
|
||||
Image = ImagePointer;
|
||||
|
||||
/* Validate input data */
|
||||
if(!Image || !Image->ImageSize)
|
||||
{
|
||||
/* Invalid parameter passed */
|
||||
return STATUS_EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Get image size and return success */
|
||||
*ImageSize = Image->ImageSize;
|
||||
return STATUS_EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the machine type of the PE/COFF image.
|
||||
*
|
||||
@ -218,7 +288,7 @@ PeGetVersion(IN PVOID ImagePointer,
|
||||
* @param Image
|
||||
* Supplies pointer to the memory area where loaded PE/COFF image context will be stored.
|
||||
*
|
||||
* @return This routine returns status code.
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
@ -438,7 +508,7 @@ PeLoadImage(IN PEFI_FILE_HANDLE FileHandle,
|
||||
* @param Address
|
||||
* Specifies destination address of memory region, where image should be relocated.
|
||||
*
|
||||
* @return This routine returns status code.
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
@ -483,6 +553,41 @@ PeRelocateImage(IN PVOID ImagePointer,
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads a PE/COFF image file and frees allocated memory.
|
||||
*
|
||||
* @param ImagePointer
|
||||
* Supplies a pointer to the PE/COFF context structure representing the loaded image.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
PeUnloadImage(IN PVOID ImagePointer)
|
||||
{
|
||||
PPECOFF_IMAGE_CONTEXT Image;
|
||||
EFI_STATUS Status;
|
||||
|
||||
/* Get PE/COFF image pointer*/
|
||||
Image = ImagePointer;
|
||||
|
||||
/* Validate input data */
|
||||
if(!Image || !Image->Data)
|
||||
{
|
||||
/* Invalid parameter passed */
|
||||
return STATUS_EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Free memory allocated for the image */
|
||||
Status = XtLdrProtocol->Memory.FreePages(Image->ImagePages, (EFI_PHYSICAL_ADDRESS)(UINT_PTR)Image->Data);
|
||||
Status |= XtLdrProtocol->Memory.FreePool(Image);
|
||||
|
||||
/* Return status */
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a PE/COFF image headers.
|
||||
*
|
||||
@ -666,7 +771,7 @@ PepRelocateLoadedImage(IN PPECOFF_IMAGE_CONTEXT Image)
|
||||
* @param SystemTable
|
||||
* Provides the EFI system table.
|
||||
*
|
||||
* @return This routine returns status code.
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
@ -688,12 +793,15 @@ XtLdrModuleMain(IN EFI_HANDLE ImageHandle,
|
||||
|
||||
/* Set routines available via PE/COFF image protocol */
|
||||
PeCoffProtocol.GetEntryPoint = PeGetEntryPoint;
|
||||
PeCoffProtocol.GetFileSize = PeGetFileSize;
|
||||
PeCoffProtocol.GetImageSize = PeGetImageSize;
|
||||
PeCoffProtocol.GetMachineType = PeGetMachineType;
|
||||
PeCoffProtocol.GetSection = PeGetSection;
|
||||
PeCoffProtocol.GetSubSystem = PeGetSubSystem;
|
||||
PeCoffProtocol.GetVersion = PeGetVersion;
|
||||
PeCoffProtocol.LoadImage = PeLoadImage;
|
||||
PeCoffProtocol.RelocateImage = PeRelocateImage;
|
||||
PeCoffProtocol.UnloadImage = PeUnloadImage;
|
||||
PeCoffProtocol.VerifyImage = PeVerifyImage;
|
||||
|
||||
/* Register PE/COFF protocol */
|
||||
|
Loading…
Reference in New Issue
Block a user