2 Support routines for UEFI memory profile.
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
21 MEMORY_PROFILE_CONTEXT Context
;
22 LIST_ENTRY
*DriverInfoList
;
23 } MEMORY_PROFILE_CONTEXT_DATA
;
27 MEMORY_PROFILE_DRIVER_INFO DriverInfo
;
28 LIST_ENTRY
*AllocInfoList
;
30 } MEMORY_PROFILE_DRIVER_INFO_DATA
;
34 MEMORY_PROFILE_ALLOC_INFO AllocInfo
;
36 } MEMORY_PROFILE_ALLOC_INFO_DATA
;
39 GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue
);
40 GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext
= {
41 MEMORY_PROFILE_CONTEXT_SIGNATURE
,
44 MEMORY_PROFILE_CONTEXT_SIGNATURE
,
45 sizeof (MEMORY_PROFILE_CONTEXT
),
46 MEMORY_PROFILE_CONTEXT_REVISION
58 GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA
*mMemoryProfileContextPtr
= NULL
;
60 BOOLEAN mMemoryProfileRecordingStatus
= FALSE
;
63 Get memory profile data.
65 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
66 @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.
67 On return, points to the size of the data returned in ProfileBuffer.
68 @param[out] ProfileBuffer Profile buffer.
70 @return EFI_SUCCESS Get the memory profile data successfully.
71 @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.
72 ProfileSize is updated with the size required.
77 ProfileProtocolGetData (
78 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
79 IN OUT UINT64
*ProfileSize
,
80 OUT VOID
*ProfileBuffer
84 Register image to memory profile.
86 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
87 @param[in] FilePath File path of the image.
88 @param[in] ImageBase Image base address.
89 @param[in] ImageSize Image size.
90 @param[in] FileType File type of the image.
92 @return EFI_SUCCESS Register success.
93 @return EFI_OUT_OF_RESOURCE No enough resource for this register.
98 ProfileProtocolRegisterImage (
99 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
100 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
101 IN PHYSICAL_ADDRESS ImageBase
,
103 IN EFI_FV_FILETYPE FileType
107 Unregister image from memory profile.
109 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
110 @param[in] FilePath File path of the image.
111 @param[in] ImageBase Image base address.
112 @param[in] ImageSize Image size.
114 @return EFI_SUCCESS Unregister success.
115 @return EFI_NOT_FOUND The image is not found.
120 ProfileProtocolUnregisterImage (
121 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
122 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
123 IN PHYSICAL_ADDRESS ImageBase
,
127 EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol
= {
128 ProfileProtocolGetData
,
129 ProfileProtocolRegisterImage
,
130 ProfileProtocolUnregisterImage
134 Return memory profile context.
136 @return Memory profile context.
139 MEMORY_PROFILE_CONTEXT_DATA
*
140 GetMemoryProfileContext (
144 return mMemoryProfileContextPtr
;
148 Retrieves the magic value from the PE/COFF header.
150 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
152 @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
153 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
157 InternalPeCoffGetPeHeaderMagicValue (
158 IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
162 // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
163 // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the
164 // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
165 // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
167 if (Hdr
.Pe32
->FileHeader
.Machine
== IMAGE_FILE_MACHINE_IA64
&& Hdr
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
168 return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
;
171 // Return the magic value from the PC/COFF Optional Header
173 return Hdr
.Pe32
->OptionalHeader
.Magic
;
177 Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory.
178 If Pe32Data is NULL, then ASSERT().
180 @param Pe32Data The pointer to the PE/COFF image that is loaded in system memory.
182 @return The Subsystem of the PE/COFF image.
186 InternalPeCoffGetSubsystem (
190 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
191 EFI_IMAGE_DOS_HEADER
*DosHdr
;
194 ASSERT (Pe32Data
!= NULL
);
196 DosHdr
= (EFI_IMAGE_DOS_HEADER
*) Pe32Data
;
197 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
199 // DOS image header is present, so read the PE header after the DOS image header.
201 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*) ((UINTN
) Pe32Data
+ (UINTN
) ((DosHdr
->e_lfanew
) & 0x0ffff));
204 // DOS image header is not present, so PE header is at the image base.
206 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*) Pe32Data
;
209 if (Hdr
.Te
->Signature
== EFI_TE_IMAGE_HEADER_SIGNATURE
) {
210 return Hdr
.Te
->Subsystem
;
211 } else if (Hdr
.Pe32
->Signature
== EFI_IMAGE_NT_SIGNATURE
) {
212 Magic
= InternalPeCoffGetPeHeaderMagicValue (Hdr
);
213 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
214 return Hdr
.Pe32
->OptionalHeader
.Subsystem
;
215 } else if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
) {
216 return Hdr
.Pe32Plus
->OptionalHeader
.Subsystem
;
224 Retrieves and returns a pointer to the entry point to a PE/COFF image that has been loaded
225 into system memory with the PE/COFF Loader Library functions.
227 Retrieves the entry point to the PE/COFF image specified by Pe32Data and returns this entry
228 point in EntryPoint. If the entry point could not be retrieved from the PE/COFF image, then
229 return RETURN_INVALID_PARAMETER. Otherwise return RETURN_SUCCESS.
230 If Pe32Data is NULL, then ASSERT().
231 If EntryPoint is NULL, then ASSERT().
233 @param Pe32Data The pointer to the PE/COFF image that is loaded in system memory.
234 @param EntryPoint The pointer to entry point to the PE/COFF image to return.
236 @retval RETURN_SUCCESS EntryPoint was returned.
237 @retval RETURN_INVALID_PARAMETER The entry point could not be found in the PE/COFF image.
241 InternalPeCoffGetEntryPoint (
243 OUT VOID
**EntryPoint
246 EFI_IMAGE_DOS_HEADER
*DosHdr
;
247 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
;
249 ASSERT (Pe32Data
!= NULL
);
250 ASSERT (EntryPoint
!= NULL
);
252 DosHdr
= (EFI_IMAGE_DOS_HEADER
*) Pe32Data
;
253 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
255 // DOS image header is present, so read the PE header after the DOS image header.
257 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*) ((UINTN
) Pe32Data
+ (UINTN
) ((DosHdr
->e_lfanew
) & 0x0ffff));
260 // DOS image header is not present, so PE header is at the image base.
262 Hdr
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*) Pe32Data
;
266 // Calculate the entry point relative to the start of the image.
267 // AddressOfEntryPoint is common for PE32 & PE32+
269 if (Hdr
.Te
->Signature
== EFI_TE_IMAGE_HEADER_SIGNATURE
) {
270 *EntryPoint
= (VOID
*) ((UINTN
) Pe32Data
+ (UINTN
) (Hdr
.Te
->AddressOfEntryPoint
& 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER
) - Hdr
.Te
->StrippedSize
);
271 return RETURN_SUCCESS
;
272 } else if (Hdr
.Pe32
->Signature
== EFI_IMAGE_NT_SIGNATURE
) {
273 *EntryPoint
= (VOID
*) ((UINTN
) Pe32Data
+ (UINTN
) (Hdr
.Pe32
->OptionalHeader
.AddressOfEntryPoint
& 0x0ffffffff));
274 return RETURN_SUCCESS
;
277 return RETURN_UNSUPPORTED
;
283 @param ContextData Memory profile context.
284 @param FileName File name of the image.
285 @param ImageBase Image base address.
286 @param ImageSize Image size.
287 @param EntryPoint Entry point of the image.
288 @param ImageSubsystem Image subsystem of the image.
289 @param FileType File type of the image.
291 @return Pointer to memory profile driver info.
294 MEMORY_PROFILE_DRIVER_INFO_DATA
*
296 IN MEMORY_PROFILE_CONTEXT_DATA
*ContextData
,
297 IN EFI_GUID
*FileName
,
298 IN PHYSICAL_ADDRESS ImageBase
,
300 IN PHYSICAL_ADDRESS EntryPoint
,
301 IN UINT16 ImageSubsystem
,
302 IN EFI_FV_FILETYPE FileType
306 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
307 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
308 VOID
*EntryPointInImage
;
311 // Use CoreInternalAllocatePool() that will not update profile for this AllocatePool action.
313 Status
= CoreInternalAllocatePool (
315 sizeof (*DriverInfoData
) + sizeof (LIST_ENTRY
),
316 (VOID
**) &DriverInfoData
318 if (EFI_ERROR (Status
)) {
322 ZeroMem (DriverInfoData
, sizeof (*DriverInfoData
));
324 DriverInfo
= &DriverInfoData
->DriverInfo
;
325 DriverInfoData
->Signature
= MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
;
326 DriverInfo
->Header
.Signature
= MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
;
327 DriverInfo
->Header
.Length
= sizeof (MEMORY_PROFILE_DRIVER_INFO
);
328 DriverInfo
->Header
.Revision
= MEMORY_PROFILE_DRIVER_INFO_REVISION
;
329 if (FileName
!= NULL
) {
330 CopyMem (&DriverInfo
->FileName
, FileName
, sizeof (EFI_GUID
));
332 DriverInfo
->ImageBase
= ImageBase
;
333 DriverInfo
->ImageSize
= ImageSize
;
334 DriverInfo
->EntryPoint
= EntryPoint
;
335 DriverInfo
->ImageSubsystem
= ImageSubsystem
;
336 if ((EntryPoint
!= 0) && ((EntryPoint
< ImageBase
) || (EntryPoint
>= (ImageBase
+ ImageSize
)))) {
338 // If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
339 // So patch ImageBuffer here to align the EntryPoint.
341 Status
= InternalPeCoffGetEntryPoint ((VOID
*) (UINTN
) ImageBase
, &EntryPointInImage
);
342 ASSERT_EFI_ERROR (Status
);
343 DriverInfo
->ImageBase
= ImageBase
+ EntryPoint
- (PHYSICAL_ADDRESS
) (UINTN
) EntryPointInImage
;
345 DriverInfo
->FileType
= FileType
;
346 DriverInfoData
->AllocInfoList
= (LIST_ENTRY
*) (DriverInfoData
+ 1);
347 InitializeListHead (DriverInfoData
->AllocInfoList
);
348 DriverInfo
->CurrentUsage
= 0;
349 DriverInfo
->PeakUsage
= 0;
350 DriverInfo
->AllocRecordCount
= 0;
352 InsertTailList (ContextData
->DriverInfoList
, &DriverInfoData
->Link
);
353 ContextData
->Context
.ImageCount
++;
354 ContextData
->Context
.TotalImageSize
+= DriverInfo
->ImageSize
;
356 return DriverInfoData
;
360 Register DXE Core to memory profile.
362 @param HobStart The start address of the HOB.
363 @param ContextData Memory profile context.
365 @retval TRUE Register success.
366 @retval FALSE Register fail.
372 IN MEMORY_PROFILE_CONTEXT_DATA
*ContextData
375 EFI_PEI_HOB_POINTERS DxeCoreHob
;
376 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
377 PHYSICAL_ADDRESS ImageBase
;
379 ASSERT (ContextData
!= NULL
);
382 // Searching for image hob
384 DxeCoreHob
.Raw
= HobStart
;
385 while ((DxeCoreHob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, DxeCoreHob
.Raw
)) != NULL
) {
386 if (CompareGuid (&DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.Name
, &gEfiHobMemoryAllocModuleGuid
)) {
392 DxeCoreHob
.Raw
= GET_NEXT_HOB (DxeCoreHob
);
394 ASSERT (DxeCoreHob
.Raw
!= NULL
);
396 ImageBase
= DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryBaseAddress
;
397 DriverInfoData
= BuildDriverInfo (
399 &DxeCoreHob
.MemoryAllocationModule
->ModuleName
,
401 DxeCoreHob
.MemoryAllocationModule
->MemoryAllocationHeader
.MemoryLength
,
402 DxeCoreHob
.MemoryAllocationModule
->EntryPoint
,
403 InternalPeCoffGetSubsystem ((VOID
*) (UINTN
) ImageBase
),
404 EFI_FV_FILETYPE_DXE_CORE
406 if (DriverInfoData
== NULL
) {
414 Initialize memory profile.
416 @param HobStart The start address of the HOB.
424 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
426 if (!IS_UEFI_MEMORY_PROFILE_ENABLED
) {
430 ContextData
= GetMemoryProfileContext ();
431 if (ContextData
!= NULL
) {
435 mMemoryProfileRecordingStatus
= TRUE
;
436 mMemoryProfileContextPtr
= &mMemoryProfileContext
;
438 RegisterDxeCore (HobStart
, &mMemoryProfileContext
);
440 DEBUG ((EFI_D_INFO
, "MemoryProfileInit MemoryProfileContext - 0x%x\n", &mMemoryProfileContext
));
444 Install memory profile protocol.
448 MemoryProfileInstallProtocol (
455 if (!IS_UEFI_MEMORY_PROFILE_ENABLED
) {
460 Status
= CoreInstallMultipleProtocolInterfaces (
462 &gEdkiiMemoryProfileGuid
,
466 ASSERT_EFI_ERROR (Status
);
470 Get the GUID file name from the file path.
472 @param FilePath File path.
474 @return The GUID file name from the file path.
478 GetFileNameFromFilePath (
479 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
482 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*ThisFilePath
;
486 ThisFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) FilePath
;
487 while (!IsDevicePathEnd (ThisFilePath
)) {
488 FileName
= EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath
);
489 if (FileName
!= NULL
) {
492 ThisFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) NextDevicePathNode (ThisFilePath
);
499 Register image to memory profile.
501 @param DriverEntry Image info.
502 @param FileType Image file type.
504 @retval TRUE Register success.
505 @retval FALSE Register fail.
509 RegisterMemoryProfileImage (
510 IN LOADED_IMAGE_PRIVATE_DATA
*DriverEntry
,
511 IN EFI_FV_FILETYPE FileType
514 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
515 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
517 if (!IS_UEFI_MEMORY_PROFILE_ENABLED
) {
521 ContextData
= GetMemoryProfileContext ();
522 if (ContextData
== NULL
) {
526 DriverInfoData
= BuildDriverInfo (
528 GetFileNameFromFilePath (DriverEntry
->Info
.FilePath
),
529 DriverEntry
->ImageContext
.ImageAddress
,
530 DriverEntry
->ImageContext
.ImageSize
,
531 DriverEntry
->ImageContext
.EntryPoint
,
532 DriverEntry
->ImageContext
.ImageType
,
535 if (DriverInfoData
== NULL
) {
543 Search image from memory profile.
545 @param ContextData Memory profile context.
546 @param FileName Image file name.
547 @param Address Image Address.
549 @return Pointer to memory profile driver info.
552 MEMORY_PROFILE_DRIVER_INFO_DATA
*
553 GetMemoryProfileDriverInfoByFileNameAndAddress (
554 IN MEMORY_PROFILE_CONTEXT_DATA
*ContextData
,
555 IN EFI_GUID
*FileName
,
556 IN PHYSICAL_ADDRESS Address
559 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
560 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
561 LIST_ENTRY
*DriverLink
;
562 LIST_ENTRY
*DriverInfoList
;
564 DriverInfoList
= ContextData
->DriverInfoList
;
566 for (DriverLink
= DriverInfoList
->ForwardLink
;
567 DriverLink
!= DriverInfoList
;
568 DriverLink
= DriverLink
->ForwardLink
) {
569 DriverInfoData
= CR (
571 MEMORY_PROFILE_DRIVER_INFO_DATA
,
573 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
575 DriverInfo
= &DriverInfoData
->DriverInfo
;
576 if ((CompareGuid (&DriverInfo
->FileName
, FileName
)) &&
577 (Address
>= DriverInfo
->ImageBase
) &&
578 (Address
< (DriverInfo
->ImageBase
+ DriverInfo
->ImageSize
))) {
579 return DriverInfoData
;
587 Search dummy image from memory profile.
589 @param ContextData Memory profile context.
591 @return Pointer to memory profile driver info.
594 MEMORY_PROFILE_DRIVER_INFO_DATA
*
596 IN MEMORY_PROFILE_CONTEXT_DATA
*ContextData
599 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
600 LIST_ENTRY
*DriverLink
;
601 LIST_ENTRY
*DriverInfoList
;
603 DriverInfoList
= ContextData
->DriverInfoList
;
605 for (DriverLink
= DriverInfoList
->ForwardLink
;
606 DriverLink
!= DriverInfoList
;
607 DriverLink
= DriverLink
->ForwardLink
) {
608 DriverInfoData
= CR (
610 MEMORY_PROFILE_DRIVER_INFO_DATA
,
612 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
614 if (CompareGuid (&gZeroGuid
, &DriverInfoData
->DriverInfo
.FileName
)) {
615 return DriverInfoData
;
619 return BuildDriverInfo (ContextData
, &gZeroGuid
, 0, 0, 0, 0, 0);
623 Search image from memory profile.
624 It will return image, if (Address >= ImageBuffer) AND (Address < ImageBuffer + ImageSize)
626 @param ContextData Memory profile context.
627 @param Address Image or Function address.
629 @return Pointer to memory profile driver info.
632 MEMORY_PROFILE_DRIVER_INFO_DATA
*
633 GetMemoryProfileDriverInfoFromAddress (
634 IN MEMORY_PROFILE_CONTEXT_DATA
*ContextData
,
635 IN PHYSICAL_ADDRESS Address
638 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
639 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
640 LIST_ENTRY
*DriverLink
;
641 LIST_ENTRY
*DriverInfoList
;
643 DriverInfoList
= ContextData
->DriverInfoList
;
645 for (DriverLink
= DriverInfoList
->ForwardLink
;
646 DriverLink
!= DriverInfoList
;
647 DriverLink
= DriverLink
->ForwardLink
) {
648 DriverInfoData
= CR (
650 MEMORY_PROFILE_DRIVER_INFO_DATA
,
652 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
654 DriverInfo
= &DriverInfoData
->DriverInfo
;
655 if ((Address
>= DriverInfo
->ImageBase
) &&
656 (Address
< (DriverInfo
->ImageBase
+ DriverInfo
->ImageSize
))) {
657 return DriverInfoData
;
662 // Should never come here.
664 return FindDummyImage (ContextData
);
668 Unregister image from memory profile.
670 @param DriverEntry Image info.
672 @retval TRUE Unregister success.
673 @retval FALSE Unregister fail.
677 UnregisterMemoryProfileImage (
678 IN LOADED_IMAGE_PRIVATE_DATA
*DriverEntry
682 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
683 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
685 PHYSICAL_ADDRESS ImageAddress
;
686 VOID
*EntryPointInImage
;
688 if (!IS_UEFI_MEMORY_PROFILE_ENABLED
) {
692 ContextData
= GetMemoryProfileContext ();
693 if (ContextData
== NULL
) {
697 DriverInfoData
= NULL
;
698 FileName
= GetFileNameFromFilePath (DriverEntry
->Info
.FilePath
);
699 ImageAddress
= DriverEntry
->ImageContext
.ImageAddress
;
700 if ((DriverEntry
->ImageContext
.EntryPoint
< ImageAddress
) || (DriverEntry
->ImageContext
.EntryPoint
>= (ImageAddress
+ DriverEntry
->ImageContext
.ImageSize
))) {
702 // If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
703 // So patch ImageAddress here to align the EntryPoint.
705 Status
= InternalPeCoffGetEntryPoint ((VOID
*) (UINTN
) ImageAddress
, &EntryPointInImage
);
706 ASSERT_EFI_ERROR (Status
);
707 ImageAddress
= ImageAddress
+ (UINTN
) DriverEntry
->ImageContext
.EntryPoint
- (UINTN
) EntryPointInImage
;
709 if (FileName
!= NULL
) {
710 DriverInfoData
= GetMemoryProfileDriverInfoByFileNameAndAddress (ContextData
, FileName
, ImageAddress
);
712 if (DriverInfoData
== NULL
) {
713 DriverInfoData
= GetMemoryProfileDriverInfoFromAddress (ContextData
, ImageAddress
);
715 if (DriverInfoData
== NULL
) {
719 ContextData
->Context
.TotalImageSize
-= DriverInfoData
->DriverInfo
.ImageSize
;
721 DriverInfoData
->DriverInfo
.ImageBase
= 0;
722 DriverInfoData
->DriverInfo
.ImageSize
= 0;
724 if (DriverInfoData
->DriverInfo
.PeakUsage
== 0) {
725 ContextData
->Context
.ImageCount
--;
726 RemoveEntryList (&DriverInfoData
->Link
);
728 // Use CoreInternalFreePool() that will not update profile for this FreePool action.
730 CoreInternalFreePool (DriverInfoData
);
737 Return if this memory type needs to be recorded into memory profile.
738 If BIOS memory type (0 ~ EfiMaxMemoryType), it checks bit (1 << MemoryType).
739 If OS memory type (0x80000000 ~ 0xFFFFFFFF), it checks bit63 - 0x8000000000000000.
741 @param MemoryType Memory type.
743 @retval TRUE This memory type need to be recorded.
744 @retval FALSE This memory type need not to be recorded.
748 CoreNeedRecordProfile (
749 IN EFI_MEMORY_TYPE MemoryType
754 if ((UINT32
) MemoryType
>= 0x80000000) {
757 TestBit
= LShiftU64 (1, MemoryType
);
760 if ((PcdGet64 (PcdMemoryProfileMemoryType
) & TestBit
) != 0) {
768 Convert EFI memory type to profile memory index. The rule is:
769 If BIOS memory type (0 ~ EfiMaxMemoryType), ProfileMemoryIndex = MemoryType.
770 If OS memory type (0x80000000 ~ 0xFFFFFFFF), ProfileMemoryIndex = EfiMaxMemoryType.
772 @param MemoryType Memory type.
774 @return EFI memory type as profile memory index.
778 GetProfileMemoryIndex (
779 IN EFI_MEMORY_TYPE MemoryType
782 if ((UINT32
) MemoryType
>= 0x80000000) {
783 return EfiMaxMemoryType
;
790 Update memory profile Allocate information.
792 @param CallerAddress Address of caller who call Allocate.
793 @param Action This Allocate action.
794 @param MemoryType Memory type.
795 @param Size Buffer size.
796 @param Buffer Buffer address.
798 @retval TRUE Profile udpate success.
799 @retval FALSE Profile update fail.
803 CoreUpdateProfileAllocate (
804 IN PHYSICAL_ADDRESS CallerAddress
,
805 IN MEMORY_PROFILE_ACTION Action
,
806 IN EFI_MEMORY_TYPE MemoryType
,
812 MEMORY_PROFILE_CONTEXT
*Context
;
813 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
814 MEMORY_PROFILE_ALLOC_INFO
*AllocInfo
;
815 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
816 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
817 MEMORY_PROFILE_ALLOC_INFO_DATA
*AllocInfoData
;
818 EFI_MEMORY_TYPE ProfileMemoryIndex
;
820 ContextData
= GetMemoryProfileContext ();
821 if (ContextData
== NULL
) {
825 DriverInfoData
= GetMemoryProfileDriverInfoFromAddress (ContextData
, CallerAddress
);
826 ASSERT (DriverInfoData
!= NULL
);
829 // Use CoreInternalAllocatePool() that will not update profile for this AllocatePool action.
831 Status
= CoreInternalAllocatePool (
833 sizeof (*AllocInfoData
),
834 (VOID
**) &AllocInfoData
836 if (EFI_ERROR (Status
)) {
839 AllocInfo
= &AllocInfoData
->AllocInfo
;
840 AllocInfoData
->Signature
= MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
;
841 AllocInfo
->Header
.Signature
= MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
;
842 AllocInfo
->Header
.Length
= sizeof (MEMORY_PROFILE_ALLOC_INFO
);
843 AllocInfo
->Header
.Revision
= MEMORY_PROFILE_ALLOC_INFO_REVISION
;
844 AllocInfo
->CallerAddress
= CallerAddress
;
845 AllocInfo
->SequenceId
= ContextData
->Context
.SequenceCount
;
846 AllocInfo
->Action
= Action
;
847 AllocInfo
->MemoryType
= MemoryType
;
848 AllocInfo
->Buffer
= (PHYSICAL_ADDRESS
) (UINTN
) Buffer
;
849 AllocInfo
->Size
= Size
;
851 InsertTailList (DriverInfoData
->AllocInfoList
, &AllocInfoData
->Link
);
853 ProfileMemoryIndex
= GetProfileMemoryIndex (MemoryType
);
855 DriverInfo
= &DriverInfoData
->DriverInfo
;
856 DriverInfo
->CurrentUsage
+= Size
;
857 if (DriverInfo
->PeakUsage
< DriverInfo
->CurrentUsage
) {
858 DriverInfo
->PeakUsage
= DriverInfo
->CurrentUsage
;
860 DriverInfo
->CurrentUsageByType
[ProfileMemoryIndex
] += Size
;
861 if (DriverInfo
->PeakUsageByType
[ProfileMemoryIndex
] < DriverInfo
->CurrentUsageByType
[ProfileMemoryIndex
]) {
862 DriverInfo
->PeakUsageByType
[ProfileMemoryIndex
] = DriverInfo
->CurrentUsageByType
[ProfileMemoryIndex
];
864 DriverInfo
->AllocRecordCount
++;
866 Context
= &ContextData
->Context
;
867 Context
->CurrentTotalUsage
+= Size
;
868 if (Context
->PeakTotalUsage
< Context
->CurrentTotalUsage
) {
869 Context
->PeakTotalUsage
= Context
->CurrentTotalUsage
;
871 Context
->CurrentTotalUsageByType
[ProfileMemoryIndex
] += Size
;
872 if (Context
->PeakTotalUsageByType
[ProfileMemoryIndex
] < Context
->CurrentTotalUsageByType
[ProfileMemoryIndex
]) {
873 Context
->PeakTotalUsageByType
[ProfileMemoryIndex
] = Context
->CurrentTotalUsageByType
[ProfileMemoryIndex
];
875 Context
->SequenceCount
++;
881 Get memory profile alloc info from memory profile
883 @param DriverInfoData Driver info
884 @param Action This Free action
885 @param Size Buffer size
886 @param Buffer Buffer address
888 @return Pointer to memory profile alloc info.
890 MEMORY_PROFILE_ALLOC_INFO_DATA
*
891 GetMemoryProfileAllocInfoFromAddress (
892 IN MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
,
893 IN MEMORY_PROFILE_ACTION Action
,
898 LIST_ENTRY
*AllocInfoList
;
899 LIST_ENTRY
*AllocLink
;
900 MEMORY_PROFILE_ALLOC_INFO
*AllocInfo
;
901 MEMORY_PROFILE_ALLOC_INFO_DATA
*AllocInfoData
;
903 AllocInfoList
= DriverInfoData
->AllocInfoList
;
905 for (AllocLink
= AllocInfoList
->ForwardLink
;
906 AllocLink
!= AllocInfoList
;
907 AllocLink
= AllocLink
->ForwardLink
) {
910 MEMORY_PROFILE_ALLOC_INFO_DATA
,
912 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
914 AllocInfo
= &AllocInfoData
->AllocInfo
;
915 if (AllocInfo
->Action
!= Action
) {
919 case MemoryProfileActionAllocatePages
:
920 if ((AllocInfo
->Buffer
<= (PHYSICAL_ADDRESS
) (UINTN
) Buffer
) &&
921 ((AllocInfo
->Buffer
+ AllocInfo
->Size
) >= ((PHYSICAL_ADDRESS
) (UINTN
) Buffer
+ Size
))) {
922 return AllocInfoData
;
925 case MemoryProfileActionAllocatePool
:
926 if (AllocInfo
->Buffer
== (PHYSICAL_ADDRESS
) (UINTN
) Buffer
) {
927 return AllocInfoData
;
940 Update memory profile Free information.
942 @param CallerAddress Address of caller who call Free.
943 @param Action This Free action.
944 @param Size Buffer size.
945 @param Buffer Buffer address.
947 @retval TRUE Profile udpate success.
948 @retval FALSE Profile update fail.
952 CoreUpdateProfileFree (
953 IN PHYSICAL_ADDRESS CallerAddress
,
954 IN MEMORY_PROFILE_ACTION Action
,
959 MEMORY_PROFILE_CONTEXT
*Context
;
960 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
961 MEMORY_PROFILE_ALLOC_INFO
*AllocInfo
;
962 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
963 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
964 LIST_ENTRY
*DriverLink
;
965 LIST_ENTRY
*DriverInfoList
;
966 MEMORY_PROFILE_DRIVER_INFO_DATA
*ThisDriverInfoData
;
967 MEMORY_PROFILE_ALLOC_INFO_DATA
*AllocInfoData
;
968 EFI_MEMORY_TYPE ProfileMemoryIndex
;
970 ContextData
= GetMemoryProfileContext ();
971 if (ContextData
== NULL
) {
975 DriverInfoData
= GetMemoryProfileDriverInfoFromAddress (ContextData
, CallerAddress
);
976 ASSERT (DriverInfoData
!= NULL
);
979 case MemoryProfileActionFreePages
:
980 AllocInfoData
= GetMemoryProfileAllocInfoFromAddress (DriverInfoData
, MemoryProfileActionAllocatePages
, Size
, Buffer
);
982 case MemoryProfileActionFreePool
:
983 AllocInfoData
= GetMemoryProfileAllocInfoFromAddress (DriverInfoData
, MemoryProfileActionAllocatePool
, 0, Buffer
);
987 AllocInfoData
= NULL
;
990 if (AllocInfoData
== NULL
) {
992 // Legal case, because driver A might free memory allocated by driver B, by some protocol.
994 DriverInfoList
= ContextData
->DriverInfoList
;
996 for (DriverLink
= DriverInfoList
->ForwardLink
;
997 DriverLink
!= DriverInfoList
;
998 DriverLink
= DriverLink
->ForwardLink
) {
999 ThisDriverInfoData
= CR (
1001 MEMORY_PROFILE_DRIVER_INFO_DATA
,
1003 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1006 case MemoryProfileActionFreePages
:
1007 AllocInfoData
= GetMemoryProfileAllocInfoFromAddress (ThisDriverInfoData
, MemoryProfileActionAllocatePages
, Size
, Buffer
);
1009 case MemoryProfileActionFreePool
:
1010 AllocInfoData
= GetMemoryProfileAllocInfoFromAddress (ThisDriverInfoData
, MemoryProfileActionAllocatePool
, 0, Buffer
);
1014 AllocInfoData
= NULL
;
1017 if (AllocInfoData
!= NULL
) {
1018 DriverInfoData
= ThisDriverInfoData
;
1023 if (AllocInfoData
== NULL
) {
1025 // No matched allocate operation is found for this free operation.
1026 // It is because the specified memory type allocate operation has been
1027 // filtered by CoreNeedRecordProfile(), but free operations have no
1028 // memory type information, they can not be filtered by CoreNeedRecordProfile().
1029 // Then, they will be filtered here.
1035 Context
= &ContextData
->Context
;
1036 DriverInfo
= &DriverInfoData
->DriverInfo
;
1037 AllocInfo
= &AllocInfoData
->AllocInfo
;
1039 ProfileMemoryIndex
= GetProfileMemoryIndex (AllocInfo
->MemoryType
);
1041 Context
->CurrentTotalUsage
-= AllocInfo
->Size
;
1042 Context
->CurrentTotalUsageByType
[ProfileMemoryIndex
] -= AllocInfo
->Size
;
1044 DriverInfo
->CurrentUsage
-= AllocInfo
->Size
;
1045 DriverInfo
->CurrentUsageByType
[ProfileMemoryIndex
] -= AllocInfo
->Size
;
1046 DriverInfo
->AllocRecordCount
--;
1048 RemoveEntryList (&AllocInfoData
->Link
);
1050 if (Action
== MemoryProfileActionFreePages
) {
1051 if (AllocInfo
->Buffer
!= (PHYSICAL_ADDRESS
) (UINTN
) Buffer
) {
1052 CoreUpdateProfileAllocate (
1053 AllocInfo
->CallerAddress
,
1054 MemoryProfileActionAllocatePages
,
1055 AllocInfo
->MemoryType
,
1056 (UINTN
) ((PHYSICAL_ADDRESS
) (UINTN
) Buffer
- AllocInfo
->Buffer
),
1057 (VOID
*) (UINTN
) AllocInfo
->Buffer
1060 if (AllocInfo
->Buffer
+ AllocInfo
->Size
!= ((PHYSICAL_ADDRESS
) (UINTN
) Buffer
+ Size
)) {
1061 CoreUpdateProfileAllocate (
1062 AllocInfo
->CallerAddress
,
1063 MemoryProfileActionAllocatePages
,
1064 AllocInfo
->MemoryType
,
1065 (UINTN
) ((AllocInfo
->Buffer
+ AllocInfo
->Size
) - ((PHYSICAL_ADDRESS
) (UINTN
) Buffer
+ Size
)),
1066 (VOID
*) ((UINTN
) Buffer
+ Size
)
1072 // Use CoreInternalFreePool() that will not update profile for this FreePool action.
1074 CoreInternalFreePool (AllocInfoData
);
1080 Update memory profile information.
1082 @param CallerAddress Address of caller who call Allocate or Free.
1083 @param Action This Allocate or Free action.
1084 @param MemoryType Memory type.
1085 @param Size Buffer size.
1086 @param Buffer Buffer address.
1088 @retval TRUE Profile udpate success.
1089 @retval FALSE Profile update fail.
1094 IN PHYSICAL_ADDRESS CallerAddress
,
1095 IN MEMORY_PROFILE_ACTION Action
,
1096 IN EFI_MEMORY_TYPE MemoryType
, // Valid for AllocatePages/AllocatePool
1097 IN UINTN Size
, // Valid for AllocatePages/FreePages/AllocatePool
1101 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
1103 if (!IS_UEFI_MEMORY_PROFILE_ENABLED
) {
1107 if (!mMemoryProfileRecordingStatus
) {
1112 // Free operations have no memory type information, so skip the check.
1114 if ((Action
== MemoryProfileActionAllocatePages
) || (Action
== MemoryProfileActionAllocatePool
)) {
1116 // Only record limited MemoryType.
1118 if (!CoreNeedRecordProfile (MemoryType
)) {
1123 ContextData
= GetMemoryProfileContext ();
1124 if (ContextData
== NULL
) {
1129 case MemoryProfileActionAllocatePages
:
1130 CoreUpdateProfileAllocate (CallerAddress
, Action
, MemoryType
, Size
, Buffer
);
1132 case MemoryProfileActionFreePages
:
1133 CoreUpdateProfileFree (CallerAddress
, Action
, Size
, Buffer
);
1135 case MemoryProfileActionAllocatePool
:
1136 CoreUpdateProfileAllocate (CallerAddress
, Action
, MemoryType
, Size
, Buffer
);
1138 case MemoryProfileActionFreePool
:
1139 CoreUpdateProfileFree (CallerAddress
, Action
, 0, Buffer
);
1148 ////////////////////
1151 Get memory profile data size.
1153 @return Memory profile data size.
1157 MemoryProfileGetDataSize (
1161 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
1162 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
1163 LIST_ENTRY
*DriverInfoList
;
1164 LIST_ENTRY
*DriverLink
;
1168 ContextData
= GetMemoryProfileContext ();
1169 if (ContextData
== NULL
) {
1173 TotalSize
= sizeof (MEMORY_PROFILE_CONTEXT
);
1174 TotalSize
+= sizeof (MEMORY_PROFILE_DRIVER_INFO
) * (UINTN
) ContextData
->Context
.ImageCount
;
1176 DriverInfoList
= ContextData
->DriverInfoList
;
1177 for (DriverLink
= DriverInfoList
->ForwardLink
;
1178 DriverLink
!= DriverInfoList
;
1179 DriverLink
= DriverLink
->ForwardLink
) {
1180 DriverInfoData
= CR (
1182 MEMORY_PROFILE_DRIVER_INFO_DATA
,
1184 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1186 TotalSize
+= sizeof (MEMORY_PROFILE_ALLOC_INFO
) * (UINTN
) DriverInfoData
->DriverInfo
.AllocRecordCount
;
1193 Copy memory profile data.
1195 @param ProfileBuffer The buffer to hold memory profile data.
1199 MemoryProfileCopyData (
1200 IN VOID
*ProfileBuffer
1203 MEMORY_PROFILE_CONTEXT
*Context
;
1204 MEMORY_PROFILE_DRIVER_INFO
*DriverInfo
;
1205 MEMORY_PROFILE_ALLOC_INFO
*AllocInfo
;
1206 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
1207 MEMORY_PROFILE_DRIVER_INFO_DATA
*DriverInfoData
;
1208 MEMORY_PROFILE_ALLOC_INFO_DATA
*AllocInfoData
;
1209 LIST_ENTRY
*DriverInfoList
;
1210 LIST_ENTRY
*DriverLink
;
1211 LIST_ENTRY
*AllocInfoList
;
1212 LIST_ENTRY
*AllocLink
;
1214 ContextData
= GetMemoryProfileContext ();
1215 if (ContextData
== NULL
) {
1219 Context
= ProfileBuffer
;
1220 CopyMem (Context
, &ContextData
->Context
, sizeof (MEMORY_PROFILE_CONTEXT
));
1221 DriverInfo
= (MEMORY_PROFILE_DRIVER_INFO
*) (Context
+ 1);
1223 DriverInfoList
= ContextData
->DriverInfoList
;
1224 for (DriverLink
= DriverInfoList
->ForwardLink
;
1225 DriverLink
!= DriverInfoList
;
1226 DriverLink
= DriverLink
->ForwardLink
) {
1227 DriverInfoData
= CR (
1229 MEMORY_PROFILE_DRIVER_INFO_DATA
,
1231 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1233 CopyMem (DriverInfo
, &DriverInfoData
->DriverInfo
, sizeof (MEMORY_PROFILE_DRIVER_INFO
));
1234 AllocInfo
= (MEMORY_PROFILE_ALLOC_INFO
*) (DriverInfo
+ 1);
1236 AllocInfoList
= DriverInfoData
->AllocInfoList
;
1237 for (AllocLink
= AllocInfoList
->ForwardLink
;
1238 AllocLink
!= AllocInfoList
;
1239 AllocLink
= AllocLink
->ForwardLink
) {
1240 AllocInfoData
= CR (
1242 MEMORY_PROFILE_ALLOC_INFO_DATA
,
1244 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1246 CopyMem (AllocInfo
, &AllocInfoData
->AllocInfo
, sizeof (MEMORY_PROFILE_ALLOC_INFO
));
1250 DriverInfo
= (MEMORY_PROFILE_DRIVER_INFO
*) ((UINTN
) (DriverInfo
+ 1) + sizeof (MEMORY_PROFILE_ALLOC_INFO
) * (UINTN
) DriverInfo
->AllocRecordCount
);
1255 Get memory profile data.
1257 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
1258 @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer.
1259 On return, points to the size of the data returned in ProfileBuffer.
1260 @param[out] ProfileBuffer Profile buffer.
1262 @return EFI_SUCCESS Get the memory profile data successfully.
1263 @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data.
1264 ProfileSize is updated with the size required.
1269 ProfileProtocolGetData (
1270 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
1271 IN OUT UINT64
*ProfileSize
,
1272 OUT VOID
*ProfileBuffer
1276 MEMORY_PROFILE_CONTEXT_DATA
*ContextData
;
1277 BOOLEAN MemoryProfileRecordingStatus
;
1279 ContextData
= GetMemoryProfileContext ();
1280 if (ContextData
== NULL
) {
1281 return EFI_UNSUPPORTED
;
1284 MemoryProfileRecordingStatus
= mMemoryProfileRecordingStatus
;
1285 mMemoryProfileRecordingStatus
= FALSE
;
1287 Size
= MemoryProfileGetDataSize ();
1289 if (*ProfileSize
< Size
) {
1290 *ProfileSize
= Size
;
1291 mMemoryProfileRecordingStatus
= MemoryProfileRecordingStatus
;
1292 return EFI_BUFFER_TOO_SMALL
;
1295 *ProfileSize
= Size
;
1296 MemoryProfileCopyData (ProfileBuffer
);
1298 mMemoryProfileRecordingStatus
= MemoryProfileRecordingStatus
;
1303 Register image to memory profile.
1305 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
1306 @param[in] FilePath File path of the image.
1307 @param[in] ImageBase Image base address.
1308 @param[in] ImageSize Image size.
1309 @param[in] FileType File type of the image.
1311 @return EFI_SUCCESS Register success.
1312 @return EFI_OUT_OF_RESOURCE No enough resource for this register.
1317 ProfileProtocolRegisterImage (
1318 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
1319 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
1320 IN PHYSICAL_ADDRESS ImageBase
,
1321 IN UINT64 ImageSize
,
1322 IN EFI_FV_FILETYPE FileType
1326 LOADED_IMAGE_PRIVATE_DATA DriverEntry
;
1327 VOID
*EntryPointInImage
;
1329 ZeroMem (&DriverEntry
, sizeof (DriverEntry
));
1330 DriverEntry
.Info
.FilePath
= FilePath
;
1331 DriverEntry
.ImageContext
.ImageAddress
= ImageBase
;
1332 DriverEntry
.ImageContext
.ImageSize
= ImageSize
;
1333 Status
= InternalPeCoffGetEntryPoint ((VOID
*) (UINTN
) ImageBase
, &EntryPointInImage
);
1334 ASSERT_EFI_ERROR (Status
);
1335 DriverEntry
.ImageContext
.EntryPoint
= (PHYSICAL_ADDRESS
) (UINTN
) EntryPointInImage
;
1336 DriverEntry
.ImageContext
.ImageType
= InternalPeCoffGetSubsystem ((VOID
*) (UINTN
) ImageBase
);
1338 return RegisterMemoryProfileImage (&DriverEntry
, FileType
) ? EFI_SUCCESS
: EFI_OUT_OF_RESOURCES
;
1342 Unregister image from memory profile.
1344 @param[in] This The EDKII_MEMORY_PROFILE_PROTOCOL instance.
1345 @param[in] FilePath File path of the image.
1346 @param[in] ImageBase Image base address.
1347 @param[in] ImageSize Image size.
1349 @return EFI_SUCCESS Unregister success.
1350 @return EFI_NOT_FOUND The image is not found.
1355 ProfileProtocolUnregisterImage (
1356 IN EDKII_MEMORY_PROFILE_PROTOCOL
*This
,
1357 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
1358 IN PHYSICAL_ADDRESS ImageBase
,
1363 LOADED_IMAGE_PRIVATE_DATA DriverEntry
;
1364 VOID
*EntryPointInImage
;
1366 ZeroMem (&DriverEntry
, sizeof (DriverEntry
));
1367 DriverEntry
.Info
.FilePath
= FilePath
;
1368 DriverEntry
.ImageContext
.ImageAddress
= ImageBase
;
1369 DriverEntry
.ImageContext
.ImageSize
= ImageSize
;
1370 Status
= InternalPeCoffGetEntryPoint ((VOID
*) (UINTN
) ImageBase
, &EntryPointInImage
);
1371 ASSERT_EFI_ERROR (Status
);
1372 DriverEntry
.ImageContext
.EntryPoint
= (PHYSICAL_ADDRESS
) (UINTN
) EntryPointInImage
;
1374 return UnregisterMemoryProfileImage (&DriverEntry
) ? EFI_SUCCESS
: EFI_NOT_FOUND
;
1377 ////////////////////