\r
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {\r
//\r
- // The PE/COFF loader can support loading image types that can be executed. \r
- // If we loaded an image type that we can not execute return EFI_UNSUPORTED. \r
+ // The PE/COFF loader can support loading image types that can be executed.\r
+ // If we loaded an image type that we can not execute return EFI_UNSUPORTED.\r
//\r
return EFI_UNSUPPORTED;\r
}\r
// If the image relocations have not been stripped, then load at any address.\r
// Otherwise load at the address at which it was linked.\r
//\r
- Status = CoreAllocatePages (\r
- (Image->ImageContext.RelocationsStripped) ? AllocateAddress : AllocateAnyPages,\r
- Image->ImageContext.ImageCodeMemoryType,\r
- Image->NumberOfPages,\r
- &Image->ImageContext.ImageAddress\r
- );\r
+ // Memory below 1MB should be treated reserved for CSM and there should be\r
+ // no modules whose preferred load addresses are below 1MB.\r
+ //\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {\r
+ Status = CoreAllocatePages (\r
+ AllocateAddress,\r
+ Image->ImageContext.ImageCodeMemoryType,\r
+ Image->NumberOfPages,\r
+ &Image->ImageContext.ImageAddress\r
+ );\r
+ }\r
+ if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {\r
+ Status = CoreAllocatePages (\r
+ AllocateAnyPages,\r
+ Image->ImageContext.ImageCodeMemoryType,\r
+ Image->NumberOfPages,\r
+ &Image->ImageContext.ImageAddress\r
+ );\r
+ }\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
DstBufAlocated = TRUE;\r
-\r
} else {\r
//\r
// Caller provided the destination buffer\r
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);\r
}\r
}\r
- \r
+\r
//\r
// Fill in the entry point of the image if it is available\r
//\r
//\r
\r
DEBUG_CODE_BEGIN ();\r
- \r
+\r
UINTN Index;\r
UINTN StartIndex;\r
CHAR8 EfiFileName[256];\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));\r
}\r
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
- \r
+\r
DEBUG_CODE_END ();\r
\r
return EFI_SUCCESS;\r
//\r
// Free memory.\r
//\r
- \r
+\r
if (DstBufAlocated) {\r
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);\r
}\r
- \r
+\r
if (Image->ImageContext.FixupData != NULL) {\r
CoreFreePool (Image->ImageContext.FixupData);\r
}\r
\r
SetJumpFlag = SetJump (Image->JumpContext);\r
//\r
- // The initial call to SetJump() must always return 0. \r
- // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump(). \r
+ // The initial call to SetJump() must always return 0.\r
+ // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().\r
//\r
if (!SetJumpFlag) {\r
//\r
}\r
CoreFreePool (Image->RuntimeData);\r
}\r
- \r
+\r
//\r
// Free the Image from memory\r
//\r