|
@@ -9,23 +9,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
#include "Host.h"
|
|
#include "Host.h"
|
|
|
|
|
|
#ifdef __APPLE__
|
|
#ifdef __APPLE__
|
|
-#define MAP_ANONYMOUS MAP_ANON
|
|
|
|
|
|
+#define MAP_ANONYMOUS MAP_ANON
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
// Globals
|
|
// Globals
|
|
//
|
|
//
|
|
|
|
|
|
-EMU_THUNK_PPI mSecEmuThunkPpi = {
|
|
|
|
|
|
+EMU_THUNK_PPI mSecEmuThunkPpi = {
|
|
GasketSecUnixPeiAutoScan,
|
|
GasketSecUnixPeiAutoScan,
|
|
GasketSecUnixFdAddress,
|
|
GasketSecUnixFdAddress,
|
|
GasketSecEmuThunkAddress
|
|
GasketSecEmuThunkAddress
|
|
};
|
|
};
|
|
|
|
|
|
-char *gGdbWorkingFileName = NULL;
|
|
|
|
-unsigned int mScriptSymbolChangesCount = 0;
|
|
|
|
-
|
|
|
|
|
|
+char *gGdbWorkingFileName = NULL;
|
|
|
|
+unsigned int mScriptSymbolChangesCount = 0;
|
|
|
|
|
|
//
|
|
//
|
|
// Default information about where the FD is located.
|
|
// Default information about where the FD is located.
|
|
@@ -34,8 +32,8 @@ unsigned int mScriptSymbolChangesCount = 0;
|
|
// The number of array elements is allocated base on parsing
|
|
// The number of array elements is allocated base on parsing
|
|
// EFI_FIRMWARE_VOLUMES and the memory is never freed.
|
|
// EFI_FIRMWARE_VOLUMES and the memory is never freed.
|
|
//
|
|
//
|
|
-UINTN gFdInfoCount = 0;
|
|
|
|
-EMU_FD_INFO *gFdInfo;
|
|
|
|
|
|
+UINTN gFdInfoCount = 0;
|
|
|
|
+EMU_FD_INFO *gFdInfo;
|
|
|
|
|
|
//
|
|
//
|
|
// Array that supports separate memory ranges.
|
|
// Array that supports separate memory ranges.
|
|
@@ -46,16 +44,12 @@ EMU_FD_INFO *gFdInfo;
|
|
UINTN gSystemMemoryCount = 0;
|
|
UINTN gSystemMemoryCount = 0;
|
|
EMU_SYSTEM_MEMORY *gSystemMemory;
|
|
EMU_SYSTEM_MEMORY *gSystemMemory;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
UINTN mImageContextModHandleArraySize = 0;
|
|
UINTN mImageContextModHandleArraySize = 0;
|
|
-IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL;
|
|
|
|
|
|
+IMAGE_CONTEXT_TO_MOD_HANDLE *mImageContextModHandleArray = NULL;
|
|
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *gPpiList;
|
|
EFI_PEI_PPI_DESCRIPTOR *gPpiList;
|
|
|
|
|
|
-
|
|
|
|
-int gInXcode = 0;
|
|
|
|
-
|
|
|
|
|
|
+int gInXcode = 0;
|
|
|
|
|
|
/*++
|
|
/*++
|
|
Breakpoint target for Xcode project. Set in the Xcode XML
|
|
Breakpoint target for Xcode project. Set in the Xcode XML
|
|
@@ -71,8 +65,6 @@ SecGdbConfigBreak (
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -121,8 +113,8 @@ main (
|
|
// If dlopen doesn't work, then we build a gdb script to allow the
|
|
// If dlopen doesn't work, then we build a gdb script to allow the
|
|
// symbols to be loaded.
|
|
// symbols to be loaded.
|
|
//
|
|
//
|
|
- Index = strlen (*Argv);
|
|
|
|
- gGdbWorkingFileName = AllocatePool (Index + strlen(".gdb") + 1);
|
|
|
|
|
|
+ Index = strlen (*Argv);
|
|
|
|
+ gGdbWorkingFileName = AllocatePool (Index + strlen (".gdb") + 1);
|
|
strcpy (gGdbWorkingFileName, *Argv);
|
|
strcpy (gGdbWorkingFileName, *Argv);
|
|
strcat (gGdbWorkingFileName, ".gdb");
|
|
strcat (gGdbWorkingFileName, ".gdb");
|
|
|
|
|
|
@@ -139,8 +131,8 @@ main (
|
|
setbuf (stdout, 0);
|
|
setbuf (stdout, 0);
|
|
setbuf (stderr, 0);
|
|
setbuf (stderr, 0);
|
|
|
|
|
|
- MemorySizeStr = (CHAR16 *) PcdGetPtr (PcdEmuMemorySize);
|
|
|
|
- FirmwareVolumesStr = (CHAR16 *) PcdGetPtr (PcdEmuFirmwareVolume);
|
|
|
|
|
|
+ MemorySizeStr = (CHAR16 *)PcdGetPtr (PcdEmuMemorySize);
|
|
|
|
+ FirmwareVolumesStr = (CHAR16 *)PcdGetPtr (PcdEmuFirmwareVolume);
|
|
|
|
|
|
//
|
|
//
|
|
// PPIs pased into PEI_CORE
|
|
// PPIs pased into PEI_CORE
|
|
@@ -169,17 +161,18 @@ main (
|
|
//
|
|
//
|
|
// Allocate space for gSystemMemory Array
|
|
// Allocate space for gSystemMemory Array
|
|
//
|
|
//
|
|
- gSystemMemoryCount = CountSeparatorsInString (MemorySizeStr, '!') + 1;
|
|
|
|
- gSystemMemory = AllocateZeroPool (gSystemMemoryCount * sizeof (EMU_SYSTEM_MEMORY));
|
|
|
|
|
|
+ gSystemMemoryCount = CountSeparatorsInString (MemorySizeStr, '!') + 1;
|
|
|
|
+ gSystemMemory = AllocateZeroPool (gSystemMemoryCount * sizeof (EMU_SYSTEM_MEMORY));
|
|
if (gSystemMemory == NULL) {
|
|
if (gSystemMemory == NULL) {
|
|
printf ("ERROR : Can not allocate memory for system. Exiting.\n");
|
|
printf ("ERROR : Can not allocate memory for system. Exiting.\n");
|
|
exit (1);
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
+
|
|
//
|
|
//
|
|
// Allocate space for gSystemMemory Array
|
|
// Allocate space for gSystemMemory Array
|
|
//
|
|
//
|
|
- gFdInfoCount = CountSeparatorsInString (FirmwareVolumesStr, '!') + 1;
|
|
|
|
- gFdInfo = AllocateZeroPool (gFdInfoCount * sizeof (EMU_FD_INFO));
|
|
|
|
|
|
+ gFdInfoCount = CountSeparatorsInString (FirmwareVolumesStr, '!') + 1;
|
|
|
|
+ gFdInfo = AllocateZeroPool (gFdInfoCount * sizeof (EMU_FD_INFO));
|
|
if (gFdInfo == NULL) {
|
|
if (gFdInfo == NULL) {
|
|
printf ("ERROR : Can not allocate memory for fd info. Exiting.\n");
|
|
printf ("ERROR : Can not allocate memory for fd info. Exiting.\n");
|
|
exit (1);
|
|
exit (1);
|
|
@@ -192,31 +185,35 @@ main (
|
|
// on a real platform this would be SRAM, or using the cache as RAM.
|
|
// on a real platform this would be SRAM, or using the cache as RAM.
|
|
// Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping
|
|
// Set InitialStackMemory to zero so UnixOpenFile will allocate a new mapping
|
|
//
|
|
//
|
|
- InitialStackMemorySize = STACK_SIZE;
|
|
|
|
- InitialStackMemory = (UINTN)MapMemory (
|
|
|
|
- 0, (UINT32) InitialStackMemorySize,
|
|
|
|
- PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE
|
|
|
|
- );
|
|
|
|
|
|
+ InitialStackMemorySize = STACK_SIZE;
|
|
|
|
+ InitialStackMemory = (UINTN)MapMemory (
|
|
|
|
+ 0,
|
|
|
|
+ (UINT32)InitialStackMemorySize,
|
|
|
|
+ PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
+ MAP_ANONYMOUS | MAP_PRIVATE
|
|
|
|
+ );
|
|
if (InitialStackMemory == 0) {
|
|
if (InitialStackMemory == 0) {
|
|
printf ("ERROR : Can not open SecStack Exiting\n");
|
|
printf ("ERROR : Can not open SecStack Exiting\n");
|
|
exit (1);
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
|
|
- printf (" OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n",
|
|
|
|
|
|
+ printf (
|
|
|
|
+ " OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n",
|
|
(unsigned int)(InitialStackMemorySize / 1024),
|
|
(unsigned int)(InitialStackMemorySize / 1024),
|
|
(unsigned long)InitialStackMemory
|
|
(unsigned long)InitialStackMemory
|
|
);
|
|
);
|
|
|
|
|
|
- for (StackPointer = (UINTN*) (UINTN) InitialStackMemory;
|
|
|
|
- StackPointer < (UINTN*)(UINTN)((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize);
|
|
|
|
- StackPointer ++) {
|
|
|
|
|
|
+ for (StackPointer = (UINTN *)(UINTN)InitialStackMemory;
|
|
|
|
+ StackPointer < (UINTN *)(UINTN)((UINTN)InitialStackMemory + (UINT64)InitialStackMemorySize);
|
|
|
|
+ StackPointer++)
|
|
|
|
+ {
|
|
*StackPointer = 0x5AA55AA5;
|
|
*StackPointer = 0x5AA55AA5;
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
// Open All the firmware volumes and remember the info in the gFdInfo global
|
|
// Open All the firmware volumes and remember the info in the gFdInfo global
|
|
//
|
|
//
|
|
- FileName = (CHAR8 *) AllocatePool (StrLen (FirmwareVolumesStr) + 1);
|
|
|
|
|
|
+ FileName = (CHAR8 *)AllocatePool (StrLen (FirmwareVolumesStr) + 1);
|
|
if (FileName == NULL) {
|
|
if (FileName == NULL) {
|
|
printf ("ERROR : Can not allocate memory for firmware volume string\n");
|
|
printf ("ERROR : Can not allocate memory for firmware volume string\n");
|
|
exit (1);
|
|
exit (1);
|
|
@@ -225,39 +222,43 @@ main (
|
|
Index2 = 0;
|
|
Index2 = 0;
|
|
for (Done = FALSE, Index = 0, PeiIndex = 0, SecFile = NULL;
|
|
for (Done = FALSE, Index = 0, PeiIndex = 0, SecFile = NULL;
|
|
FirmwareVolumesStr[Index2] != 0;
|
|
FirmwareVolumesStr[Index2] != 0;
|
|
- Index++) {
|
|
|
|
|
|
+ Index++)
|
|
|
|
+ {
|
|
for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++) {
|
|
for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++) {
|
|
FileName[Index1++] = FirmwareVolumesStr[Index2];
|
|
FileName[Index1++] = FirmwareVolumesStr[Index2];
|
|
}
|
|
}
|
|
|
|
+
|
|
if (FirmwareVolumesStr[Index2] == '!') {
|
|
if (FirmwareVolumesStr[Index2] == '!') {
|
|
Index2++;
|
|
Index2++;
|
|
}
|
|
}
|
|
- FileName[Index1] = '\0';
|
|
|
|
|
|
+
|
|
|
|
+ FileName[Index1] = '\0';
|
|
|
|
|
|
if (Index == 0) {
|
|
if (Index == 0) {
|
|
// Map FV Recovery Read Only and other areas Read/Write
|
|
// Map FV Recovery Read Only and other areas Read/Write
|
|
Status = MapFd0 (
|
|
Status = MapFd0 (
|
|
- FileName,
|
|
|
|
- &gFdInfo[0].Address,
|
|
|
|
- &gFdInfo[0].Size
|
|
|
|
- );
|
|
|
|
|
|
+ FileName,
|
|
|
|
+ &gFdInfo[0].Address,
|
|
|
|
+ &gFdInfo[0].Size
|
|
|
|
+ );
|
|
} else {
|
|
} else {
|
|
//
|
|
//
|
|
// Open the FD and remember where it got mapped into our processes address space
|
|
// Open the FD and remember where it got mapped into our processes address space
|
|
// Maps Read Only
|
|
// Maps Read Only
|
|
//
|
|
//
|
|
Status = MapFile (
|
|
Status = MapFile (
|
|
- FileName,
|
|
|
|
- &gFdInfo[Index].Address,
|
|
|
|
- &gFdInfo[Index].Size
|
|
|
|
- );
|
|
|
|
|
|
+ FileName,
|
|
|
|
+ &gFdInfo[Index].Address,
|
|
|
|
+ &gFdInfo[Index].Size
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
+
|
|
if (EFI_ERROR (Status)) {
|
|
if (EFI_ERROR (Status)) {
|
|
printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, (unsigned int)Status);
|
|
printf ("ERROR : Can not open Firmware Device File %s (%x). Exiting.\n", FileName, (unsigned int)Status);
|
|
exit (1);
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
|
|
- printf (" FD loaded from %s at 0x%08lx",FileName, (unsigned long)gFdInfo[Index].Address);
|
|
|
|
|
|
+ printf (" FD loaded from %s at 0x%08lx", FileName, (unsigned long)gFdInfo[Index].Address);
|
|
|
|
|
|
if (SecFile == NULL) {
|
|
if (SecFile == NULL) {
|
|
//
|
|
//
|
|
@@ -265,11 +266,11 @@ main (
|
|
// Load the first one we find.
|
|
// Load the first one we find.
|
|
//
|
|
//
|
|
FileHandle = NULL;
|
|
FileHandle = NULL;
|
|
- Status = PeiServicesFfsFindNextFile (
|
|
|
|
- EFI_FV_FILETYPE_SECURITY_CORE,
|
|
|
|
- (EFI_PEI_FV_HANDLE)(UINTN)gFdInfo[Index].Address,
|
|
|
|
- &FileHandle
|
|
|
|
- );
|
|
|
|
|
|
+ Status = PeiServicesFfsFindNextFile (
|
|
|
|
+ EFI_FV_FILETYPE_SECURITY_CORE,
|
|
|
|
+ (EFI_PEI_FV_HANDLE)(UINTN)gFdInfo[Index].Address,
|
|
|
|
+ &FileHandle
|
|
|
|
+ );
|
|
if (!EFI_ERROR (Status)) {
|
|
if (!EFI_ERROR (Status)) {
|
|
Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SecFile);
|
|
Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SecFile);
|
|
if (!EFI_ERROR (Status)) {
|
|
if (!EFI_ERROR (Status)) {
|
|
@@ -293,9 +294,9 @@ main (
|
|
// map this memory into the SEC process memory space.
|
|
// map this memory into the SEC process memory space.
|
|
//
|
|
//
|
|
Index1 = 0;
|
|
Index1 = 0;
|
|
- Index = 0;
|
|
|
|
|
|
+ Index = 0;
|
|
while (1) {
|
|
while (1) {
|
|
- UINTN val = 0;
|
|
|
|
|
|
+ UINTN val = 0;
|
|
//
|
|
//
|
|
// Save the size of the memory.
|
|
// Save the size of the memory.
|
|
//
|
|
//
|
|
@@ -303,10 +304,12 @@ main (
|
|
val = val * 10 + MemorySizeStr[Index1] - '0';
|
|
val = val * 10 + MemorySizeStr[Index1] - '0';
|
|
Index1++;
|
|
Index1++;
|
|
}
|
|
}
|
|
|
|
+
|
|
gSystemMemory[Index++].Size = val * 0x100000;
|
|
gSystemMemory[Index++].Size = val * 0x100000;
|
|
if (MemorySizeStr[Index1] == 0) {
|
|
if (MemorySizeStr[Index1] == 0) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
Index1++;
|
|
Index1++;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -315,7 +318,7 @@ main (
|
|
//
|
|
//
|
|
// Hand off to SEC
|
|
// Hand off to SEC
|
|
//
|
|
//
|
|
- SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, SecFile);
|
|
|
|
|
|
+ SecLoadFromCore ((UINTN)InitialStackMemory, (UINTN)InitialStackMemorySize, (UINTN)gFdInfo[0].Address, SecFile);
|
|
|
|
|
|
//
|
|
//
|
|
// If we get here, then the SEC Core returned. This is an error as SEC should
|
|
// If we get here, then the SEC Core returned. This is an error as SEC should
|
|
@@ -325,40 +328,40 @@ main (
|
|
exit (1);
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
EFI_PHYSICAL_ADDRESS *
|
|
EFI_PHYSICAL_ADDRESS *
|
|
MapMemory (
|
|
MapMemory (
|
|
- IN INTN fd,
|
|
|
|
- IN UINT64 length,
|
|
|
|
- IN INTN prot,
|
|
|
|
- IN INTN flags
|
|
|
|
|
|
+ IN INTN fd,
|
|
|
|
+ IN UINT64 length,
|
|
|
|
+ IN INTN prot,
|
|
|
|
+ IN INTN flags
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- STATIC UINTN base = 0x40000000;
|
|
|
|
- CONST UINTN align = (1 << 24);
|
|
|
|
- VOID *res = NULL;
|
|
|
|
- BOOLEAN isAligned = 0;
|
|
|
|
|
|
+ STATIC UINTN base = 0x40000000;
|
|
|
|
+ CONST UINTN align = (1 << 24);
|
|
|
|
+ VOID *res = NULL;
|
|
|
|
+ BOOLEAN isAligned = 0;
|
|
|
|
|
|
//
|
|
//
|
|
// Try to get an aligned block somewhere in the address space of this
|
|
// Try to get an aligned block somewhere in the address space of this
|
|
// process.
|
|
// process.
|
|
//
|
|
//
|
|
- while((!isAligned) && (base != 0)) {
|
|
|
|
|
|
+ while ((!isAligned) && (base != 0)) {
|
|
res = mmap ((void *)base, length, prot, flags, fd, 0);
|
|
res = mmap ((void *)base, length, prot, flags, fd, 0);
|
|
if (res == MAP_FAILED) {
|
|
if (res == MAP_FAILED) {
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
+
|
|
if ((((UINTN)res) & ~(align-1)) == (UINTN)res) {
|
|
if ((((UINTN)res) & ~(align-1)) == (UINTN)res) {
|
|
- isAligned=1;
|
|
|
|
|
|
+ isAligned = 1;
|
|
} else {
|
|
} else {
|
|
- munmap(res, length);
|
|
|
|
|
|
+ munmap (res, length);
|
|
base += align;
|
|
base += align;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -389,16 +392,16 @@ MapFile (
|
|
OUT UINT64 *Length
|
|
OUT UINT64 *Length
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- int fd;
|
|
|
|
- VOID *res;
|
|
|
|
- UINTN FileSize;
|
|
|
|
|
|
+ int fd;
|
|
|
|
+ VOID *res;
|
|
|
|
+ UINTN FileSize;
|
|
|
|
|
|
fd = open (FileName, O_RDWR);
|
|
fd = open (FileName, O_RDWR);
|
|
if (fd < 0) {
|
|
if (fd < 0) {
|
|
return EFI_NOT_FOUND;
|
|
return EFI_NOT_FOUND;
|
|
}
|
|
}
|
|
- FileSize = lseek (fd, 0, SEEK_END);
|
|
|
|
|
|
|
|
|
|
+ FileSize = lseek (fd, 0, SEEK_END);
|
|
|
|
|
|
res = MapMemory (fd, FileSize, PROT_READ | PROT_EXEC, MAP_PRIVATE);
|
|
res = MapMemory (fd, FileSize, PROT_READ | PROT_EXEC, MAP_PRIVATE);
|
|
|
|
|
|
@@ -409,8 +412,8 @@ MapFile (
|
|
return EFI_DEVICE_ERROR;
|
|
return EFI_DEVICE_ERROR;
|
|
}
|
|
}
|
|
|
|
|
|
- *Length = (UINT64) FileSize;
|
|
|
|
- *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res;
|
|
|
|
|
|
+ *Length = (UINT64)FileSize;
|
|
|
|
+ *BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)res;
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
return EFI_SUCCESS;
|
|
}
|
|
}
|
|
@@ -422,16 +425,17 @@ MapFd0 (
|
|
OUT UINT64 *Length
|
|
OUT UINT64 *Length
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- int fd;
|
|
|
|
- void *res, *res2, *res3;
|
|
|
|
- UINTN FileSize;
|
|
|
|
- UINTN FvSize;
|
|
|
|
- void *EmuMagicPage;
|
|
|
|
|
|
+ int fd;
|
|
|
|
+ void *res, *res2, *res3;
|
|
|
|
+ UINTN FileSize;
|
|
|
|
+ UINTN FvSize;
|
|
|
|
+ void *EmuMagicPage;
|
|
|
|
|
|
fd = open (FileName, O_RDWR);
|
|
fd = open (FileName, O_RDWR);
|
|
if (fd < 0) {
|
|
if (fd < 0) {
|
|
return EFI_NOT_FOUND;
|
|
return EFI_NOT_FOUND;
|
|
}
|
|
}
|
|
|
|
+
|
|
FileSize = lseek (fd, 0, SEEK_END);
|
|
FileSize = lseek (fd, 0, SEEK_END);
|
|
|
|
|
|
FvSize = FixedPcdGet64 (PcdEmuFlashFvRecoverySize);
|
|
FvSize = FixedPcdGet64 (PcdEmuFlashFvRecoverySize);
|
|
@@ -469,13 +473,13 @@ MapFd0 (
|
|
|
|
|
|
// Map the rest of the FD as read/write
|
|
// Map the rest of the FD as read/write
|
|
res2 = mmap (
|
|
res2 = mmap (
|
|
- (void *)(UINTN)(FixedPcdGet64 (PcdEmuFlashFvRecoveryBase) + FvSize),
|
|
|
|
- FileSize - FvSize,
|
|
|
|
- PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
- MAP_SHARED,
|
|
|
|
- fd,
|
|
|
|
- FvSize
|
|
|
|
- );
|
|
|
|
|
|
+ (void *)(UINTN)(FixedPcdGet64 (PcdEmuFlashFvRecoveryBase) + FvSize),
|
|
|
|
+ FileSize - FvSize,
|
|
|
|
+ PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
+ MAP_SHARED,
|
|
|
|
+ fd,
|
|
|
|
+ FvSize
|
|
|
|
+ );
|
|
close (fd);
|
|
close (fd);
|
|
if (res2 == MAP_FAILED) {
|
|
if (res2 == MAP_FAILED) {
|
|
perror ("MapFd0() Failed res2 =");
|
|
perror ("MapFd0() Failed res2 =");
|
|
@@ -504,13 +508,12 @@ MapFd0 (
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- *Length = (UINT64) FileSize;
|
|
|
|
- *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res;
|
|
|
|
|
|
+ *Length = (UINT64)FileSize;
|
|
|
|
+ *BaseAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)res;
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
return EFI_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -528,24 +531,24 @@ Returns:
|
|
**/
|
|
**/
|
|
VOID
|
|
VOID
|
|
SecLoadFromCore (
|
|
SecLoadFromCore (
|
|
- IN UINTN LargestRegion,
|
|
|
|
- IN UINTN LargestRegionSize,
|
|
|
|
- IN UINTN BootFirmwareVolumeBase,
|
|
|
|
- IN VOID *PeiCorePe32File
|
|
|
|
|
|
+ IN UINTN LargestRegion,
|
|
|
|
+ IN UINTN LargestRegionSize,
|
|
|
|
+ IN UINTN BootFirmwareVolumeBase,
|
|
|
|
+ IN VOID *PeiCorePe32File
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- EFI_STATUS Status;
|
|
|
|
- EFI_PHYSICAL_ADDRESS TopOfMemory;
|
|
|
|
- VOID *TopOfStack;
|
|
|
|
- EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint;
|
|
|
|
- EFI_SEC_PEI_HAND_OFF *SecCoreData;
|
|
|
|
- UINTN PeiStackSize;
|
|
|
|
|
|
+ EFI_STATUS Status;
|
|
|
|
+ EFI_PHYSICAL_ADDRESS TopOfMemory;
|
|
|
|
+ VOID *TopOfStack;
|
|
|
|
+ EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint;
|
|
|
|
+ EFI_SEC_PEI_HAND_OFF *SecCoreData;
|
|
|
|
+ UINTN PeiStackSize;
|
|
|
|
|
|
//
|
|
//
|
|
// Compute Top Of Memory for Stack and PEI Core Allocations
|
|
// Compute Top Of Memory for Stack and PEI Core Allocations
|
|
//
|
|
//
|
|
TopOfMemory = LargestRegion + LargestRegionSize;
|
|
TopOfMemory = LargestRegion + LargestRegionSize;
|
|
- PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
|
|
|
|
|
|
+ PeiStackSize = (UINTN)RShiftU64 ((UINT64)STACK_SIZE, 1);
|
|
|
|
|
|
//
|
|
//
|
|
// |-----------| <---- TemporaryRamBase + TemporaryRamSize
|
|
// |-----------| <---- TemporaryRamBase + TemporaryRamSize
|
|
@@ -562,22 +565,21 @@ SecLoadFromCore (
|
|
//
|
|
//
|
|
// Reservet space for storing PeiCore's parament in stack.
|
|
// Reservet space for storing PeiCore's parament in stack.
|
|
//
|
|
//
|
|
- TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
|
|
|
|
- TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
|
|
|
-
|
|
|
|
|
|
+ TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
|
|
|
|
+ TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
|
|
|
|
|
//
|
|
//
|
|
// Bind this information into the SEC hand-off state
|
|
// Bind this information into the SEC hand-off state
|
|
//
|
|
//
|
|
- SecCoreData = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack;
|
|
|
|
- SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
|
|
|
|
- SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
|
|
|
|
|
|
+ SecCoreData = (EFI_SEC_PEI_HAND_OFF *)(UINTN)TopOfStack;
|
|
|
|
+ SecCoreData->DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
|
|
|
|
+ SecCoreData->BootFirmwareVolumeBase = (VOID *)BootFirmwareVolumeBase;
|
|
SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdEmuFirmwareFdSize);
|
|
SecCoreData->BootFirmwareVolumeSize = PcdGet32 (PcdEmuFirmwareFdSize);
|
|
- SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion;
|
|
|
|
|
|
+ SecCoreData->TemporaryRamBase = (VOID *)(UINTN)LargestRegion;
|
|
SecCoreData->TemporaryRamSize = STACK_SIZE;
|
|
SecCoreData->TemporaryRamSize = STACK_SIZE;
|
|
SecCoreData->StackBase = SecCoreData->TemporaryRamBase;
|
|
SecCoreData->StackBase = SecCoreData->TemporaryRamBase;
|
|
SecCoreData->StackSize = PeiStackSize;
|
|
SecCoreData->StackSize = PeiStackSize;
|
|
- SecCoreData->PeiTemporaryRamBase = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);
|
|
|
|
|
|
+ SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN)SecCoreData->TemporaryRamBase + PeiStackSize);
|
|
SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize;
|
|
SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize;
|
|
|
|
|
|
//
|
|
//
|
|
@@ -585,14 +587,14 @@ SecLoadFromCore (
|
|
//
|
|
//
|
|
Status = SecPeCoffGetEntryPoint (PeiCorePe32File, (VOID **)&PeiCoreEntryPoint);
|
|
Status = SecPeCoffGetEntryPoint (PeiCorePe32File, (VOID **)&PeiCoreEntryPoint);
|
|
if (EFI_ERROR (Status)) {
|
|
if (EFI_ERROR (Status)) {
|
|
- return ;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
//
|
|
// Transfer control to the SEC Core
|
|
// Transfer control to the SEC Core
|
|
//
|
|
//
|
|
PeiSwitchStacks (
|
|
PeiSwitchStacks (
|
|
- (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,
|
|
|
|
|
|
+ (SWITCH_STACK_ENTRY_POINT)(UINTN)PeiCoreEntryPoint,
|
|
SecCoreData,
|
|
SecCoreData,
|
|
(VOID *)gPpiList,
|
|
(VOID *)gPpiList,
|
|
TopOfStack
|
|
TopOfStack
|
|
@@ -600,10 +602,9 @@ SecLoadFromCore (
|
|
//
|
|
//
|
|
// If we get here, then the SEC Core returned. This is an error
|
|
// If we get here, then the SEC Core returned. This is an error
|
|
//
|
|
//
|
|
- return ;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -631,29 +632,30 @@ SecUnixPeiAutoScan (
|
|
OUT UINT64 *MemorySize
|
|
OUT UINT64 *MemorySize
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- void *res;
|
|
|
|
|
|
+ void *res;
|
|
|
|
|
|
if (Index >= gSystemMemoryCount) {
|
|
if (Index >= gSystemMemoryCount) {
|
|
return EFI_UNSUPPORTED;
|
|
return EFI_UNSUPPORTED;
|
|
}
|
|
}
|
|
|
|
|
|
*MemoryBase = 0;
|
|
*MemoryBase = 0;
|
|
- res = MapMemory (
|
|
|
|
- 0, gSystemMemory[Index].Size,
|
|
|
|
- PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
- MAP_PRIVATE | MAP_ANONYMOUS
|
|
|
|
- );
|
|
|
|
|
|
+ res = MapMemory (
|
|
|
|
+ 0,
|
|
|
|
+ gSystemMemory[Index].Size,
|
|
|
|
+ PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
+ MAP_PRIVATE | MAP_ANONYMOUS
|
|
|
|
+ );
|
|
if (res == MAP_FAILED) {
|
|
if (res == MAP_FAILED) {
|
|
return EFI_DEVICE_ERROR;
|
|
return EFI_DEVICE_ERROR;
|
|
}
|
|
}
|
|
- *MemorySize = gSystemMemory[Index].Size;
|
|
|
|
- *MemoryBase = (UINTN)res;
|
|
|
|
|
|
+
|
|
|
|
+ *MemorySize = gSystemMemory[Index].Size;
|
|
|
|
+ *MemoryBase = (UINTN)res;
|
|
gSystemMemory[Index].Memory = *MemoryBase;
|
|
gSystemMemory[Index].Memory = *MemoryBase;
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
return EFI_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -675,7 +677,7 @@ Returns:
|
|
**/
|
|
**/
|
|
BOOLEAN
|
|
BOOLEAN
|
|
EfiSystemMemoryRange (
|
|
EfiSystemMemoryRange (
|
|
- IN VOID *MemoryAddress
|
|
|
|
|
|
+ IN VOID *MemoryAddress
|
|
)
|
|
)
|
|
{
|
|
{
|
|
UINTN Index;
|
|
UINTN Index;
|
|
@@ -684,7 +686,8 @@ EfiSystemMemoryRange (
|
|
MemoryBase = (EFI_PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
|
|
MemoryBase = (EFI_PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
|
|
for (Index = 0; Index < gSystemMemoryCount; Index++) {
|
|
for (Index = 0; Index < gSystemMemoryCount; Index++) {
|
|
if ((MemoryBase >= gSystemMemory[Index].Memory) &&
|
|
if ((MemoryBase >= gSystemMemory[Index].Memory) &&
|
|
- (MemoryBase < (gSystemMemory[Index].Memory + gSystemMemory[Index].Size)) ) {
|
|
|
|
|
|
+ (MemoryBase < (gSystemMemory[Index].Memory + gSystemMemory[Index].Size)))
|
|
|
|
+ {
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -692,7 +695,6 @@ EfiSystemMemoryRange (
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -715,8 +717,6 @@ SecEmuThunkAddress (
|
|
return &gEmuThunkProtocol;
|
|
return &gEmuThunkProtocol;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
RETURN_STATUS
|
|
RETURN_STATUS
|
|
EFIAPI
|
|
EFIAPI
|
|
SecPeCoffGetEntryPoint (
|
|
SecPeCoffGetEntryPoint (
|
|
@@ -728,10 +728,10 @@ SecPeCoffGetEntryPoint (
|
|
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
|
|
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
|
|
|
|
|
|
ZeroMem (&ImageContext, sizeof (ImageContext));
|
|
ZeroMem (&ImageContext, sizeof (ImageContext));
|
|
- ImageContext.Handle = Pe32Data;
|
|
|
|
- ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead;
|
|
|
|
|
|
+ ImageContext.Handle = Pe32Data;
|
|
|
|
+ ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)SecImageRead;
|
|
|
|
|
|
- Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
|
|
|
|
|
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
|
if (EFI_ERROR (Status)) {
|
|
if (EFI_ERROR (Status)) {
|
|
return Status;
|
|
return Status;
|
|
}
|
|
}
|
|
@@ -741,7 +741,7 @@ SecPeCoffGetEntryPoint (
|
|
// Relocate image to match the address where it resides
|
|
// Relocate image to match the address where it resides
|
|
//
|
|
//
|
|
ImageContext.ImageAddress = (UINTN)Pe32Data;
|
|
ImageContext.ImageAddress = (UINTN)Pe32Data;
|
|
- Status = PeCoffLoaderLoadImage (&ImageContext);
|
|
|
|
|
|
+ Status = PeCoffLoaderLoadImage (&ImageContext);
|
|
if (EFI_ERROR (Status)) {
|
|
if (EFI_ERROR (Status)) {
|
|
return Status;
|
|
return Status;
|
|
}
|
|
}
|
|
@@ -755,10 +755,11 @@ SecPeCoffGetEntryPoint (
|
|
// Or just return image entry point
|
|
// Or just return image entry point
|
|
//
|
|
//
|
|
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer (Pe32Data);
|
|
ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer (Pe32Data);
|
|
- Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
|
|
|
|
|
|
+ Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
|
|
if (EFI_ERROR (Status)) {
|
|
if (EFI_ERROR (Status)) {
|
|
return Status;
|
|
return Status;
|
|
}
|
|
}
|
|
|
|
+
|
|
ImageContext.EntryPoint = (UINTN)*EntryPoint;
|
|
ImageContext.EntryPoint = (UINTN)*EntryPoint;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -769,8 +770,6 @@ SecPeCoffGetEntryPoint (
|
|
return Status;
|
|
return Status;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -804,7 +803,7 @@ SecUnixFdAddress (
|
|
*FdSize = gFdInfo[Index].Size;
|
|
*FdSize = gFdInfo[Index].Size;
|
|
*FixUp = 0;
|
|
*FixUp = 0;
|
|
|
|
|
|
- if (*FdBase == 0 && *FdSize == 0) {
|
|
|
|
|
|
+ if ((*FdBase == 0) && (*FdSize == 0)) {
|
|
return EFI_UNSUPPORTED;
|
|
return EFI_UNSUPPORTED;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -820,7 +819,6 @@ SecUnixFdAddress (
|
|
return EFI_SUCCESS;
|
|
return EFI_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -836,11 +834,11 @@ Returns:
|
|
**/
|
|
**/
|
|
UINTN
|
|
UINTN
|
|
CountSeparatorsInString (
|
|
CountSeparatorsInString (
|
|
- IN const CHAR16 *String,
|
|
|
|
- IN CHAR16 Separator
|
|
|
|
|
|
+ IN const CHAR16 *String,
|
|
|
|
+ IN CHAR16 Separator
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- UINTN Count;
|
|
|
|
|
|
+ UINTN Count;
|
|
|
|
|
|
for (Count = 0; *String != '\0'; String++) {
|
|
for (Count = 0; *String != '\0'; String++) {
|
|
if (*String == Separator) {
|
|
if (*String == Separator) {
|
|
@@ -851,15 +849,15 @@ CountSeparatorsInString (
|
|
return Count;
|
|
return Count;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
EFI_STATUS
|
|
EFI_STATUS
|
|
EFIAPI
|
|
EFIAPI
|
|
SecImageRead (
|
|
SecImageRead (
|
|
- IN VOID *FileHandle,
|
|
|
|
- IN UINTN FileOffset,
|
|
|
|
- IN OUT UINTN *ReadSize,
|
|
|
|
- OUT VOID *Buffer
|
|
|
|
|
|
+ IN VOID *FileHandle,
|
|
|
|
+ IN UINTN FileOffset,
|
|
|
|
+ IN OUT UINTN *ReadSize,
|
|
|
|
+ OUT VOID *Buffer
|
|
)
|
|
)
|
|
|
|
+
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -876,13 +874,13 @@ Returns:
|
|
|
|
|
|
**/
|
|
**/
|
|
{
|
|
{
|
|
- CHAR8 *Destination8;
|
|
|
|
- CHAR8 *Source8;
|
|
|
|
- UINTN Length;
|
|
|
|
|
|
+ CHAR8 *Destination8;
|
|
|
|
+ CHAR8 *Source8;
|
|
|
|
+ UINTN Length;
|
|
|
|
|
|
- Destination8 = Buffer;
|
|
|
|
- Source8 = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
|
|
|
|
- Length = *ReadSize;
|
|
|
|
|
|
+ Destination8 = Buffer;
|
|
|
|
+ Source8 = (CHAR8 *)((UINTN)FileHandle + FileOffset);
|
|
|
|
+ Length = *ReadSize;
|
|
while (Length--) {
|
|
while (Length--) {
|
|
*(Destination8++) = *(Source8++);
|
|
*(Destination8++) = *(Source8++);
|
|
}
|
|
}
|
|
@@ -890,7 +888,6 @@ Returns:
|
|
return EFI_SUCCESS;
|
|
return EFI_SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -909,14 +906,13 @@ Returns:
|
|
**/
|
|
**/
|
|
EFI_STATUS
|
|
EFI_STATUS
|
|
AddHandle (
|
|
AddHandle (
|
|
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
|
|
|
|
- IN VOID *ModHandle
|
|
|
|
|
|
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
|
|
|
|
+ IN VOID *ModHandle
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- UINTN Index;
|
|
|
|
- IMAGE_CONTEXT_TO_MOD_HANDLE *Array;
|
|
|
|
- UINTN PreviousSize;
|
|
|
|
-
|
|
|
|
|
|
+ UINTN Index;
|
|
|
|
+ IMAGE_CONTEXT_TO_MOD_HANDLE *Array;
|
|
|
|
+ UINTN PreviousSize;
|
|
|
|
|
|
Array = mImageContextModHandleArray;
|
|
Array = mImageContextModHandleArray;
|
|
for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
|
|
for (Index = 0; Index < mImageContextModHandleArraySize; Index++, Array++) {
|
|
@@ -936,7 +932,7 @@ AddHandle (
|
|
// copy the old values to the new location. But it does
|
|
// copy the old values to the new location. But it does
|
|
// not zero the new memory area.
|
|
// not zero the new memory area.
|
|
//
|
|
//
|
|
- PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE);
|
|
|
|
|
|
+ PreviousSize = mImageContextModHandleArraySize * sizeof (IMAGE_CONTEXT_TO_MOD_HANDLE);
|
|
mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE;
|
|
mImageContextModHandleArraySize += MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE;
|
|
|
|
|
|
mImageContextModHandleArray = ReallocatePool (
|
|
mImageContextModHandleArray = ReallocatePool (
|
|
@@ -954,7 +950,6 @@ AddHandle (
|
|
return AddHandle (ImageContext, ModHandle);
|
|
return AddHandle (ImageContext, ModHandle);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/*++
|
|
/*++
|
|
|
|
|
|
Routine Description:
|
|
Routine Description:
|
|
@@ -971,7 +966,7 @@ Returns:
|
|
**/
|
|
**/
|
|
VOID *
|
|
VOID *
|
|
RemoveHandle (
|
|
RemoveHandle (
|
|
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
UINTN Index;
|
|
UINTN Index;
|
|
@@ -998,60 +993,60 @@ RemoveHandle (
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
BOOLEAN
|
|
BOOLEAN
|
|
IsPdbFile (
|
|
IsPdbFile (
|
|
- IN CHAR8 *PdbFileName
|
|
|
|
|
|
+ IN CHAR8 *PdbFileName
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- UINTN Len;
|
|
|
|
|
|
+ UINTN Len;
|
|
|
|
|
|
if (PdbFileName == NULL) {
|
|
if (PdbFileName == NULL) {
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
Len = strlen (PdbFileName);
|
|
Len = strlen (PdbFileName);
|
|
- if ((Len < 5)|| (PdbFileName[Len - 4] != '.')) {
|
|
|
|
|
|
+ if ((Len < 5) || (PdbFileName[Len - 4] != '.')) {
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
- if ((PdbFileName[Len - 3] == 'P' || PdbFileName[Len - 3] == 'p') &&
|
|
|
|
- (PdbFileName[Len - 2] == 'D' || PdbFileName[Len - 2] == 'd') &&
|
|
|
|
- (PdbFileName[Len - 1] == 'B' || PdbFileName[Len - 1] == 'b')) {
|
|
|
|
|
|
+ if (((PdbFileName[Len - 3] == 'P') || (PdbFileName[Len - 3] == 'p')) &&
|
|
|
|
+ ((PdbFileName[Len - 2] == 'D') || (PdbFileName[Len - 2] == 'd')) &&
|
|
|
|
+ ((PdbFileName[Len - 1] == 'B') || (PdbFileName[Len - 1] == 'b')))
|
|
|
|
+ {
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-#define MAX_SPRINT_BUFFER_SIZE 0x200
|
|
|
|
|
|
+#define MAX_SPRINT_BUFFER_SIZE 0x200
|
|
|
|
|
|
void
|
|
void
|
|
PrintLoadAddress (
|
|
PrintLoadAddress (
|
|
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
if (ImageContext->PdbPointer == NULL) {
|
|
if (ImageContext->PdbPointer == NULL) {
|
|
- fprintf (stderr,
|
|
|
|
|
|
+ fprintf (
|
|
|
|
+ stderr,
|
|
"0x%08lx Loading NO DEBUG with entry point 0x%08lx\n",
|
|
"0x%08lx Loading NO DEBUG with entry point 0x%08lx\n",
|
|
(unsigned long)(ImageContext->ImageAddress),
|
|
(unsigned long)(ImageContext->ImageAddress),
|
|
(unsigned long)ImageContext->EntryPoint
|
|
(unsigned long)ImageContext->EntryPoint
|
|
);
|
|
);
|
|
} else {
|
|
} else {
|
|
- fprintf (stderr,
|
|
|
|
|
|
+ fprintf (
|
|
|
|
+ stderr,
|
|
"0x%08lx Loading %s with entry point 0x%08lx\n",
|
|
"0x%08lx Loading %s with entry point 0x%08lx\n",
|
|
(unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders),
|
|
(unsigned long)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders),
|
|
ImageContext->PdbPointer,
|
|
ImageContext->PdbPointer,
|
|
(unsigned long)ImageContext->EntryPoint
|
|
(unsigned long)ImageContext->EntryPoint
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
// Keep output synced up
|
|
// Keep output synced up
|
|
fflush (stderr);
|
|
fflush (stderr);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
Loads the image using dlopen so symbols will be automatically
|
|
Loads the image using dlopen so symbols will be automatically
|
|
loaded by gdb.
|
|
loaded by gdb.
|
|
@@ -1064,18 +1059,17 @@ PrintLoadAddress (
|
|
**/
|
|
**/
|
|
BOOLEAN
|
|
BOOLEAN
|
|
DlLoadImage (
|
|
DlLoadImage (
|
|
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
-
|
|
|
|
-#ifdef __APPLE__
|
|
|
|
|
|
+ #ifdef __APPLE__
|
|
|
|
|
|
return FALSE;
|
|
return FALSE;
|
|
|
|
|
|
-#else
|
|
|
|
|
|
+ #else
|
|
|
|
|
|
- void *Handle = NULL;
|
|
|
|
- void *Entry = NULL;
|
|
|
|
|
|
+ void *Handle = NULL;
|
|
|
|
+ void *Entry = NULL;
|
|
|
|
|
|
if (ImageContext->PdbPointer == NULL) {
|
|
if (ImageContext->PdbPointer == NULL) {
|
|
return FALSE;
|
|
return FALSE;
|
|
@@ -1086,19 +1080,19 @@ DlLoadImage (
|
|
}
|
|
}
|
|
|
|
|
|
fprintf (
|
|
fprintf (
|
|
- stderr,
|
|
|
|
- "Loading %s 0x%08lx - entry point 0x%08lx\n",
|
|
|
|
- ImageContext->PdbPointer,
|
|
|
|
- (unsigned long)ImageContext->ImageAddress,
|
|
|
|
- (unsigned long)ImageContext->EntryPoint
|
|
|
|
- );
|
|
|
|
|
|
+ stderr,
|
|
|
|
+ "Loading %s 0x%08lx - entry point 0x%08lx\n",
|
|
|
|
+ ImageContext->PdbPointer,
|
|
|
|
+ (unsigned long)ImageContext->ImageAddress,
|
|
|
|
+ (unsigned long)ImageContext->EntryPoint
|
|
|
|
+ );
|
|
|
|
|
|
Handle = dlopen (ImageContext->PdbPointer, RTLD_NOW);
|
|
Handle = dlopen (ImageContext->PdbPointer, RTLD_NOW);
|
|
if (Handle != NULL) {
|
|
if (Handle != NULL) {
|
|
Entry = dlsym (Handle, "_ModuleEntryPoint");
|
|
Entry = dlsym (Handle, "_ModuleEntryPoint");
|
|
AddHandle (ImageContext, Handle);
|
|
AddHandle (ImageContext, Handle);
|
|
} else {
|
|
} else {
|
|
- printf("%s\n", dlerror());
|
|
|
|
|
|
+ printf ("%s\n", dlerror ());
|
|
}
|
|
}
|
|
|
|
|
|
if (Entry != NULL) {
|
|
if (Entry != NULL) {
|
|
@@ -1109,25 +1103,23 @@ DlLoadImage (
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
|
|
|
+ #endif
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
#ifdef __APPLE__
|
|
#ifdef __APPLE__
|
|
-__attribute__((noinline))
|
|
|
|
|
|
+__attribute__ ((noinline))
|
|
#endif
|
|
#endif
|
|
VOID
|
|
VOID
|
|
SecGdbScriptBreak (
|
|
SecGdbScriptBreak (
|
|
- char *FileName,
|
|
|
|
- int FileNameLength,
|
|
|
|
- long unsigned int LoadAddress,
|
|
|
|
- int AddSymbolFlag
|
|
|
|
|
|
+ char *FileName,
|
|
|
|
+ int FileNameLength,
|
|
|
|
+ long unsigned int LoadAddress,
|
|
|
|
+ int AddSymbolFlag
|
|
)
|
|
)
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
Adds the image to a gdb script so its symbols can be loaded.
|
|
Adds the image to a gdb script so its symbols can be loaded.
|
|
The AddFirmwareSymbolFile helper macro is used.
|
|
The AddFirmwareSymbolFile helper macro is used.
|
|
@@ -1137,18 +1129,17 @@ SecGdbScriptBreak (
|
|
**/
|
|
**/
|
|
VOID
|
|
VOID
|
|
GdbScriptAddImage (
|
|
GdbScriptAddImage (
|
|
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
-
|
|
|
|
PrintLoadAddress (ImageContext);
|
|
PrintLoadAddress (ImageContext);
|
|
|
|
|
|
- if (ImageContext->PdbPointer != NULL && !IsPdbFile (ImageContext->PdbPointer)) {
|
|
|
|
|
|
+ if ((ImageContext->PdbPointer != NULL) && !IsPdbFile (ImageContext->PdbPointer)) {
|
|
FILE *GdbTempFile;
|
|
FILE *GdbTempFile;
|
|
if (FeaturePcdGet (PcdEmulatorLazyLoadSymbols)) {
|
|
if (FeaturePcdGet (PcdEmulatorLazyLoadSymbols)) {
|
|
GdbTempFile = fopen (gGdbWorkingFileName, "a");
|
|
GdbTempFile = fopen (gGdbWorkingFileName, "a");
|
|
if (GdbTempFile != NULL) {
|
|
if (GdbTempFile != NULL) {
|
|
- long unsigned int SymbolsAddr = (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders);
|
|
|
|
|
|
+ long unsigned int SymbolsAddr = (long unsigned int)(ImageContext->ImageAddress + ImageContext->SizeOfHeaders);
|
|
mScriptSymbolChangesCount++;
|
|
mScriptSymbolChangesCount++;
|
|
fprintf (
|
|
fprintf (
|
|
GdbTempFile,
|
|
GdbTempFile,
|
|
@@ -1188,11 +1179,10 @@ GdbScriptAddImage (
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
VOID
|
|
VOID
|
|
EFIAPI
|
|
EFIAPI
|
|
SecPeCoffRelocateImageExtraAction (
|
|
SecPeCoffRelocateImageExtraAction (
|
|
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
if (!DlLoadImage (ImageContext)) {
|
|
if (!DlLoadImage (ImageContext)) {
|
|
@@ -1200,7 +1190,6 @@ SecPeCoffRelocateImageExtraAction (
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
Adds the image to a gdb script so its symbols can be unloaded.
|
|
Adds the image to a gdb script so its symbols can be unloaded.
|
|
The RemoveFirmwareSymbolFile helper macro is used.
|
|
The RemoveFirmwareSymbolFile helper macro is used.
|
|
@@ -1210,7 +1199,7 @@ SecPeCoffRelocateImageExtraAction (
|
|
**/
|
|
**/
|
|
VOID
|
|
VOID
|
|
GdbScriptRemoveImage (
|
|
GdbScriptRemoveImage (
|
|
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
FILE *GdbTempFile;
|
|
FILE *GdbTempFile;
|
|
@@ -1257,27 +1246,24 @@ GdbScriptRemoveImage (
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
VOID
|
|
VOID
|
|
EFIAPI
|
|
EFIAPI
|
|
SecPeCoffUnloadImageExtraAction (
|
|
SecPeCoffUnloadImageExtraAction (
|
|
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
|
|
|
|
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- VOID *Handle;
|
|
|
|
|
|
+ VOID *Handle;
|
|
|
|
|
|
//
|
|
//
|
|
// Check to see if the image symbols were loaded with gdb script, or dlopen
|
|
// Check to see if the image symbols were loaded with gdb script, or dlopen
|
|
//
|
|
//
|
|
Handle = RemoveHandle (ImageContext);
|
|
Handle = RemoveHandle (ImageContext);
|
|
if (Handle != NULL) {
|
|
if (Handle != NULL) {
|
|
-#ifndef __APPLE__
|
|
|
|
|
|
+ #ifndef __APPLE__
|
|
dlclose (Handle);
|
|
dlclose (Handle);
|
|
-#endif
|
|
|
|
|
|
+ #endif
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
GdbScriptRemoveImage (ImageContext);
|
|
GdbScriptRemoveImage (ImageContext);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|