+ IN UINTN StreamHandleToClose,\r
+ IN BOOLEAN FreeStreamBuffer\r
+ );\r
+\r
+/**\r
+ Creates and initializes the DebugImageInfo Table. Also creates the configuration\r
+ table and registers it into the system table.\r
+\r
+ Note:\r
+ This function allocates memory, frees it, and then allocates memory at an\r
+ address within the initial allocation. Since this function is called early\r
+ in DXE core initialization (before drivers are dispatched), this should not\r
+ be a problem.\r
+\r
+**/\r
+VOID\r
+CoreInitializeDebugImageInfoTable (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Update the CRC32 in the Debug Table.\r
+ Since the CRC32 service is made available by the Runtime driver, we have to\r
+ wait for the Runtime Driver to be installed before the CRC32 can be computed.\r
+ This function is called elsewhere by the core when the runtime architectural\r
+ protocol is produced.\r
+\r
+**/\r
+VOID\r
+CoreUpdateDebugTableCrc32 (\r
+ VOID\r
+ );\r
+\r
+\r
+/**\r
+ Adds a new DebugImageInfo structure to the DebugImageInfo Table. Re-Allocates\r
+ the table if it's not large enough to accomidate another entry.\r
+\r
+ @param ImageInfoType type of debug image information\r
+ @param LoadedImage pointer to the loaded image protocol for the image being\r
+ loaded\r
+ @param ImageHandle image handle for the image being loaded\r
+\r
+**/\r
+VOID\r
+CoreNewDebugImageInfoEntry (\r
+ IN UINT32 ImageInfoType,\r
+ IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage,\r
+ IN EFI_HANDLE ImageHandle\r
+ );\r
+\r
+\r
+/**\r
+ Removes and frees an entry from the DebugImageInfo Table.\r
+\r
+ @param ImageHandle image handle for the image being unloaded\r
+\r
+**/\r
+VOID\r
+CoreRemoveDebugImageInfoEntry (\r
+ EFI_HANDLE ImageHandle\r
+ );\r
+\r
+\r
+/**\r
+ This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.\r
+\r
+ @param ImageHandle The image handle.\r
+ @param SystemTable The system table.\r
+\r
+ @retval EFI_SUCCESS Successfully initialized firmware volume block\r
+ driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FwVolBlockDriverInit (\r
+ IN EFI_HANDLE ImageHandle,\r
+ 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
+ buffer.\r
+\r
+ @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 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
+ @retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.\r
+ @retval EFI_SUCCESS Successfully produced a FVB protocol on given\r
+ buffer.\r
+\r
+**/\r
+EFI_STATUS\r
+ProduceFVBProtocolOnBuffer (\r
+ 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
+\r
+/**\r
+ Raising to the task priority level of the mutual exclusion\r
+ lock, and then acquires ownership of the lock.\r
+\r
+ @param Lock The lock to acquire\r
+\r
+ @return Lock owned\r
+\r
+**/\r
+VOID\r
+CoreAcquireLock (\r
+ IN EFI_LOCK *Lock\r
+ );\r
+\r
+\r
+/**\r
+ Initialize a basic mutual exclusion lock. Each lock\r
+ provides mutual exclusion access at it's task priority\r
+ level. Since there is no-premption (at any TPL) or\r
+ multiprocessor support, acquiring the lock only consists\r
+ of raising to the locks TPL.\r
+\r
+ @param Lock The EFI_LOCK structure to initialize\r
+\r
+ @retval EFI_SUCCESS Lock Owned.\r
+ @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned.\r
+\r
+**/\r
+EFI_STATUS\r
+CoreAcquireLockOrFail (\r
+ IN EFI_LOCK *Lock\r
+ );\r
+\r
+\r
+/**\r
+ Releases ownership of the mutual exclusion lock, and\r
+ restores the previous task priority level.\r
+\r
+ @param Lock The lock to release\r
+\r
+ @return Lock unowned\r
+\r
+**/\r
+VOID\r
+CoreReleaseLock (\r
+ IN EFI_LOCK *Lock\r
+ );\r
+\r
+/**\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
+ @param StartLba Pointer to StartLba.\r
+ On input, the start logical block index from which to read.\r
+ On output,the end logical block index after reading.\r
+ @param Offset Pointer to Offset\r
+ On input, offset into the block at which to begin reading.\r
+ On output, offset into the end block after reading.\r
+ @param DataSize Size of data to be read.\r
+ @param Data Pointer to Buffer that the data will be read into.\r
+\r
+ @retval EFI_SUCCESS Successfully read data from firmware block.\r
+ @retval others\r
+**/\r
+EFI_STATUS\r
+ReadFvbData (\r
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r
+ IN OUT EFI_LBA *StartLba,\r
+ IN OUT UINTN *Offset,\r
+ IN UINTN DataSize,\r
+ OUT UINT8 *Data\r
+ );\r
+\r
+/**\r
+ Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and\r
+ copy the real length volume header into it.\r
+\r
+ @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to\r
+ read the volume header\r
+ @param FwVolHeader Pointer to pointer to allocated buffer in which\r
+ the volume header is returned.\r
+\r
+ @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
+GetFwVolHeader (\r
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r
+ OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r
+ );\r
+\r
+/**\r
+ Verify checksum of the firmware volume header.\r
+\r
+ @param FvHeader Points to the firmware volume header to be checked\r
+\r
+ @retval TRUE Checksum verification passed\r
+ @retval FALSE Checksum verification failed\r
+\r
+**/\r
+BOOLEAN\r
+VerifyFvHeaderChecksum (\r
+ 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