]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/DxeCore: invoke the emulator protocol for foreign images
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / DxeMain.h
index 60d85f082ffa5d5f09f907ab8421d9b92b1a6b7a..bbb424bdb00ac59c095fb5cb3ff11361fb936219 100644 (file)
@@ -2,14 +2,8 @@
   The internal header file includes the common header files, defines\r
   internal structure and functions used by DxeCore module.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -53,6 +47,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/TcgService.h>\r
 #include <Protocol/HiiPackageList.h>\r
 #include <Protocol/SmmBase2.h>\r
+#include <Protocol/PeCoffImageEmulator.h>\r
 #include <Guid/MemoryTypeInformation.h>\r
 #include <Guid/FirmwareFileSystem2.h>\r
 #include <Guid/FirmwareFileSystem3.h>\r
@@ -69,7 +64,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/IdleLoopEvent.h>\r
 #include <Guid/VectorHandoffTable.h>\r
 #include <Ppi/VectorHandoffInfo.h>\r
-#include <Guid/ZeroGuid.h>\r
 #include <Guid/MemoryProfile.h>\r
 \r
 #include <Library/DxeCoreEntryPoint.h>\r
@@ -90,7 +84,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DevicePathLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/DxeServicesLib.h>\r
 #include <Library/DebugAgentLib.h>\r
 #include <Library/CpuExceptionHandlerLib.h>\r
@@ -110,8 +103,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 \r
 ///\r
-/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependecy expression\r
-///                        to save time.  A EFI_DEP_PUSH is evauated one an\r
+/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expression\r
+///                        to save time.  A EFI_DEP_PUSH is evaluated one an\r
 ///                        replaced with EFI_DEP_REPLACE_TRUE. If PI spec's Vol 2\r
 ///                        Driver Execution Environment Core Interface use 0xff\r
 ///                        as new DEPEX opcode. EFI_DEP_REPLACE_TRUE should be\r
@@ -124,31 +117,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 #define DEPEX_STACK_SIZE_INCREMENT  0x1000\r
 \r
