20#define _DBGMSGID_ "[PRMPECOFFLIB]"
47 UINT16 PrmModuleExportDescriptorOrdinal;
48 CONST CHAR8 *CurrentExportName;
50 UINT32 *ExportNamePointerTable;
51 UINT32 *ExportAddressTable;
54 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
56 if ((ImageExportDirectory ==
NULL) ||
57 (PeCoffLoaderImageContext ==
NULL) ||
58 (PeCoffLoaderImageContext->ImageAddress == 0) ||
59 (ExportDescriptor ==
NULL))
61 return EFI_INVALID_PARAMETER;
64 *ExportDescriptor =
NULL;
68 " %a %a: %d exported names found in this image.\n",
71 ImageExportDirectory->NumberOfNames
77 CurrentImageAddress = PeCoffLoaderImageContext->ImageAddress;
78 ExportAddressTable = (UINT32 *)((
UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfFunctions);
79 ExportNamePointerTable = (UINT32 *)((
UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfNames);
80 OrdinalTable = (UINT16 *)((
UINTN)CurrentImageAddress + ImageExportDirectory->AddressOfNameOrdinals);
82 for (Index = 0; Index < ImageExportDirectory->NumberOfNames; Index++) {
83 CurrentExportName = (
CONST CHAR8 *)((
UINTN)CurrentImageAddress + ExportNamePointerTable[Index]);
86 " %a %a: Export Name[0x%x] - %a.\n",
94 PRM_STRING (PRM_MODULE_EXPORT_DESCRIPTOR_NAME),
96 AsciiStrLen (PRM_STRING (PRM_MODULE_EXPORT_DESCRIPTOR_NAME))
99 PrmModuleExportDescriptorOrdinal = OrdinalTable[Index];
102 " %a %a: PRM Module Export Descriptor found. Ordinal = %d.\n",
105 PrmModuleExportDescriptorOrdinal
107 if (PrmModuleExportDescriptorOrdinal >= ImageExportDirectory->NumberOfFunctions) {
108 DEBUG ((DEBUG_ERROR,
"%a %a: The PRM Module Export Descriptor ordinal value is invalid.\n", _DBGMSGID_, __func__));
109 return EFI_NOT_FOUND;
113 if (TempExportDescriptor->Header.Signature == PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE) {
114 *ExportDescriptor = TempExportDescriptor;
115 DEBUG ((DEBUG_INFO,
" %a %a: PRM Module Export Descriptor found at 0x%x.\n", _DBGMSGID_, __func__, (
UINTN)ExportDescriptor));
119 " %a %a: PRM Module Export Descriptor found at 0x%x but signature check failed.\n",
122 (
UINTN)TempExportDescriptor
126 DEBUG ((DEBUG_INFO,
" %a %a: Exiting export iteration since export descriptor found.\n", _DBGMSGID_, __func__));
131 return EFI_NOT_FOUND;
158 UINT32 NumberOfRvaAndSizes;
163 if ((Image ==
NULL) || (PeCoffLoaderImageContext ==
NULL) || (ImageExportDirectory ==
NULL)) {
164 return EFI_INVALID_PARAMETER;
167 DirectoryEntry =
NULL;
168 ExportDirectory =
NULL;
175 switch (PeCoffLoaderImageContext->Machine) {
195 "%a %a: The machine type for this image is not valid for a PRM module.\n",
199 return EFI_UNSUPPORTED;
204 PeCoffLoaderImageContext->PeCoffHeaderOffset
210 if (OptionalHeaderPtrUnion.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
211 DEBUG ((DEBUG_ERROR,
"%a %a: The PE signature is not valid for the current image.\n", _DBGMSGID_, __func__));
212 return EFI_UNSUPPORTED;
219 NumberOfRvaAndSizes = OptionalHeaderPtrUnion.Pe32->OptionalHeader.NumberOfRvaAndSizes;
220 DirectoryEntry = (
EFI_IMAGE_DATA_DIRECTORY *)&(OptionalHeaderPtrUnion.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
225 NumberOfRvaAndSizes = OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
226 DirectoryEntry = (
EFI_IMAGE_DATA_DIRECTORY *)&(OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]);
228 return EFI_UNSUPPORTED;
231 if ((NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_EXPORT) || (DirectoryEntry->VirtualAddress == 0)) {
235 return EFI_NOT_FOUND;
236 }
else if (((UINT32)(~0) - DirectoryEntry->VirtualAddress) < DirectoryEntry->Size) {
240 DEBUG ((DEBUG_ERROR,
"%a %a: The export directory entry in this image results in overflow.\n", _DBGMSGID_, __func__));
241 return EFI_UNSUPPORTED;
243 DEBUG ((DEBUG_INFO,
"%a %a: Export Directory Entry found in the image at 0x%x.\n", _DBGMSGID_, __func__, (
UINTN)OptionalHeaderPtrUnion.Pe32));
244 DEBUG ((DEBUG_INFO,
" %a %a: Directory Entry Virtual Address = 0x%x.\n", _DBGMSGID_, __func__, DirectoryEntry->VirtualAddress));
249 " %a %a: Export Directory Table found successfully at 0x%x. Name address = 0x%x. Name = %a.\n",
252 (
UINTN)ExportDirectory,
253 ((
UINTN)Image + ExportDirectory->Name),
254 (CHAR8 *)((
UINTN)Image + ExportDirectory->Name)
258 *ImageExportDirectory = ExportDirectory;
283 OUT UINT16 *ImageMajorVersion,
284 OUT UINT16 *ImageMinorVersion
290 DEBUG ((DEBUG_INFO,
" %a %a - Entry.\n", _DBGMSGID_, __func__));
292 if ((Image ==
NULL) || (PeCoffLoaderImageContext ==
NULL) || (ImageMajorVersion ==
NULL) || (ImageMinorVersion ==
NULL)) {
293 return EFI_INVALID_PARAMETER;
301 switch (PeCoffLoaderImageContext->Machine) {
321 "%a %a: The machine type for this image is not valid for a PRM module.\n",
325 return EFI_UNSUPPORTED;
330 PeCoffLoaderImageContext->PeCoffHeaderOffset
335 if (OptionalHeaderPtrUnion.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
336 DEBUG ((DEBUG_ERROR,
"%a %a: The PE signature is not valid for the current image.\n", _DBGMSGID_, __func__));
337 return EFI_UNSUPPORTED;
344 *ImageMajorVersion = OptionalHeaderPtrUnion.Pe32->OptionalHeader.MajorImageVersion;
345 *ImageMinorVersion = OptionalHeaderPtrUnion.Pe32->OptionalHeader.MinorImageVersion;
350 *ImageMajorVersion = OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.MajorImageVersion;
351 *ImageMinorVersion = OptionalHeaderPtrUnion.Pe32Plus->OptionalHeader.MinorImageVersion;
354 DEBUG ((DEBUG_INFO,
" %a %a - Image Major Version: 0x%02x.\n", _DBGMSGID_, __func__, *ImageMajorVersion));
355 DEBUG ((DEBUG_INFO,
" %a %a - Image Minor Version: 0x%02x.\n", _DBGMSGID_, __func__, *ImageMinorVersion));
382 UINTN ExportNameIndex;
383 UINT16 CurrentExportOrdinal;
384 UINT32 *ExportAddressTable;
385 UINT32 *ExportNamePointerTable;
386 UINT16 *OrdinalTable;
387 CONST CHAR8 *ExportNameTablePointerName;
389 if ((ExportName ==
NULL) || (ImageBaseAddress == 0) || (ImageExportDirectory ==
NULL) || (ExportPhysicalAddress ==
NULL)) {
390 return EFI_INVALID_PARAMETER;
393 *ExportPhysicalAddress = 0;
395 ExportAddressTable = (UINT32 *)((
UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfFunctions);
396 ExportNamePointerTable = (UINT32 *)((
UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfNames);
397 OrdinalTable = (UINT16 *)((
UINTN)ImageBaseAddress + ImageExportDirectory->AddressOfNameOrdinals);
399 for (ExportNameIndex = 0; ExportNameIndex < ImageExportDirectory->NumberOfNames; ExportNameIndex++) {
400 ExportNameTablePointerName = (
CONST CHAR8 *)((
UINTN)ImageBaseAddress + ExportNamePointerTable[ExportNameIndex]);
402 if (
AsciiStrnCmp (ExportName, ExportNameTablePointerName, PRM_HANDLER_NAME_MAXIMUM_LENGTH) == 0) {
403 CurrentExportOrdinal = OrdinalTable[ExportNameIndex];
405 ASSERT (CurrentExportOrdinal < ImageExportDirectory->NumberOfFunctions);
406 if (CurrentExportOrdinal >= ImageExportDirectory->NumberOfFunctions) {
407 DEBUG ((DEBUG_ERROR,
" %a %a: The export ordinal value is invalid.\n", _DBGMSGID_, __func__));
416 return EFI_NOT_FOUND;
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
EFI_STATUS GetExportDirectoryInPeCoffImage(IN VOID *Image, IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, OUT EFI_IMAGE_EXPORT_DIRECTORY **ImageExportDirectory)
EFI_STATUS GetPrmModuleExportDescriptorTable(IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, OUT PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT **ExportDescriptor)
EFI_STATUS GetImageVersionInPeCoffImage(IN VOID *Image, IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, OUT UINT16 *ImageMajorVersion, OUT UINT16 *ImageMinorVersion)
EFI_STATUS GetExportEntryAddress(IN CONST CHAR8 *ExportName, IN EFI_PHYSICAL_ADDRESS ImageBaseAddress, IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress)
#define DEBUG(Expression)
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
#define EFI_IMAGE_MACHINE_AARCH64
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_IMAGE_MACHINE_IA32
#define EFI_IMAGE_MACHINE_X64