]> 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 48a57df65016e2c87280100bfe509d9602eccaa1..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 - 2012, 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
@@ -41,6 +35,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/Decompress.h>\r
 #include <Protocol/LoadPe32Image.h>\r
 #include <Protocol/Security.h>\r
+#include <Protocol/Security2.h>\r
 #include <Protocol/Ebc.h>\r
 #include <Protocol/Reset.h>\r
 #include <Protocol/Cpu.h>\r
@@ -52,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
@@ -63,8 +59,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/MemoryAllocationHob.h>\r
 #include <Guid/EventLegacyBios.h>\r
 #include <Guid/EventGroup.h>\r
+#include <Guid/EventExitBootServiceFailed.h>\r
 #include <Guid/LoadModuleAtFixedAddress.h>\r
 #include <Guid/IdleLoopEvent.h>\r
+#include <Guid/VectorHandoffTable.h>\r
+#include <Ppi/VectorHandoffInfo.h>\r
+#include <Guid/MemoryProfile.h>\r
 \r
 #include <Library/DxeCoreEntryPoint.h>\r
 #include <Library/DebugLib.h>\r
@@ -84,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
@@ -104,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
@@ -187,6 +186,78 @@ typedef struct {
   EFI_HANDLE            DeviceHandle;\r
 } EFI_GCD_MAP_ENTRY;\r
 \r
+\r
+#define LOADED_IMAGE_PRIVATE_DATA_SIGNATURE   SIGNATURE_32('l','d','r','i')\r
+\r
+typedef struct {\r
+  UINTN                       Signature;\r
+  /// Image handle\r
+  EFI_HANDLE                  Handle;\r
+  /// Image type\r
+  UINTN                       Type;\r
+  /// If entrypoint has been called\r
+  BOOLEAN                     Started;\r
+  /// The image's entry point\r
+  EFI_IMAGE_ENTRY_POINT       EntryPoint;\r
+  /// loaded image protocol\r
+  EFI_LOADED_IMAGE_PROTOCOL   Info;\r
+  /// Location in memory\r
+  EFI_PHYSICAL_ADDRESS        ImageBasePage;\r
+  /// Number of pages\r
+  UINTN                       NumberOfPages;\r
+  /// Original fixup data\r
+  CHAR8                       *FixupData;\r
+  /// Tpl of started image\r
+  EFI_TPL                     Tpl;\r
+  /// Status returned by started image\r
+  EFI_STATUS                  Status;\r
+  /// Size of ExitData from started image\r
+  UINTN                       ExitDataSize;\r
+  /// Pointer to exit data from started image\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
+  /// EBC Protocol pointer\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 Protocol\r
+  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;\r
+  /// PeCoffLoader ImageContext\r
+  PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  /// Status returned by LoadImage() service.\r
+  EFI_STATUS                  LoadImageStatus;\r
+} LOADED_IMAGE_PRIVATE_DATA;\r
+\r
+#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
@@ -195,6 +266,8 @@ extern EFI_RUNTIME_SERVICES                     *gDxeCoreRT;
 extern EFI_DXE_SERVICES                         *gDxeCoreDS;\r
 extern EFI_HANDLE                               gDxeCoreImageHandle;\r
 \r
+extern BOOLEAN                                  gMemoryMapTerminated;\r
+\r
 extern EFI_DECOMPRESS_PROTOCOL                  gEfiDecompress;\r
 \r
 extern EFI_RUNTIME_ARCH_PROTOCOL                *gRuntime;\r
@@ -203,6 +276,7 @@ extern EFI_WATCHDOG_TIMER_ARCH_PROTOCOL         *gWatchdogTimer;
 extern EFI_METRONOME_ARCH_PROTOCOL              *gMetronome;\r
 extern EFI_TIMER_ARCH_PROTOCOL                  *gTimer;\r
 extern EFI_SECURITY_ARCH_PROTOCOL               *gSecurity;\r
+extern EFI_SECURITY2_ARCH_PROTOCOL              *gSecurity2;\r
 extern EFI_BDS_ARCH_PROTOCOL                    *gBds;\r
 extern EFI_SMM_BASE2_PROTOCOL                   *gSmmBase2;\r
 \r