-#if defined (MDE_CPU_IPF)\r
-///\r
-/// For Itanium machines make the default allocations 8K aligned\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE * 2)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE * 2)\r
-\r
-#elif defined (MDE_CPU_AARCH64)\r
-///\r
-/// 64-bit ARM systems allow the OS to execute with 64 KB page size,\r
-/// so for improved interoperability with the firmware, align the\r
-/// runtime regions to 64 KB as well\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (SIZE_64KB)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)\r
-\r
-#else\r
-///\r
-/// For genric EFI machines make the default allocations 4K aligned\r
-///\r
-#define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT  (EFI_PAGE_SIZE)\r
-#define DEFAULT_PAGE_ALLOCATION                     (EFI_PAGE_SIZE)\r
-\r
-#endif\r
-\r
 typedef struct {\r
   EFI_GUID                    *ProtocolGuid;\r
   VOID                        **Protocol;\r
@@ -224,43 +192,45 @@ typedef struct {
 typedef struct {\r
   UINTN                       Signature;\r
   /// Image handle\r
-  EFI_HANDLE                  Handle;   \r
+  EFI_HANDLE                  Handle;\r
   /// Image type\r
-  UINTN                       Type;           \r
+  UINTN                       Type;\r
   /// If entrypoint has been called\r
-  BOOLEAN                     Started;        \r
+  BOOLEAN                     Started;\r
   /// The image's entry point\r
-  EFI_IMAGE_ENTRY_POINT       EntryPoint;     \r
+  EFI_IMAGE_ENTRY_POINT       EntryPoint;\r
   /// loaded image protocol\r
-  EFI_LOADED_IMAGE_PROTOCOL   Info;           \r
+  EFI_LOADED_IMAGE_PROTOCOL   Info;\r
   /// Location in memory\r
-  EFI_PHYSICAL_ADDRESS        ImageBasePage;  \r
+  EFI_PHYSICAL_ADDRESS        ImageBasePage;\r
   /// Number of pages\r
-  UINTN                       NumberOfPages;  \r
+  UINTN                       NumberOfPages;\r
   /// Original fixup data\r
-  CHAR8                       *FixupData;     \r
+  CHAR8                       *FixupData;\r
   /// Tpl of started image\r
-  EFI_TPL                     Tpl;            \r
+  EFI_TPL                     Tpl;\r
   /// Status returned by started image\r
-  EFI_STATUS                  Status;         \r
+  EFI_STATUS                  Status;\r
   /// Size of ExitData from started image\r
-  UINTN                       ExitDataSize;   \r
+  UINTN                       ExitDataSize;\r
   /// Pointer to exit data from started image\r
-  VOID                        *ExitData;      \r
-  /// Pointer to pool allocation for context save/retore\r
-  VOID                        *JumpBuffer;    \r
-  /// Pointer to buffer for context save/retore\r
-  BASE_LIBRARY_JUMP_BUFFER    *JumpContext;  \r
+  VOID                        *ExitData;\r
+  /// Pointer to pool allocation for context save/restore\r
+  VOID                        *JumpBuffer;\r
+  /// Pointer to buffer for context save/restore\r
+  BASE_LIBRARY_JUMP_BUFFER    *JumpContext;\r
   /// Machine type from PE image\r
-  UINT16                      Machine;        \r
+  UINT16                      Machine;\r
   /// EBC Protocol pointer\r
-  EFI_EBC_PROTOCOL            *Ebc;           \r
+  EFI_EBC_PROTOCOL            *Ebc;\r
+  /// PE/COFF Image Emulator Protocol pointer\r
+  EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL  *PeCoffEmu;\r
   /// Runtime image list\r
-  EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;   \r
-  /// Pointer to Loaded Image Device Path Protocl\r
-  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;  \r
+  EFI_RUNTIME_IMAGE_ENTRY     *RuntimeData;\r
+  /// Pointer to Loaded Image Device Path Protocol\r
+  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;\r
   /// PeCoffLoader ImageContext\r
-  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext; \r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
   /// Status returned by LoadImage() service.\r
   EFI_STATUS                  LoadImageStatus;\r
 } LOADED_IMAGE_PRIVATE_DATA;\r
@@ -268,6 +238,26 @@ typedef struct {
 #define LOADED_IMAGE_PRIVATE_DATA_FROM_THIS(a) \\r
           CR(a, LOADED_IMAGE_PRIVATE_DATA, Info, LOADED_IMAGE_PRIVATE_DATA_SIGNATURE)\r
 \r
+#define IMAGE_PROPERTIES_RECORD_CODE_SECTION_SIGNATURE SIGNATURE_32 ('I','P','R','C')\r
+\r
+typedef struct {\r
+  UINT32                 Signature;\r
+  LIST_ENTRY             Link;\r
+  EFI_PHYSICAL_ADDRESS   CodeSegmentBase;\r
+  UINT64                 CodeSegmentSize;\r
+} IMAGE_PROPERTIES_RECORD_CODE_SECTION;\r
+\r
+#define IMAGE_PROPERTIES_RECORD_SIGNATURE SIGNATURE_32 ('I','P','R','D')\r
+\r
+typedef struct {\r
+  UINT32                 Signature;\r
+  LIST_ENTRY             Link;\r
+  EFI_PHYSICAL_ADDRESS   ImageBase;\r
+  UINT64                 ImageSize;\r
+  UINTN                  CodeSegmentCount;\r
+  LIST_ENTRY             CodeSegmentList;\r
+} IMAGE_PROPERTIES_RECORD;\r
+\r
 //\r
 // DXE Core Global Variables\r
 //\r
@@ -446,7 +436,7 @@ CoreNotifyOnProtocolInstallation (
 \r
 \r
 /**\r
-  Return TRUE if all AP services are availible.\r
+  Return TRUE if all AP services are available.\r
 \r
   @retval EFI_SUCCESS    All AP services are available\r
   @retval EFI_NOT_FOUND  At least one AP service is not available\r
@@ -474,7 +464,7 @@ CalculateEfiHdrCrc (
 /**\r
   Called by the platform code to process a tick.\r
 \r
-  @param  Duration               The number of 100ns elasped since the last call\r
+  @param  Duration               The number of 100ns elapsed since the last call\r
                                  to TimerTick\r
 \r
 **/\r
@@ -1098,7 +1088,7 @@ CoreLocateDevicePath (
   @retval EFI_NOT_FOUND          No handles match the search.\r
   @retval EFI_OUT_OF_RESOURCES   There is not enough pool memory to store the\r
                                  matching results.\r
-  @retval EFI_INVALID_PARAMETER  One or more paramters are not valid.\r
+  @retval EFI_INVALID_PARAMETER  One or more parameters are not valid.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1186,8 +1176,8 @@ CoreConnectHandlesByKey (
   @retval EFI_NOT_FOUND         1) There are no EFI_DRIVER_BINDING_PROTOCOL instances\r
                                 present in the system.\r
                                 2) No drivers were connected to ControllerHandle.\r
-  @retval EFI_SECURITY_VIOLATION \r
-                                The user has no permission to start UEFI device drivers on the device path \r
+  @retval EFI_SECURITY_VIOLATION\r
+                                The user has no permission to start UEFI device drivers on the device path\r
                                 associated with the ControllerHandle or specified by the RemainingDevicePath.\r
 \r
 **/\r
@@ -1432,10 +1422,10 @@ CoreInternalFreePool (
   @retval EFI_LOAD_ERROR          Image was not loaded because the image format was corrupt or not\r
                                   understood.\r
   @retval EFI_DEVICE_ERROR        Image was not loaded because the device returned a read error.\r
-  @retval EFI_ACCESS_DENIED       Image was not loaded because the platform policy prohibits the \r
+  @retval EFI_ACCESS_DENIED       Image was not loaded because the platform policy prohibits the\r
                                   image from being loaded. NULL is returned in *ImageHandle.\r
-  @retval EFI_SECURITY_VIOLATION  Image was loaded and an ImageHandle was created with a \r
-                                  valid EFI_LOADED_IMAGE_PROTOCOL. However, the current \r
+  @retval EFI_SECURITY_VIOLATION  Image was loaded and an ImageHandle was created with a\r
+                                  valid EFI_LOADED_IMAGE_PROTOCOL. However, the current\r
                                   platform policy specifies that the image should not be started.\r
 \r
 **/\r
@@ -1459,7 +1449,7 @@ CoreLoadImage (
                                   unloaded.\r
 \r
   @retval EFI_SUCCESS             The image has been unloaded.\r
-  @retval EFI_UNSUPPORTED         The image has been sarted, and does not support\r
+  @retval EFI_UNSUPPORTED         The image has been started, and does not support\r
                                   unload.\r
   @retval EFI_INVALID_PARAMPETER  ImageHandle is not a valid image handle.\r
 \r
@@ -1842,7 +1832,7 @@ CoreGetMemorySpaceDescriptor (
   @param  Attributes             Specified attributes\r
 \r
   @retval EFI_SUCCESS           The attributes were set for the memory region.\r
-  @retval EFI_INVALID_PARAMETER Length is zero. \r
+  @retval EFI_INVALID_PARAMETER Length is zero.\r
   @retval EFI_UNSUPPORTED       The processor does not support one or more bytes of the memory\r
                                 resource range specified by BaseAddress and Length.\r
   @retval EFI_UNSUPPORTED       The bit mask of attributes is not support for the memory resource\r
@@ -2184,19 +2174,6 @@ CoreDisplayDiscoveredNotDispatched (
   );\r
 \r
 \r
-/**\r
-  Place holder function until all the Boot Services and Runtime Services are\r
-  available.\r
-\r
-  @return EFI_NOT_AVAILABLE_YET\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-CoreEfiNotAvailableYetArg0 (\r
-  VOID\r
-  );\r
-\r
 \r
 /**\r
   Place holder function until all the Boot Services and Runtime Services are\r
@@ -2676,24 +2653,8 @@ CoreReleaseLock (
   IN EFI_LOCK  *Lock\r
   );\r
 \r
-\r
-/**\r
-  An empty function to pass error checking of CreateEventEx ().\r
-\r
-  @param  Event                 Event whose notification function is being invoked.\r
-  @param  Context               Pointer to the notification function's context,\r
-                                which is implementation-dependent.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-CoreEmptyCallbackFunction (\r
-  IN EFI_EVENT                Event,\r
-  IN VOID                     *Context\r
-  );\r
-\r
 /**\r
-  Read data from Firmware Block by FVB protocol Read. \r
+  Read data from Firmware Block by FVB protocol Read.\r
   The data may cross the multi block ranges.\r
 \r
   @param  Fvb                   The FW_VOL_BLOCK_PROTOCOL instance from which to read data.\r
@@ -2875,6 +2836,15 @@ CoreInitializeMemoryAttributesTable (
   VOID\r
   );\r
 \r
+/**\r
+  Initialize Memory Protection support.\r
+**/\r
+VOID\r
+EFIAPI\r
+CoreInitializeMemoryProtection (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Install MemoryAttributesTable on memory allocation.\r
 \r
@@ -2905,4 +2875,78 @@ RemoveImageRecord (
   IN EFI_RUNTIME_IMAGE_ENTRY  *RuntimeImage\r
   );\r
 \r
+/**\r
+  Protect UEFI image.\r
+\r
+  @param[in]  LoadedImage              The loaded image protocol\r
+  @param[in]  LoadedImageDevicePath    The loaded image device path protocol\r
+**/\r
+VOID\r
+ProtectUefiImage (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath\r
+  );\r
+\r
+/**\r
+  Unprotect UEFI image.\r
+\r
+  @param[in]  LoadedImage              The loaded image protocol\r
+  @param[in]  LoadedImageDevicePath    The loaded image device path protocol\r
+**/\r
+VOID\r
+UnprotectUefiImage (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath\r
+  );\r
+\r
+/**\r
+  ExitBootServices Callback function for memory protection.\r
+**/\r
+VOID\r
+MemoryProtectionExitBootServicesCallback (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Manage memory permission attributes on a memory range, according to the\r
+  configured DXE memory protection policy.\r
+\r
+  @param  OldType           The old memory type of the range\r
+  @param  NewType           The new memory type of the range\r
+  @param  Memory            The base address of the range\r
+  @param  Length            The size of the range (in bytes)\r
+\r
+  @return EFI_SUCCESS       If the the CPU arch protocol is not installed yet\r
+  @return EFI_SUCCESS       If no DXE memory protection policy has been configured\r
+  @return EFI_SUCCESS       If OldType and NewType use the same permission attributes\r
+  @return other             Return value of gCpu->SetMemoryAttributes()\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ApplyMemoryProtectionPolicy (\r
+  IN  EFI_MEMORY_TYPE       OldType,\r
+  IN  EFI_MEMORY_TYPE       NewType,\r
+  IN  EFI_PHYSICAL_ADDRESS  Memory,\r
+  IN  UINT64                Length\r
+  );\r
+\r
+/**\r
+  Merge continous memory map entries whose have same attributes.\r
+\r
+  @param  MemoryMap       A pointer to the buffer in which firmware places\r
+                          the current memory map.\r
+  @param  MemoryMapSize   A pointer to the size, in bytes, of the\r
+                          MemoryMap buffer. On input, this is the size of\r
+                          the current memory map.  On output,\r
+                          it is the size of new memory map after merge.\r
+  @param  DescriptorSize  Size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.\r
+**/\r
+VOID\r
+MergeMemoryMap (\r
+  IN OUT EFI_MEMORY_DESCRIPTOR  *MemoryMap,\r
+  IN OUT UINTN                  *MemoryMapSize,\r
+  IN UINTN                      DescriptorSize\r
+  );\r
+\r
 #endif\r