diff options
Diffstat (limited to 'PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c')
-rw-r--r-- | PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c | 258 |
1 files changed, 132 insertions, 126 deletions
diff --git a/PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c b/PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c index d760d137dc..d535c2c105 100644 --- a/PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c +++ b/PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c @@ -37,26 +37,27 @@ **/
EFI_STATUS
GetPrmModuleExportDescriptorTable (
- IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory,
- IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
- OUT PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT **ExportDescriptor
+ IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory,
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
+ OUT PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT **ExportDescriptor
)
{
- UINTN Index;
- EFI_PHYSICAL_ADDRESS CurrentImageAddress;
- UINT16 PrmModuleExportDescriptorOrdinal;
- CONST CHAR8 *CurrentExportName;
- UINT16 *OrdinalTable;
- UINT32 *ExportNamePointerTable;
- UINT32 *ExportAddressTable;
- PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *TempExportDescriptor;
+ UINTN Index;
+ EFI_PHYSICAL_ADDRESS CurrentImageAddress;
+ UINT16 PrmModuleExportDescriptorOrdinal;
+ CONST CHAR8 *CurrentExportName;
+ UINT16 *OrdinalTable;
+ UINT32 *ExportNamePointerTable;
+ UINT32 *ExportAddressTable;
+ PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *TempExportDescriptor;
DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));
- if (ImageExportDirectory == NULL ||
- PeCoffLoaderImageContext == NULL ||
- PeCoffLoaderImageContext->ImageAddress == 0 ||
- ExportDescriptor == NULL) {
+ if ((ImageExportDirectory == NULL) ||
+ (PeCoffLoaderImageContext == NULL) ||
+ (PeCoffLoaderImageContext->ImageAddress == 0) ||
+ (ExportDescriptor == NULL))
+ {
return EFI_INVALID_PARAMETER;
}
@@ -73,13 +74,13 @@ GetPrmModuleExportDescriptorTable ( //
// The export name pointer table and export ordinal table form two parallel arrays associated by index.
//
- CurrentImageAddress = PeCoffLoaderImageContext->ImageAddress;
- ExportAddressTable = (UINT32 *) ((UINTN) CurrentImageAddress + ImageExportDirectory->AddressOfFunctions);
- ExportNamePointerTable = (UINT32 *) ((UINTN) CurrentImageAddress + ImageExportDirectory->AddressOfNames);
- OrdinalTable = (UINT16 *) ((UINTN) CurrentImageAddress + ImageExportDirectory->AddressOfNameOrdinals);
+ CurrentImageAddress = PeCoffLoaderImageContext->ImageAddress;
+ ExportAddressTable = (UINT32 *)((UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfFunctions);
+ ExportNamePointerTable = (UINT32 *)((UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfNames);
+ OrdinalTable = (UINT16 *)((UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfNameOrdinals);
for (Index = 0; Index < ImageExportDirectory->NumberOfNames; Index++) {
- CurrentExportName = (CONST CHAR8 *) ((UINTN) CurrentImageAddress + ExportNamePointerTable[Index]);
+ CurrentExportName = (CONST CHAR8 *)((UINTN)CurrentImageAddress + ExportNamePointerTable[Index]);
DEBUG ((
DEBUG_INFO,
" %a %a: Export Name[0x%x] - %a.\n",
@@ -89,11 +90,12 @@ GetPrmModuleExportDescriptorTable ( CurrentExportName
));
if (
- AsciiStrnCmp (
- PRM_STRING(PRM_MODULE_EXPORT_DESCRIPTOR_NAME),
- CurrentExportName,
- AsciiStrLen (PRM_STRING(PRM_MODULE_EXPORT_DESCRIPTOR_NAME))
- ) == 0) {
+ AsciiStrnCmp (
+ PRM_STRING (PRM_MODULE_EXPORT_DESCRIPTOR_NAME),
+ CurrentExportName,
+ AsciiStrLen (PRM_STRING (PRM_MODULE_EXPORT_DESCRIPTOR_NAME))
+ ) == 0)
+ {
PrmModuleExportDescriptorOrdinal = OrdinalTable[Index];
DEBUG ((
DEBUG_INFO,
@@ -106,19 +108,21 @@ GetPrmModuleExportDescriptorTable ( DEBUG ((DEBUG_ERROR, "%a %a: The PRM Module Export Descriptor ordinal value is invalid.\n", _DBGMSGID_, __FUNCTION__));
return EFI_NOT_FOUND;
}
- TempExportDescriptor = (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *) ((UINTN) CurrentImageAddress + ExportAddressTable[PrmModuleExportDescriptorOrdinal]);
+
+ TempExportDescriptor = (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *)((UINTN)CurrentImageAddress + ExportAddressTable[PrmModuleExportDescriptorOrdinal]);
if (TempExportDescriptor->Header.Signature == PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE) {
*ExportDescriptor = TempExportDescriptor;
- DEBUG ((DEBUG_INFO, " %a %a: PRM Module Export Descriptor found at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN) ExportDescriptor));
+ DEBUG ((DEBUG_INFO, " %a %a: PRM Module Export Descriptor found at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN)ExportDescriptor));
} else {
DEBUG ((
DEBUG_INFO,
" %a %a: PRM Module Export Descriptor found at 0x%x but signature check failed.\n",
_DBGMSGID_,
__FUNCTION__,
- (UINTN) TempExportDescriptor
+ (UINTN)TempExportDescriptor
));
}
+
DEBUG ((DEBUG_INFO, " %a %a: Exiting export iteration since export descriptor found.\n", _DBGMSGID_, __FUNCTION__));
return EFI_SUCCESS;
}
@@ -145,18 +149,18 @@ GetPrmModuleExportDescriptorTable ( **/
EFI_STATUS
GetExportDirectoryInPeCoffImage (
- IN VOID *Image,
- IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
- OUT EFI_IMAGE_EXPORT_DIRECTORY **ImageExportDirectory
+ IN VOID *Image,
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
+ OUT EFI_IMAGE_EXPORT_DIRECTORY **ImageExportDirectory
)
{
- UINT16 Magic;
- UINT32 NumberOfRvaAndSizes;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion;
- EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
- EFI_IMAGE_EXPORT_DIRECTORY *ExportDirectory;
+ UINT16 Magic;
+ UINT32 NumberOfRvaAndSizes;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion;
+ EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
+ EFI_IMAGE_EXPORT_DIRECTORY *ExportDirectory;
- if (Image == NULL || PeCoffLoaderImageContext == NULL || ImageExportDirectory == NULL) {
+ if ((Image == NULL) || (PeCoffLoaderImageContext == NULL) || (ImageExportDirectory == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -169,36 +173,36 @@ GetExportDirectoryInPeCoffImage ( // image with PE32 magic.
//
switch (PeCoffLoaderImageContext->Machine) {
- case EFI_IMAGE_MACHINE_IA32:
- //
- // Assume PE32 image with IA32 Machine field.
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
- break;
- case EFI_IMAGE_MACHINE_X64:
- case EFI_IMAGE_MACHINE_AARCH64:
- //
- // Assume PE32+ image with X64 Machine field
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
- break;
- default:
- //
- // For unknown Machine field, use Magic in optional header
- //
- DEBUG ((
- DEBUG_WARN,
- "%a %a: The machine type for this image is not valid for a PRM module.\n",
- _DBGMSGID_,
- __FUNCTION__
- ));
- return EFI_UNSUPPORTED;
+ case EFI_IMAGE_MACHINE_IA32:
+ //
+ // Assume PE32 image with IA32 Machine field.
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
+ break;
+ case EFI_IMAGE_MACHINE_X64:
+ case EFI_IMAGE_MACHINE_AARCH64:
+ //
+ // Assume PE32+ image with X64 Machine field
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+ break;
+ default:
+ //
+ // For unknown Machine field, use Magic in optional header
+ //
+ DEBUG ((
+ DEBUG_WARN,
+ "%a %a: The machine type for this image is not valid for a PRM module.\n",
+ _DBGMSGID_,
+ __FUNCTION__
+ ));
+ return EFI_UNSUPPORTED;
}
- OptionalHeaderPtrUnion.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) (
- (UINTN) Image +
- PeCoffLoaderImageContext->PeCoffHeaderOffset
- );
+ OptionalHeaderPtrUnion.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(
+ (UINTN)Image +
+ PeCoffLoaderImageContext->PeCoffHeaderOffset
+ );
//
// Check the PE/COFF Header Signature. Determine if the image is valid and/or a TE image.
@@ -213,43 +217,44 @@ GetExportDirectoryInPeCoffImage ( // Use the PE32 offset to get the Export Directory Entry
//
NumberOfRvaAndSizes = OptionalHeaderPtrUnion.Pe32->OptionalHeader.NumberOfRvaAndSizes;
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHeaderPtrUnion.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(OptionalHeaderPtrUnion.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
} else if (OptionalHeaderPtrUnion.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// Use the PE32+ offset get the Export Directory Entry
//
NumberOfRvaAndSizes = OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
} else {
return EFI_UNSUPPORTED;
}
- if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_EXPORT || DirectoryEntry->VirtualAddress == 0) {
+ if ((NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_EXPORT) || (DirectoryEntry->VirtualAddress == 0)) {
//
// The export directory is not present
//
return EFI_NOT_FOUND;
- } else if (((UINT32) (~0) - DirectoryEntry->VirtualAddress) < DirectoryEntry->Size) {
+ } else if (((UINT32)(~0) - DirectoryEntry->VirtualAddress) < DirectoryEntry->Size) {
//
// The directory address overflows
//
DEBUG ((DEBUG_ERROR, "%a %a: The export directory entry in this image results in overflow.\n", _DBGMSGID_, __FUNCTION__));
return EFI_UNSUPPORTED;
} else {
- DEBUG ((DEBUG_INFO, "%a %a: Export Directory Entry found in the image at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN) OptionalHeaderPtrUnion.Pe32));
+ DEBUG ((DEBUG_INFO, "%a %a: Export Directory Entry found in the image at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN)OptionalHeaderPtrUnion.Pe32));
DEBUG ((DEBUG_INFO, " %a %a: Directory Entry Virtual Address = 0x%x.\n", _DBGMSGID_, __FUNCTION__, DirectoryEntry->VirtualAddress));
- ExportDirectory = (EFI_IMAGE_EXPORT_DIRECTORY *) ((UINTN) Image + DirectoryEntry->VirtualAddress);
+ ExportDirectory = (EFI_IMAGE_EXPORT_DIRECTORY *)((UINTN)Image + DirectoryEntry->VirtualAddress);
DEBUG ((
DEBUG_INFO,
" %a %a: Export Directory Table found successfully at 0x%x. Name address = 0x%x. Name = %a.\n",
_DBGMSGID_,
__FUNCTION__,
- (UINTN) ExportDirectory,
- ((UINTN) Image + ExportDirectory->Name),
- (CHAR8 *) ((UINTN) Image + ExportDirectory->Name)
+ (UINTN)ExportDirectory,
+ ((UINTN)Image + ExportDirectory->Name),
+ (CHAR8 *)((UINTN)Image + ExportDirectory->Name)
));
}
+
*ImageExportDirectory = ExportDirectory;
return EFI_SUCCESS;
@@ -273,18 +278,18 @@ GetExportDirectoryInPeCoffImage ( **/
EFI_STATUS
GetImageVersionInPeCoffImage (
- IN VOID *Image,
- IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
- OUT UINT16 *ImageMajorVersion,
- OUT UINT16 *ImageMinorVersion
+ IN VOID *Image,
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext,
+ OUT UINT16 *ImageMajorVersion,
+ OUT UINT16 *ImageMinorVersion
)
{
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion;
- UINT16 Magic;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion;
+ UINT16 Magic;
DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));
- if (Image == NULL || PeCoffLoaderImageContext == NULL || ImageMajorVersion == NULL || ImageMinorVersion == NULL) {
+ if ((Image == NULL) || (PeCoffLoaderImageContext == NULL) || (ImageMajorVersion == NULL) || (ImageMinorVersion == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -294,36 +299,36 @@ GetImageVersionInPeCoffImage ( // image with PE32 magic.
//
switch (PeCoffLoaderImageContext->Machine) {
- case EFI_IMAGE_MACHINE_IA32:
- //
- // Assume PE32 image
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
- break;
- case EFI_IMAGE_MACHINE_X64:
- case EFI_IMAGE_MACHINE_AARCH64:
- //
- // Assume PE32+ image
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
- break;
- default:
- //
- // For unknown Machine field, use Magic in optional header
- //
- DEBUG ((
- DEBUG_WARN,
- "%a %a: The machine type for this image is not valid for a PRM module.\n",
- _DBGMSGID_,
- __FUNCTION__
- ));
- return EFI_UNSUPPORTED;
+ case EFI_IMAGE_MACHINE_IA32:
+ //
+ // Assume PE32 image
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
+ break;
+ case EFI_IMAGE_MACHINE_X64:
+ case EFI_IMAGE_MACHINE_AARCH64:
+ //
+ // Assume PE32+ image
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+ break;
+ default:
+ //
+ // For unknown Machine field, use Magic in optional header
+ //
+ DEBUG ((
+ DEBUG_WARN,
+ "%a %a: The machine type for this image is not valid for a PRM module.\n",
+ _DBGMSGID_,
+ __FUNCTION__
+ ));
+ return EFI_UNSUPPORTED;
}
- OptionalHeaderPtrUnion.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) (
- (UINTN) Image +
- PeCoffLoaderImageContext->PeCoffHeaderOffset
- );
+ OptionalHeaderPtrUnion.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(
+ (UINTN)Image +
+ PeCoffLoaderImageContext->PeCoffHeaderOffset
+ );
//
// Check the PE/COFF Header Signature. Determine if the image is valid and/or a TE image.
//
@@ -368,30 +373,31 @@ GetImageVersionInPeCoffImage ( **/
EFI_STATUS
GetExportEntryAddress (
- IN CONST CHAR8 *ExportName,
- IN EFI_PHYSICAL_ADDRESS ImageBaseAddress,
- IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory,
- OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress
+ IN CONST CHAR8 *ExportName,
+ IN EFI_PHYSICAL_ADDRESS ImageBaseAddress,
+ IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory,
+ OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress
)
{
- UINTN ExportNameIndex;
- UINT16 CurrentExportOrdinal;
- UINT32 *ExportAddressTable;
- UINT32 *ExportNamePointerTable;
- UINT16 *OrdinalTable;
- CONST CHAR8 *ExportNameTablePointerName;
-
- if (ExportName == NULL || ImageBaseAddress == 0 || ImageExportDirectory == NULL || ExportPhysicalAddress == NULL) {
+ UINTN ExportNameIndex;
+ UINT16 CurrentExportOrdinal;
+ UINT32 *ExportAddressTable;
+ UINT32 *ExportNamePointerTable;
+ UINT16 *OrdinalTable;
+ CONST CHAR8 *ExportNameTablePointerName;
+
+ if ((ExportName == NULL) || (ImageBaseAddress == 0) || (ImageExportDirectory == NULL) || (ExportPhysicalAddress == NULL)) {
return EFI_INVALID_PARAMETER;
}
+
*ExportPhysicalAddress = 0;
- ExportAddressTable = (UINT32 *) ((UINTN) ImageBaseAddress + ImageExportDirectory->AddressOfFunctions);
- ExportNamePointerTable = (UINT32 *) ((UINTN) ImageBaseAddress + ImageExportDirectory->AddressOfNames);
- OrdinalTable = (UINT16 *) ((UINTN) ImageBaseAddress + ImageExportDirectory->AddressOfNameOrdinals);
+ ExportAddressTable = (UINT32 *)((UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfFunctions);
+ ExportNamePointerTable = (UINT32 *)((UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfNames);
+ OrdinalTable = (UINT16 *)((UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfNameOrdinals);
for (ExportNameIndex = 0; ExportNameIndex < ImageExportDirectory->NumberOfNames; ExportNameIndex++) {
- ExportNameTablePointerName = (CONST CHAR8 *) ((UINTN) ImageBaseAddress + ExportNamePointerTable[ExportNameIndex]);
+ ExportNameTablePointerName = (CONST CHAR8 *)((UINTN)ImageBaseAddress + ExportNamePointerTable[ExportNameIndex]);
if (AsciiStrnCmp (ExportName, ExportNameTablePointerName, PRM_HANDLER_NAME_MAXIMUM_LENGTH) == 0) {
CurrentExportOrdinal = OrdinalTable[ExportNameIndex];
@@ -402,7 +408,7 @@ GetExportEntryAddress ( break;
}
- *ExportPhysicalAddress = (EFI_PHYSICAL_ADDRESS) ((UINTN) ImageBaseAddress + ExportAddressTable[CurrentExportOrdinal]);
+ *ExportPhysicalAddress = (EFI_PHYSICAL_ADDRESS)((UINTN)ImageBaseAddress + ExportAddressTable[CurrentExportOrdinal]);
return EFI_SUCCESS;
}
}
|