@@ -362,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
@@ -390,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
@@ -670,8 +744,12 @@ CoreInstallProtocolInterfaceNotify (
                                  arguments to InstallProtocolInterface(). All the\r
                                  protocols are added to Handle.\r
 \r
+  @retval EFI_SUCCESS            All the protocol interface was installed.\r
+  @retval EFI_OUT_OF_RESOURCES   There was not enough memory in pool to install all the protocols.\r
+  @retval EFI_ALREADY_STARTED    A Device Path Protocol instance was passed in that is already present in\r
+                                 the handle database.\r
   @retval EFI_INVALID_PARAMETER  Handle is NULL.\r
-  @retval EFI_SUCCESS            Protocol interfaces successfully installed.\r
+  @retval EFI_INVALID_PARAMETER  Protocol is already installed on the handle specified by Handle.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1010,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
@@ -1080,19 +1158,27 @@ CoreConnectHandlesByKey (
 /**\r
   Connects one or more drivers to a controller.\r
 \r
-  @param  ControllerHandle                      Handle of the controller to be\r
-                                                connected.\r
-  @param  DriverImageHandle                     DriverImageHandle A pointer to an\r
-                                                ordered list of driver image\r
-                                                handles.\r
-  @param  RemainingDevicePath                   RemainingDevicePath A pointer to\r
-                                                the device path that specifies a\r
-                                                child of the controller specified\r
-                                                by ControllerHandle.\r
-  @param  Recursive                             Whether the function would be\r
-                                                called recursively or not.\r
+  @param  ControllerHandle      The handle of the controller to which driver(s) are to be connected.\r
+  @param  DriverImageHandle     A pointer to an ordered list handles that support the\r
+                                EFI_DRIVER_BINDING_PROTOCOL.\r
+  @param  RemainingDevicePath   A pointer to the device path that specifies a child of the\r
+                                controller specified by ControllerHandle.\r
+  @param  Recursive             If TRUE, then ConnectController() is called recursively\r
+                                until the entire tree of controllers below the controller specified\r
+                                by ControllerHandle have been created. If FALSE, then\r
+                                the tree of controllers is only expanded one level.\r
 \r
-  @return Status code.\r
+  @retval EFI_SUCCESS           1) One or more drivers were connected to ControllerHandle.\r
+                                2) No drivers were connected to ControllerHandle, but\r
+                                RemainingDevicePath is not NULL, and it is an End Device\r
+                                Path Node.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+  @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
+                                associated with the ControllerHandle or specified by the RemainingDevicePath.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1175,8 +1261,6 @@ CoreAllocatePages (
   IN OUT EFI_PHYSICAL_ADDRESS  *Memory\r
   );\r
 \r
-\r
-\r
 /**\r
   Frees previous allocated pages.\r
 \r
@@ -1195,8 +1279,6 @@ CoreFreePages (
   IN UINTN                  NumberOfPages\r
   );\r
 \r
-\r
-\r
 /**\r
   This function returns a copy of the current memory map. The map is an array of\r
   memory descriptors, each of which describes a contiguous block of memory.\r
@@ -1247,7 +1329,7 @@ CoreGetMemoryMap (
   @param  Buffer                 The address to return a pointer to the allocated\r
                                  pool\r
 \r
-  @retval EFI_INVALID_PARAMETER  PoolType not valid\r
+  @retval EFI_INVALID_PARAMETER  PoolType not valid or Buffer is NULL\r
   @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.\r
   @retval EFI_SUCCESS            Pool successfully allocated.\r
 \r
@@ -1260,7 +1342,26 @@ CoreAllocatePool (
   OUT VOID            **Buffer\r
   );\r
 \r
+/**\r
+  Allocate pool of a particular type.\r
+\r
+  @param  PoolType               Type of pool to allocate\r
+  @param  Size                   The amount of pool to allocate\r
+  @param  Buffer                 The address to return a pointer to the allocated\r
+                                 pool\r
 \r
+  @retval EFI_INVALID_PARAMETER  PoolType not valid or Buffer is NULL\r
+  @retval EFI_OUT_OF_RESOURCES   Size exceeds max pool size or allocation failed.\r
+  @retval EFI_SUCCESS            Pool successfully allocated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreInternalAllocatePool (\r
+  IN EFI_MEMORY_TYPE  PoolType,\r
+  IN UINTN            Size,\r
+  OUT VOID            **Buffer\r
+  );\r
 \r
 /**\r
   Frees pool.\r
@@ -1277,7 +1378,22 @@ CoreFreePool (
   IN VOID        *Buffer\r
   );\r
 \r
+/**\r
+  Frees pool.\r
 \r
+  @param  Buffer                 The allocated pool entry to free\r
+  @param  PoolType               Pointer to pool type\r
+\r
+  @retval EFI_INVALID_PARAMETER  Buffer is not a valid value.\r
+  @retval EFI_SUCCESS            Pool successfully freed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreInternalFreePool (\r
+  IN VOID               *Buffer,\r
+  OUT EFI_MEMORY_TYPE   *PoolType OPTIONAL\r
+  );\r
 \r
 /**\r
   Loads an EFI image into memory and returns a handle to the image.\r
@@ -1306,10 +1422,10 @@ CoreFreePool (
   @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
@@ -1333,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
@@ -1360,6 +1476,7 @@ CoreUnloadImage (
 \r
   @retval EFI_INVALID_PARAMETER   Invalid parameter\r
   @retval EFI_OUT_OF_RESOURCES    No enough buffer to allocate\r
+  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the image should not be started.\r
   @retval EFI_SUCCESS             Successfully transfer control to the image's\r
                                   entry point.\r
 \r
@@ -1409,7 +1526,7 @@ CoreExit (
 \r
 \r
 /**\r
-  Creates a general-purpose event structure.\r
+  Creates an event.\r
 \r
   @param  Type                   The type of event to create and its mode and\r
                                  attributes\r
@@ -1439,7 +1556,7 @@ CoreCreateEvent (
 \r
 \r
 /**\r
-  Creates a general-purpose event structure\r
+  Creates an event in a group.\r
 \r
   @param  Type                   The type of event to create and its mode and\r
                                  attributes\r
@@ -1469,7 +1586,36 @@ CoreCreateEventEx (
   OUT EFI_EVENT               *Event\r
   );\r
 \r
+/**\r
+  Creates a general-purpose event structure\r
 \r
+  @param  Type                   The type of event to create and its mode and\r
+                                 attributes\r
+  @param  NotifyTpl              The task priority level of event notifications\r
+  @param  NotifyFunction         Pointer to the events notification function\r
+  @param  NotifyContext          Pointer to the notification functions context;\r
+                                 corresponds to parameter "Context" in the\r
+                                 notification function\r
+  @param  EventGroup             GUID for EventGroup if NULL act the same as\r
+                                 gBS->CreateEvent().\r
+  @param  Event                  Pointer to the newly created event if the call\r
+                                 succeeds; undefined otherwise\r
+\r
+  @retval EFI_SUCCESS            The event structure was created\r
+  @retval EFI_INVALID_PARAMETER  One of the parameters has an invalid value\r
+  @retval EFI_OUT_OF_RESOURCES   The event could not be allocated\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreCreateEventInternal (\r
+  IN UINT32                   Type,\r
+  IN EFI_TPL                  NotifyTpl,\r
+  IN EFI_EVENT_NOTIFY         NotifyFunction, OPTIONAL\r
+  IN CONST VOID               *NotifyContext, OPTIONAL\r
+  IN CONST EFI_GUID           *EventGroup,    OPTIONAL\r
+  OUT EFI_EVENT               *Event\r
+  );\r
 \r
 /**\r
   Sets the type of timer and the trigger time for a timer event.\r
@@ -1686,12 +1832,12 @@ 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
                                 range specified by BaseAddress and Length.\r
-  @retval EFI_ACCESS_DEFINED    The attributes for the memory resource range specified by\r
+  @retval EFI_ACCESS_DENIED     The attributes for the memory resource range specified by\r
                                 BaseAddress and Length cannot be modified.\r
   @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the attributes of\r
                                 the memory resource range.\r
@@ -1708,6 +1854,32 @@ CoreSetMemorySpaceAttributes (
   );\r
 \r
 \r
+/**\r
+  Modifies the capabilities for a memory region in the global coherency domain of the\r
+  processor.\r
+\r
+  @param  BaseAddress      The physical address that is the start address of a memory region.\r
+  @param  Length           The size in bytes of the memory region.\r
+  @param  Capabilities     The bit mask of capabilities that the memory region supports.\r
+\r
+  @retval EFI_SUCCESS           The capabilities were set for the memory region.\r
+  @retval EFI_INVALID_PARAMETER Length is zero.\r
+  @retval EFI_UNSUPPORTED       The capabilities specified by Capabilities do not include the\r
+                                memory region attributes currently in use.\r
+  @retval EFI_ACCESS_DENIED     The capabilities for the memory resource range specified by\r
+                                BaseAddress and Length cannot be modified.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the capabilities\r
+                                of the memory resource range.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreSetMemorySpaceCapabilities (\r
+  IN EFI_PHYSICAL_ADDRESS  BaseAddress,\r
+  IN UINT64                Length,\r
+  IN UINT64                Capabilities\r
+  );\r
+\r
+\r
 /**\r
   Returns a map of the memory resources in the global coherency domain of the\r
   processor.\r
@@ -2002,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
@@ -2248,7 +2407,7 @@ OpenSectionStream (
                                 non-null on input, then the buffer is caller\r
                                 allocated.  If Buffer is NULL, then the buffer\r
                                 is callee allocated.  In either case, the\r
-                                requried buffer size is returned in *BufferSize.\r
+                                required buffer size is returned in *BufferSize.\r
   @param  BufferSize            On input, indicates the size of *Buffer if\r
                                 *Buffer is non-null on input.  On output,\r
                                 indicates the required size (allocated size if\r
@@ -2309,6 +2468,8 @@ GetSection (
   SEP member function.  Deletes an existing section stream\r
 \r
   @param  StreamHandleToClose    Indicates the stream to close\r
+  @param  FreeStreamBuffer       TRUE - Need to free stream buffer;\r
+                                 FALSE - No need to free stream buffer.\r
 \r
   @retval EFI_SUCCESS            The section stream is closed sucessfully.\r
   @retval EFI_OUT_OF_RESOURCES   Memory allocation failed.\r
@@ -2319,7 +2480,8 @@ GetSection (
 EFI_STATUS\r
 EFIAPI\r
 CloseSectionStream (\r
-  IN  UINTN                                     StreamHandleToClose\r
+  IN  UINTN                                     StreamHandleToClose,\r
+  IN  BOOLEAN                                   FreeStreamBuffer\r
   );\r
 \r
 /**\r
@@ -2400,6 +2562,19 @@ FwVolBlockDriverInit (
   IN EFI_SYSTEM_TABLE           *SystemTable\r
   );\r
 \r
+/**\r
+\r
+  Get FVB authentication status\r
+\r
+  @param FvbProtocol    FVB protocol.\r
+\r
+  @return Authentication status.\r
+\r
+**/\r
+UINT32\r
+GetFvbAuthenticationStatus (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL     *FvbProtocol\r
+  );\r
 \r
 /**\r
   This routine produces a firmware volume block protocol on a given\r
@@ -2408,8 +2583,10 @@ FwVolBlockDriverInit (
   @param  BaseAddress            base address of the firmware volume image\r
   @param  Length                 length of the firmware volume image\r
   @param  ParentHandle           handle of parent firmware volume, if this image\r
-                                 came from an FV image file in another firmware\r
+                                 came from an FV image file and section in another firmware\r
                                  volume (ala capsules)\r
+  @param  AuthenticationStatus   Authentication status inherited, if this image\r
+                                 came from an FV image file and section in another firmware volume.\r
   @param  FvProtocol             Firmware volume block protocol produced.\r
 \r
   @retval EFI_VOLUME_CORRUPTED   Volume corrupted.\r
@@ -2423,6 +2600,7 @@ ProduceFVBProtocolOnBuffer (
   IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
   IN UINT64                 Length,\r
   IN EFI_HANDLE             ParentHandle,\r
+  IN UINT32                 AuthenticationStatus,\r
   OUT EFI_HANDLE            *FvProtocol  OPTIONAL\r
   );\r
 \r
@@ -2475,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
@@ -2529,6 +2691,8 @@ ReadFvbData (
   @retval EFI_OUT_OF_RESOURCES  No enough buffer could be allocated.\r
   @retval EFI_SUCCESS           Successfully read volume header to the allocated\r
                                 buffer.\r
+  @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or\r
+                                the file system could not be understood.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -2551,4 +2715,238 @@ VerifyFvHeaderChecksum (
   IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r
   );\r
 \r
+/**\r
+  Initialize memory profile.\r
+\r
+  @param HobStart   The start address of the HOB.\r
+\r
+**/\r
+VOID\r
+MemoryProfileInit (\r
+  IN VOID   *HobStart\r
+  );\r
+\r
+/**\r
+  Install memory profile protocol.\r
+\r
+**/\r
+VOID\r
+MemoryProfileInstallProtocol (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Register image to memory profile.\r
+\r
+  @param DriverEntry    Image info.\r
+  @param FileType       Image file type.\r
+\r
+  @return EFI_SUCCESS           Register successfully.\r
+  @return EFI_UNSUPPORTED       Memory profile unsupported,\r
+                                or memory profile for the image is not required.\r
+  @return EFI_OUT_OF_RESOURCES  No enough resource for this register.\r
+\r
+**/\r
+EFI_STATUS\r
+RegisterMemoryProfileImage (\r
+  IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry,\r
+  IN EFI_FV_FILETYPE            FileType\r
+  );\r
+\r
+/**\r
+  Unregister image from memory profile.\r
+\r
+  @param DriverEntry    Image info.\r
+\r
+  @return EFI_SUCCESS           Unregister successfully.\r
+  @return EFI_UNSUPPORTED       Memory profile unsupported,\r
+                                or memory profile for the image is not required.\r
+  @return EFI_NOT_FOUND         The image is not found.\r
+\r
+**/\r
+EFI_STATUS\r
+UnregisterMemoryProfileImage (\r
+  IN LOADED_IMAGE_PRIVATE_DATA  *DriverEntry\r
+  );\r
+\r
+/**\r
+  Update memory profile information.\r
+\r
+  @param CallerAddress  Address of caller who call Allocate or Free.\r
+  @param Action         This Allocate or Free action.\r
+  @param MemoryType     Memory type.\r
+                        EfiMaxMemoryType means the MemoryType is unknown.\r
+  @param Size           Buffer size.\r
+  @param Buffer         Buffer address.\r
+  @param ActionString   String for memory profile action.\r
+                        Only needed for user defined allocate action.\r
+\r
+  @return EFI_SUCCESS           Memory profile is updated.\r
+  @return EFI_UNSUPPORTED       Memory profile is unsupported,\r
+                                or memory profile for the image is not required,\r
+                                or memory profile for the memory type is not required.\r
+  @return EFI_ACCESS_DENIED     It is during memory profile data getting.\r
+  @return EFI_ABORTED           Memory profile recording is not enabled.\r
+  @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile for allocate action.\r
+  @return EFI_NOT_FOUND         No matched allocate info found for free action.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CoreUpdateProfile (\r
+  IN EFI_PHYSICAL_ADDRESS   CallerAddress,\r
+  IN MEMORY_PROFILE_ACTION  Action,\r
+  IN EFI_MEMORY_TYPE        MemoryType,\r
+  IN UINTN                  Size,       // Valid for AllocatePages/FreePages/AllocatePool\r
+  IN VOID                   *Buffer,\r
+  IN CHAR8                  *ActionString OPTIONAL\r
+  );\r
+\r
+/**\r
+  Internal function.  Converts a memory range to use new attributes.\r
+\r
+  @param  Start                  The first address of the range Must be page\r
+                                 aligned\r
+  @param  NumberOfPages          The number of pages to convert\r
+  @param  NewAttributes          The new attributes value for the range.\r
+\r
+**/\r
+VOID\r
+CoreUpdateMemoryAttributes (\r
+  IN EFI_PHYSICAL_ADDRESS  Start,\r
+  IN UINT64                NumberOfPages,\r
+  IN UINT64                NewAttributes\r
+  );\r
+\r
+/**\r
+  Initialize PropertiesTable support.\r
+**/\r
+VOID\r
+EFIAPI\r
+CoreInitializePropertiesTable (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initialize MemoryAttrubutesTable support.\r
+**/\r
+VOID\r
+EFIAPI\r
+CoreInitializeMemoryAttributesTable (\r
+  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
+  @param[in] MemoryType EFI memory type.\r
+**/\r
+VOID\r
+InstallMemoryAttributesTableOnMemoryAllocation (\r
+  IN EFI_MEMORY_TYPE    MemoryType\r
+  );\r
+\r
+/**\r
+  Insert image record.\r
+\r
+  @param  RuntimeImage    Runtime image information\r
+**/\r
+VOID\r
+InsertImageRecord (\r
+  IN EFI_RUNTIME_IMAGE_ENTRY  *RuntimeImage\r
+  );\r
+\r
+/**\r
+  Remove Image record.\r
+\r
+  @param  RuntimeImage    Runtime image information\r
+**/\r
+VOID\r
+RemoveImageRecord (\r
+  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