summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c')
-rw-r--r--MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c611
1 files changed, 322 insertions, 289 deletions
diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
index 62bbe3cdc8..00e33b707d 100644
--- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
+++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
@@ -9,15 +9,15 @@
#include "DxeMain.h"
#include "Imem.h"
-#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
+#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_CONTEXT Context;
- LIST_ENTRY *DriverInfoList;
+ UINT32 Signature;
+ MEMORY_PROFILE_CONTEXT Context;
+ LIST_ENTRY *DriverInfoList;
} MEMORY_PROFILE_CONTEXT_DATA;
typedef struct {
@@ -29,15 +29,14 @@ typedef struct {
} MEMORY_PROFILE_DRIVER_INFO_DATA;
typedef struct {
- UINT32 Signature;
- MEMORY_PROFILE_ALLOC_INFO AllocInfo;
- CHAR8 *ActionString;
- LIST_ENTRY Link;
+ UINT32 Signature;
+ MEMORY_PROFILE_ALLOC_INFO AllocInfo;
+ CHAR8 *ActionString;
+ LIST_ENTRY Link;
} MEMORY_PROFILE_ALLOC_INFO_DATA;
-
-GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
+GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY mImageQueue = INITIALIZE_LIST_HEAD_VARIABLE (mImageQueue);
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext = {
MEMORY_PROFILE_CONTEXT_SIGNATURE,
{
{
@@ -47,21 +46,21 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext
},
0,
0,
- {0},
- {0},
+ { 0 },
+ { 0 },
0,
0,
0
},
&mImageQueue,
};
-GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
-GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize;
/**
Get memory profile data.
@@ -82,7 +81,7 @@ EFIAPI
ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
);
/**
@@ -103,11 +102,11 @@ ProfileProtocolGetData (
EFI_STATUS
EFIAPI
ProfileProtocolRegisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN EFI_FV_FILETYPE FileType
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN EFI_FV_FILETYPE FileType
);
/**
@@ -127,10 +126,10 @@ ProfileProtocolRegisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolUnregisterImage (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize
);
/**
@@ -147,8 +146,8 @@ ProfileProtocolUnregisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
);
/**
@@ -164,8 +163,8 @@ ProfileProtocolGetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
);
/**
@@ -194,16 +193,16 @@ ProfileProtocolSetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
);
-GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
ProfileProtocolGetData,
ProfileProtocolRegisterImage,
ProfileProtocolUnregisterImage,
@@ -268,22 +267,22 @@ InternalPeCoffGetSubsystem (
ASSERT (Pe32Data != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
return Hdr.Te->Subsystem;
- } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
Magic = Hdr.Pe32->OptionalHeader.Magic;
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
return Hdr.Pe32->OptionalHeader.Subsystem;
@@ -318,23 +317,23 @@ InternalPeCoffGetEntryPoint (
OUT VOID **EntryPoint
)
{
- EFI_IMAGE_DOS_HEADER *DosHdr;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
ASSERT (Pe32Data != NULL);
ASSERT (EntryPoint != NULL);
- DosHdr = (EFI_IMAGE_DOS_HEADER *) Pe32Data;
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) ((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *) Pe32Data;
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
}
//
@@ -342,10 +341,10 @@ InternalPeCoffGetEntryPoint (
// AddressOfEntryPoint is common for PE32 & PE32+
//
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);
return RETURN_SUCCESS;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
- *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
+ *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
return RETURN_SUCCESS;
}
@@ -368,30 +367,30 @@ InternalPeCoffGetEntryPoint (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
BuildDriverInfo (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS ImageBase,
- IN UINT64 ImageSize,
- IN PHYSICAL_ADDRESS EntryPoint,
- IN UINT16 ImageSubsystem,
- IN EFI_FV_FILETYPE FileType
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN UINT64 ImageSize,
+ IN PHYSICAL_ADDRESS EntryPoint,
+ IN UINT16 ImageSubsystem,
+ IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- VOID *EntryPointInImage;
- CHAR8 *PdbString;
- UINTN PdbSize;
- UINTN PdbOccupiedSize;
-
- PdbSize = 0;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ VOID *EntryPointInImage;
+ CHAR8 *PdbString;
+ UINTN PdbSize;
+ UINTN PdbOccupiedSize;
+
+ PdbSize = 0;
PdbOccupiedSize = 0;
- PdbString = NULL;
+ PdbString = NULL;
if (ImageBase != 0) {
- PdbString = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageBase);
+ PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageBase);
if (PdbString != NULL) {
- PdbSize = AsciiStrSize (PdbString);
+ PdbSize = AsciiStrSize (PdbString);
PdbOccupiedSize = GET_OCCUPIED_SIZE (PdbSize, sizeof (UINT64));
}
}
@@ -402,53 +401,56 @@ BuildDriverInfo (
Status = CoreInternalAllocatePool (
EfiBootServicesData,
sizeof (*DriverInfoData) + sizeof (LIST_ENTRY) + PdbSize,
- (VOID **) &DriverInfoData
+ (VOID **)&DriverInfoData
);
if (EFI_ERROR (Status)) {
return NULL;
}
+
ASSERT (DriverInfoData != NULL);
ZeroMem (DriverInfoData, sizeof (*DriverInfoData));
- DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
+ DriverInfo = &DriverInfoData->DriverInfo;
+ DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
DriverInfo->Header.Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
- DriverInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
- DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
+ DriverInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_DRIVER_INFO) + PdbOccupiedSize);
+ DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
if (FileName != NULL) {
CopyMem (&DriverInfo->FileName, FileName, sizeof (EFI_GUID));
}
- DriverInfo->ImageBase = ImageBase;
- DriverInfo->ImageSize = ImageSize;
- DriverInfo->EntryPoint = EntryPoint;
+
+ DriverInfo->ImageBase = ImageBase;
+ DriverInfo->ImageSize = ImageSize;
+ DriverInfo->EntryPoint = EntryPoint;
DriverInfo->ImageSubsystem = ImageSubsystem;
if ((EntryPoint != 0) && ((EntryPoint < ImageBase) || (EntryPoint >= (ImageBase + ImageSize)))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageBuffer here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
}
- DriverInfo->FileType = FileType;
- DriverInfoData->AllocInfoList = (LIST_ENTRY *) (DriverInfoData + 1);
+
+ DriverInfo->FileType = FileType;
+ DriverInfoData->AllocInfoList = (LIST_ENTRY *)(DriverInfoData + 1);
InitializeListHead (DriverInfoData->AllocInfoList);
- DriverInfo->CurrentUsage = 0;
- DriverInfo->PeakUsage = 0;
+ DriverInfo->CurrentUsage = 0;
+ DriverInfo->PeakUsage = 0;
DriverInfo->AllocRecordCount = 0;
if (PdbSize != 0) {
- DriverInfo->PdbStringOffset = (UINT16) sizeof (MEMORY_PROFILE_DRIVER_INFO);
- DriverInfoData->PdbString = (CHAR8 *) (DriverInfoData->AllocInfoList + 1);
+ DriverInfo->PdbStringOffset = (UINT16)sizeof (MEMORY_PROFILE_DRIVER_INFO);
+ DriverInfoData->PdbString = (CHAR8 *)(DriverInfoData->AllocInfoList + 1);
CopyMem (DriverInfoData->PdbString, PdbString, PdbSize);
} else {
DriverInfo->PdbStringOffset = 0;
- DriverInfoData->PdbString = NULL;
+ DriverInfoData->PdbString = NULL;
}
InsertTailList (ContextData->DriverInfoList, &DriverInfoData->Link);
- ContextData->Context.ImageCount ++;
+ ContextData->Context.ImageCount++;
ContextData->Context.TotalImageSize += DriverInfo->ImageSize;
return DriverInfoData;
@@ -465,13 +467,13 @@ BuildDriverInfo (
**/
BOOLEAN
NeedRecordThisDriver (
- IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath
)
{
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
- UINTN DevicePathSize;
- UINTN FilePathSize;
+ EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance;
+ UINTN DevicePathSize;
+ UINTN FilePathSize;
if (!IsDevicePathValid (mMemoryProfileDriverPath, mMemoryProfileDriverPathSize)) {
//
@@ -483,7 +485,7 @@ NeedRecordThisDriver (
//
// Record FilePath without END node.
//
- FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
+ FilePathSize = GetDevicePathSize (DriverFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
DevicePathInstance = mMemoryProfileDriverPath;
do {
@@ -500,14 +502,15 @@ NeedRecordThisDriver (
//
DevicePathSize = (UINTN)TmpDevicePath - (UINTN)DevicePathInstance;
if ((FilePathSize == DevicePathSize) &&
- (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0)) {
+ (CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0))
+ {
return TRUE;
}
//
// Get next instance.
//
- DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength(TmpDevicePath));
+ DevicePathInstance = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)DevicePathInstance + DevicePathSize + DevicePathNodeLength (TmpDevicePath));
} while (DevicePathSubType (TmpDevicePath) != END_ENTIRE_DEVICE_PATH_SUBTYPE);
return FALSE;
@@ -525,22 +528,22 @@ NeedRecordThisDriver (
**/
BOOLEAN
RegisterDxeCore (
- IN VOID *HobStart,
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
+ IN VOID *HobStart,
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData
)
{
- EFI_PEI_HOB_POINTERS DxeCoreHob;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- PHYSICAL_ADDRESS ImageBase;
- UINT8 TempBuffer[sizeof(MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof(EFI_DEVICE_PATH_PROTOCOL)];
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
+ EFI_PEI_HOB_POINTERS DxeCoreHob;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ PHYSICAL_ADDRESS ImageBase;
+ UINT8 TempBuffer[sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH) + sizeof (EFI_DEVICE_PATH_PROTOCOL)];
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FilePath;
ASSERT (ContextData != NULL);
//
// Searching for image hob
//
- DxeCoreHob.Raw = HobStart;
+ DxeCoreHob.Raw = HobStart;
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
//
@@ -548,26 +551,28 @@ RegisterDxeCore (
//
break;
}
+
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
}
+
ASSERT (DxeCoreHob.Raw != NULL);
- FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) TempBuffer;
+ FilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)TempBuffer;
EfiInitializeFwVolDevicepathNode (FilePath, &DxeCoreHob.MemoryAllocationModule->ModuleName);
SetDevicePathEndNode (FilePath + 1);
- if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *) FilePath)) {
+ if (!NeedRecordThisDriver ((EFI_DEVICE_PATH_PROTOCOL *)FilePath)) {
return FALSE;
}
- ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
+ ImageBase = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
DriverInfoData = BuildDriverInfo (
ContextData,
&DxeCoreHob.MemoryAllocationModule->ModuleName,
ImageBase,
DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength,
DxeCoreHob.MemoryAllocationModule->EntryPoint,
- InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase),
+ InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase),
EFI_FV_FILETYPE_DXE_CORE
);
if (DriverInfoData == NULL) {
@@ -585,10 +590,10 @@ RegisterDxeCore (
**/
VOID
MemoryProfileInit (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -605,9 +610,10 @@ MemoryProfileInit (
} else {
mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_ENABLE;
}
+
mMemoryProfileDriverPathSize = PcdGetSize (PcdMemoryProfileDriverPath);
- mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
- mMemoryProfileContextPtr = &mMemoryProfileContext;
+ mMemoryProfileDriverPath = AllocateCopyPool (mMemoryProfileDriverPathSize, PcdGetPtr (PcdMemoryProfileDriverPath));
+ mMemoryProfileContextPtr = &mMemoryProfileContext;
RegisterDxeCore (HobStart, &mMemoryProfileContext);
@@ -623,8 +629,8 @@ MemoryProfileInstallProtocol (
VOID
)
{
- EFI_HANDLE Handle;
- EFI_STATUS Status;
+ EFI_HANDLE Handle;
+ EFI_STATUS Status;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return;
@@ -650,21 +656,22 @@ MemoryProfileInstallProtocol (
**/
EFI_GUID *
GetFileNameFromFilePath (
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath
)
{
- MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
- EFI_GUID *FileName;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *ThisFilePath;
+ EFI_GUID *FileName;
FileName = NULL;
if (FilePath != NULL) {
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePath;
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath;
while (!IsDevicePathEnd (ThisFilePath)) {
FileName = EfiGetNameGuidFromFwVolDevicePathNode (ThisFilePath);
if (FileName != NULL) {
break;
}
- ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) NextDevicePathNode (ThisFilePath);
+
+ ThisFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)NextDevicePathNode (ThisFilePath);
}
}
@@ -689,8 +696,8 @@ RegisterMemoryProfileImage (
IN EFI_FV_FILETYPE FileType
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -733,21 +740,22 @@ RegisterMemoryProfileImage (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoByFileNameAndAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN EFI_GUID *FileName,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN EFI_GUID *FileName,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -757,7 +765,8 @@ GetMemoryProfileDriverInfoByFileNameAndAddress (
DriverInfo = &DriverInfoData->DriverInfo;
if ((CompareGuid (&DriverInfo->FileName, FileName)) &&
(Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -777,20 +786,21 @@ GetMemoryProfileDriverInfoByFileNameAndAddress (
**/
MEMORY_PROFILE_DRIVER_INFO_DATA *
GetMemoryProfileDriverInfoFromAddress (
- IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
- IN PHYSICAL_ADDRESS Address
+ IN MEMORY_PROFILE_CONTEXT_DATA *ContextData,
+ IN PHYSICAL_ADDRESS Address
)
{
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *DriverInfoList;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *DriverInfoList;
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -799,7 +809,8 @@ GetMemoryProfileDriverInfoFromAddress (
);
DriverInfo = &DriverInfoData->DriverInfo;
if ((Address >= DriverInfo->ImageBase) &&
- (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize))) {
+ (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
+ {
return DriverInfoData;
}
}
@@ -820,15 +831,15 @@ GetMemoryProfileDriverInfoFromAddress (
**/
EFI_STATUS
UnregisterMemoryProfileImage (
- IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
+ IN LOADED_IMAGE_PRIVATE_DATA *DriverEntry
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- EFI_GUID *FileName;
- PHYSICAL_ADDRESS ImageAddress;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ EFI_GUID *FileName;
+ PHYSICAL_ADDRESS ImageAddress;
+ VOID *EntryPointInImage;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -844,23 +855,26 @@ UnregisterMemoryProfileImage (
}
DriverInfoData = NULL;
- FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
- ImageAddress = DriverEntry->ImageContext.ImageAddress;
+ FileName = GetFileNameFromFilePath (DriverEntry->Info.FilePath);
+ ImageAddress = DriverEntry->ImageContext.ImageAddress;
if ((DriverEntry->ImageContext.EntryPoint < ImageAddress) || (DriverEntry->ImageContext.EntryPoint >= (ImageAddress + DriverEntry->ImageContext.ImageSize))) {
//
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageAddress here to align the EntryPoint.
//
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageAddress, &EntryPointInImage);
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageAddress, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- ImageAddress = ImageAddress + (UINTN) DriverEntry->ImageContext.EntryPoint - (UINTN) EntryPointInImage;
+ ImageAddress = ImageAddress + (UINTN)DriverEntry->ImageContext.EntryPoint - (UINTN)EntryPointInImage;
}
+
if (FileName != NULL) {
DriverInfoData = GetMemoryProfileDriverInfoByFileNameAndAddress (ContextData, FileName, ImageAddress);
}
+
if (DriverInfoData == NULL) {
DriverInfoData = GetMemoryProfileDriverInfoFromAddress (ContextData, ImageAddress);
}
+
if (DriverInfoData == NULL) {
return EFI_NOT_FOUND;
}
@@ -868,11 +882,11 @@ UnregisterMemoryProfileImage (
ContextData->Context.TotalImageSize -= DriverInfoData->DriverInfo.ImageSize;
// Keep the ImageBase for RVA calculation in Application.
- //DriverInfoData->DriverInfo.ImageBase = 0;
+ // DriverInfoData->DriverInfo.ImageBase = 0;
DriverInfoData->DriverInfo.ImageSize = 0;
if (DriverInfoData->DriverInfo.PeakUsage == 0) {
- ContextData->Context.ImageCount --;
+ ContextData->Context.ImageCount--;
RemoveEntryList (&DriverInfoData->Link);
//
// Use CoreInternalFreePool() that will not update profile for this FreePool action.
@@ -897,14 +911,14 @@ UnregisterMemoryProfileImage (
**/
BOOLEAN
CoreNeedRecordProfile (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- UINT64 TestBit;
+ UINT64 TestBit;
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
TestBit = BIT63;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
TestBit = BIT62;
} else {
TestBit = LShiftU64 (1, MemoryType);
@@ -930,12 +944,12 @@ CoreNeedRecordProfile (
**/
UINTN
GetProfileMemoryIndex (
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_MEMORY_TYPE MemoryType
)
{
- if ((UINT32) MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
+ if ((UINT32)MemoryType >= MEMORY_TYPE_OS_RESERVED_MIN) {
return EfiMaxMemoryType;
- } else if ((UINT32) MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
+ } else if ((UINT32)MemoryType >= MEMORY_TYPE_OEM_RESERVED_MIN) {
return EfiMaxMemoryType + 1;
} else {
return MemoryType;
@@ -968,17 +982,17 @@ CoreUpdateProfileAllocate (
IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- UINTN ProfileMemoryIndex;
- MEMORY_PROFILE_ACTION BasicAction;
- UINTN ActionStringSize;
- UINTN ActionStringOccupiedSize;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ UINTN ProfileMemoryIndex;
+ MEMORY_PROFILE_ACTION BasicAction;
+ UINTN ActionStringSize;
+ UINTN ActionStringOccupiedSize;
BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
@@ -992,10 +1006,10 @@ CoreUpdateProfileAllocate (
return EFI_UNSUPPORTED;
}
- ActionStringSize = 0;
+ ActionStringSize = 0;
ActionStringOccupiedSize = 0;
if (ActionString != NULL) {
- ActionStringSize = AsciiStrSize (ActionString);
+ ActionStringSize = AsciiStrSize (ActionString);
ActionStringOccupiedSize = GET_OCCUPIED_SIZE (ActionStringSize, sizeof (UINT64));
}
@@ -1003,48 +1017,49 @@ CoreUpdateProfileAllocate (
// Use CoreInternalAllocatePool() that will not update profile for this AllocatePool action.
//
AllocInfoData = NULL;
- Status = CoreInternalAllocatePool (
- EfiBootServicesData,
- sizeof (*AllocInfoData) + ActionStringSize,
- (VOID **) &AllocInfoData
- );
+ Status = CoreInternalAllocatePool (
+ EfiBootServicesData,
+ sizeof (*AllocInfoData) + ActionStringSize,
+ (VOID **)&AllocInfoData
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
+
ASSERT (AllocInfoData != NULL);
//
// Only update SequenceCount if and only if it is basic action.
//
if (Action == BasicAction) {
- ContextData->Context.SequenceCount ++;
+ ContextData->Context.SequenceCount++;
}
- AllocInfo = &AllocInfoData->AllocInfo;
- AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
- AllocInfo->Header.Length = (UINT16) (sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
- AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
- AllocInfo->CallerAddress = CallerAddress;
- AllocInfo->SequenceId = ContextData->Context.SequenceCount;
- AllocInfo->Action = Action;
- AllocInfo->MemoryType = MemoryType;
- AllocInfo->Buffer = (PHYSICAL_ADDRESS) (UINTN) Buffer;
- AllocInfo->Size = Size;
+ AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
+ AllocInfo->Header.Length = (UINT16)(sizeof (MEMORY_PROFILE_ALLOC_INFO) + ActionStringOccupiedSize);
+ AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
+ AllocInfo->CallerAddress = CallerAddress;
+ AllocInfo->SequenceId = ContextData->Context.SequenceCount;
+ AllocInfo->Action = Action;
+ AllocInfo->MemoryType = MemoryType;
+ AllocInfo->Buffer = (PHYSICAL_ADDRESS)(UINTN)Buffer;
+ AllocInfo->Size = Size;
if (ActionString != NULL) {
- AllocInfo->ActionStringOffset = (UINT16) sizeof (MEMORY_PROFILE_ALLOC_INFO);
- AllocInfoData->ActionString = (CHAR8 *) (AllocInfoData + 1);
+ AllocInfo->ActionStringOffset = (UINT16)sizeof (MEMORY_PROFILE_ALLOC_INFO);
+ AllocInfoData->ActionString = (CHAR8 *)(AllocInfoData + 1);
CopyMem (AllocInfoData->ActionString, ActionString, ActionStringSize);
} else {
AllocInfo->ActionStringOffset = 0;
- AllocInfoData->ActionString = NULL;
+ AllocInfoData->ActionString = NULL;
}
InsertTailList (DriverInfoData->AllocInfoList, &AllocInfoData->Link);
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- DriverInfo->AllocRecordCount ++;
+ DriverInfo->AllocRecordCount++;
//
// Update summary if and only if it is basic action.
@@ -1056,6 +1071,7 @@ CoreUpdateProfileAllocate (
if (DriverInfo->PeakUsage < DriverInfo->CurrentUsage) {
DriverInfo->PeakUsage = DriverInfo->CurrentUsage;
}
+
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] += Size;
if (DriverInfo->PeakUsageByType[ProfileMemoryIndex] < DriverInfo->CurrentUsageByType[ProfileMemoryIndex]) {
DriverInfo->PeakUsageByType[ProfileMemoryIndex] = DriverInfo->CurrentUsageByType[ProfileMemoryIndex];
@@ -1065,6 +1081,7 @@ CoreUpdateProfileAllocate (
if (Context->PeakTotalUsage < Context->CurrentTotalUsage) {
Context->PeakTotalUsage = Context->CurrentTotalUsage;
}
+
Context->CurrentTotalUsageByType[ProfileMemoryIndex] += Size;
if (Context->PeakTotalUsageByType[ProfileMemoryIndex] < Context->CurrentTotalUsageByType[ProfileMemoryIndex]) {
Context->PeakTotalUsageByType[ProfileMemoryIndex] = Context->CurrentTotalUsageByType[ProfileMemoryIndex];
@@ -1087,22 +1104,23 @@ CoreUpdateProfileAllocate (
**/
MEMORY_PROFILE_ALLOC_INFO_DATA *
GetMemoryProfileAllocInfoFromAddress (
- IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
- IN MEMORY_PROFILE_ACTION BasicAction,
- IN UINTN Size,
- IN VOID *Buffer
+ IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData,
+ IN MEMORY_PROFILE_ACTION BasicAction,
+ IN UINTN Size,
+ IN VOID *Buffer
)
{
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1113,17 +1131,21 @@ GetMemoryProfileAllocInfoFromAddress (
if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK) != BasicAction) {
continue;
}
+
switch (BasicAction) {
case MemoryProfileActionAllocatePages:
- if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS) (UINTN) Buffer) &&
- ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size))) {
+ if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS)(UINTN)Buffer) &&
+ ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)))
+ {
return AllocInfoData;
}
+
break;
case MemoryProfileActionAllocatePool:
- if (AllocInfo->Buffer == (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer == (PHYSICAL_ADDRESS)(UINTN)Buffer) {
return AllocInfoData;
}
+
break;
default:
ASSERT (FALSE);
@@ -1186,7 +1208,7 @@ CoreUpdateProfileFree (
// Need use do-while loop to find all possible records,
// because one address might be recorded multiple times.
//
- Found = FALSE;
+ Found = FALSE;
AllocInfoData = NULL;
do {
if (DriverInfoData != NULL) {
@@ -1203,6 +1225,7 @@ CoreUpdateProfileFree (
break;
}
}
+
if (AllocInfoData == NULL) {
//
// Legal case, because driver A might free memory allocated by driver B, by some protocol.
@@ -1211,7 +1234,8 @@ CoreUpdateProfileFree (
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
ThisDriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1230,6 +1254,7 @@ CoreUpdateProfileFree (
AllocInfoData = NULL;
break;
}
+
if (AllocInfoData != NULL) {
DriverInfoData = ThisDriverInfoData;
break;
@@ -1254,44 +1279,45 @@ CoreUpdateProfileFree (
Found = TRUE;
- Context = &ContextData->Context;
+ Context = &ContextData->Context;
DriverInfo = &DriverInfoData->DriverInfo;
- AllocInfo = &AllocInfoData->AllocInfo;
+ AllocInfo = &AllocInfoData->AllocInfo;
- DriverInfo->AllocRecordCount --;
+ DriverInfo->AllocRecordCount--;
//
// Update summary if and only if it is basic action.
//
if (AllocInfo->Action == (AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK)) {
ProfileMemoryIndex = GetProfileMemoryIndex (AllocInfo->MemoryType);
- Context->CurrentTotalUsage -= AllocInfo->Size;
+ Context->CurrentTotalUsage -= AllocInfo->Size;
Context->CurrentTotalUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
- DriverInfo->CurrentUsage -= AllocInfo->Size;
+ DriverInfo->CurrentUsage -= AllocInfo->Size;
DriverInfo->CurrentUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
}
RemoveEntryList (&AllocInfoData->Link);
if (BasicAction == MemoryProfileActionFreePages) {
- if (AllocInfo->Buffer != (PHYSICAL_ADDRESS) (UINTN) Buffer) {
+ if (AllocInfo->Buffer != (PHYSICAL_ADDRESS)(UINTN)Buffer) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((PHYSICAL_ADDRESS) (UINTN) Buffer - AllocInfo->Buffer),
- (VOID *) (UINTN) AllocInfo->Buffer,
+ (UINTN)((PHYSICAL_ADDRESS)(UINTN)Buffer - AllocInfo->Buffer),
+ (VOID *)(UINTN)AllocInfo->Buffer,
AllocInfoData->ActionString
);
}
- if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)) {
+
+ if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)) {
CoreUpdateProfileAllocate (
AllocInfo->CallerAddress,
AllocInfo->Action,
AllocInfo->MemoryType,
- (UINTN) ((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS) (UINTN) Buffer + Size)),
- (VOID *) ((UINTN) Buffer + Size),
+ (UINTN)((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS)(UINTN)Buffer + Size)),
+ (VOID *)((UINTN)Buffer + Size),
AllocInfoData->ActionString
);
}
@@ -1337,9 +1363,9 @@ CoreUpdateProfile (
IN CHAR8 *ActionString OPTIONAL
)
{
- EFI_STATUS Status;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_ACTION BasicAction;
+ EFI_STATUS Status;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_ACTION BasicAction;
if (!IS_UEFI_MEMORY_PROFILE_ENABLED) {
return EFI_UNSUPPORTED;
@@ -1394,6 +1420,7 @@ CoreUpdateProfile (
Status = EFI_UNSUPPORTED;
break;
}
+
CoreReleaseMemoryProfileLock ();
return Status;
@@ -1412,15 +1439,14 @@ MemoryProfileGetDataSize (
VOID
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN TotalSize;
-
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN TotalSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1432,7 +1458,8 @@ MemoryProfileGetDataSize (
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1444,7 +1471,8 @@ MemoryProfileGetDataSize (
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1466,35 +1494,36 @@ MemoryProfileGetDataSize (
**/
VOID
MemoryProfileCopyData (
- IN VOID *ProfileBuffer
+ IN VOID *ProfileBuffer
)
{
- MEMORY_PROFILE_CONTEXT *Context;
- MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
- MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
- MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
- LIST_ENTRY *DriverInfoList;
- LIST_ENTRY *DriverLink;
- LIST_ENTRY *AllocInfoList;
- LIST_ENTRY *AllocLink;
- UINTN PdbSize;
- UINTN ActionStringSize;
+ MEMORY_PROFILE_CONTEXT *Context;
+ MEMORY_PROFILE_DRIVER_INFO *DriverInfo;
+ MEMORY_PROFILE_ALLOC_INFO *AllocInfo;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData;
+ MEMORY_PROFILE_ALLOC_INFO_DATA *AllocInfoData;
+ LIST_ENTRY *DriverInfoList;
+ LIST_ENTRY *DriverLink;
+ LIST_ENTRY *AllocInfoList;
+ LIST_ENTRY *AllocLink;
+ UINTN PdbSize;
+ UINTN ActionStringSize;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
- return ;
+ return;
}
Context = ProfileBuffer;
CopyMem (Context, &ContextData->Context, sizeof (MEMORY_PROFILE_CONTEXT));
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) (Context + 1);
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)(Context + 1);
DriverInfoList = ContextData->DriverInfoList;
for (DriverLink = DriverInfoList->ForwardLink;
DriverLink != DriverInfoList;
- DriverLink = DriverLink->ForwardLink) {
+ DriverLink = DriverLink->ForwardLink)
+ {
DriverInfoData = CR (
DriverLink,
MEMORY_PROFILE_DRIVER_INFO_DATA,
@@ -1504,14 +1533,16 @@ MemoryProfileCopyData (
CopyMem (DriverInfo, &DriverInfoData->DriverInfo, sizeof (MEMORY_PROFILE_DRIVER_INFO));
if (DriverInfo->PdbStringOffset != 0) {
PdbSize = AsciiStrSize (DriverInfoData->PdbString);
- CopyMem ((VOID *) ((UINTN) DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
+ CopyMem ((VOID *)((UINTN)DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) DriverInfo + DriverInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)DriverInfo + DriverInfo->Header.Length);
AllocInfoList = DriverInfoData->AllocInfoList;
for (AllocLink = AllocInfoList->ForwardLink;
AllocLink != AllocInfoList;
- AllocLink = AllocLink->ForwardLink) {
+ AllocLink = AllocLink->ForwardLink)
+ {
AllocInfoData = CR (
AllocLink,
MEMORY_PROFILE_ALLOC_INFO_DATA,
@@ -1521,12 +1552,13 @@ MemoryProfileCopyData (
CopyMem (AllocInfo, &AllocInfoData->AllocInfo, sizeof (MEMORY_PROFILE_ALLOC_INFO));
if (AllocInfo->ActionStringOffset != 0) {
ActionStringSize = AsciiStrSize (AllocInfoData->ActionString);
- CopyMem ((VOID *) ((UINTN) AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
+ CopyMem ((VOID *)((UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
}
- AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *) ((UINTN) AllocInfo + AllocInfo->Header.Length);
+
+ AllocInfo = (MEMORY_PROFILE_ALLOC_INFO *)((UINTN)AllocInfo + AllocInfo->Header.Length);
}
- DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *) AllocInfo;
+ DriverInfo = (MEMORY_PROFILE_DRIVER_INFO *)AllocInfo;
}
}
@@ -1549,25 +1581,25 @@ EFIAPI
ProfileProtocolGetData (
IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
IN OUT UINT64 *ProfileSize,
- OUT VOID *ProfileBuffer
+ OUT VOID *ProfileBuffer
)
{
- UINTN Size;
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
- BOOLEAN MemoryProfileGettingStatus;
+ UINTN Size;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ BOOLEAN MemoryProfileGettingStatus;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
return EFI_UNSUPPORTED;
}
- MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
+ MemoryProfileGettingStatus = mMemoryProfileGettingStatus;
mMemoryProfileGettingStatus = TRUE;
Size = MemoryProfileGetDataSize ();
if (*ProfileSize < Size) {
- *ProfileSize = Size;
+ *ProfileSize = Size;
mMemoryProfileGettingStatus = MemoryProfileGettingStatus;
return EFI_BUFFER_TOO_SMALL;
}
@@ -1604,18 +1636,18 @@ ProfileProtocolRegisterImage (
IN EFI_FV_FILETYPE FileType
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
- DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *) (UINTN) ImageBase);
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
+ DriverEntry.ImageContext.ImageType = InternalPeCoffGetSubsystem ((VOID *)(UINTN)ImageBase);
return RegisterMemoryProfileImage (&DriverEntry, FileType);
}
@@ -1643,17 +1675,17 @@ ProfileProtocolUnregisterImage (
IN UINT64 ImageSize
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA DriverEntry;
- VOID *EntryPointInImage;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA DriverEntry;
+ VOID *EntryPointInImage;
ZeroMem (&DriverEntry, sizeof (DriverEntry));
- DriverEntry.Info.FilePath = FilePath;
+ DriverEntry.Info.FilePath = FilePath;
DriverEntry.ImageContext.ImageAddress = ImageBase;
- DriverEntry.ImageContext.ImageSize = ImageSize;
- Status = InternalPeCoffGetEntryPoint ((VOID *) (UINTN) ImageBase, &EntryPointInImage);
+ DriverEntry.ImageContext.ImageSize = ImageSize;
+ Status = InternalPeCoffGetEntryPoint ((VOID *)(UINTN)ImageBase, &EntryPointInImage);
ASSERT_EFI_ERROR (Status);
- DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS) (UINTN) EntryPointInImage;
+ DriverEntry.ImageContext.EntryPoint = (PHYSICAL_ADDRESS)(UINTN)EntryPointInImage;
return UnregisterMemoryProfileImage (&DriverEntry);
}
@@ -1672,11 +1704,11 @@ ProfileProtocolUnregisterImage (
EFI_STATUS
EFIAPI
ProfileProtocolGetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- OUT BOOLEAN *RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ OUT BOOLEAN *RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1686,6 +1718,7 @@ ProfileProtocolGetRecordingState (
if (RecordingState == NULL) {
return EFI_INVALID_PARAMETER;
}
+
*RecordingState = mMemoryProfileRecordingEnable;
return EFI_SUCCESS;
}
@@ -1703,11 +1736,11 @@ ProfileProtocolGetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolSetRecordingState (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN BOOLEAN RecordingState
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN BOOLEAN RecordingState
)
{
- MEMORY_PROFILE_CONTEXT_DATA *ContextData;
+ MEMORY_PROFILE_CONTEXT_DATA *ContextData;
ContextData = GetMemoryProfileContext ();
if (ContextData == NULL) {
@@ -1744,13 +1777,13 @@ ProfileProtocolSetRecordingState (
EFI_STATUS
EFIAPI
ProfileProtocolRecord (
- IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN MEMORY_PROFILE_ACTION Action,
- IN EFI_MEMORY_TYPE MemoryType,
- IN VOID *Buffer,
- IN UINTN Size,
- IN CHAR8 *ActionString OPTIONAL
+ IN EDKII_MEMORY_PROFILE_PROTOCOL *This,
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
)
{
return CoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);