Move the memory allocation and variable set to BdsEntry, use VariableLock protocol to lock the L”PerfDataMemAddr” variable and prevent malware to update it.

Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14386 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lzeng14
2013-05-23 02:56:41 +00:00
parent d0cec2da21
commit f6c07313d1
6 changed files with 76 additions and 58 deletions

View File

@@ -3,7 +3,7 @@
performance, all the function will only include if the performance
switch is set.
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -19,7 +19,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
PERF_HEADER mPerfHeader;
PERF_DATA mPerfData;
EFI_PHYSICAL_ADDRESS mAcpiLowMemoryBase = 0x0FFFFFFFFULL;
UINT32 mAcpiLowMemoryLength = 0x4000;
/**
Get the short verion of PDB file name to be
@@ -134,40 +133,6 @@ GetNameFromHandle (
return ;
}
/**
Allocates a block of memory to store performance data.
**/
VOID
AllocateMemoryForPerformanceData (
VOID
)
{
EFI_STATUS Status;
if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
//
// Allocate a block of memory that contain performance data to OS
//
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
EFI_SIZE_TO_PAGES (mAcpiLowMemoryLength),
&mAcpiLowMemoryBase
);
if (!EFI_ERROR (Status)) {
gRT->SetVariable (
L"PerfDataMemAddr",
&gPerformanceProtocolGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (EFI_PHYSICAL_ADDRESS),
&mAcpiLowMemoryBase
);
}
}
}
/**
Writes performance data of booting into the allocated memory.
@@ -209,16 +174,13 @@ WriteBootToOsPerformanceData (
// List of flags indicating PerfEntry contains DXE handle
//
BOOLEAN *PerfEntriesAsDxeHandle;
UINTN VarSize;
//
// Record the performance data for End of BDS
//
PERF_END(NULL, "BDS", NULL, 0);
if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
return;
}
//
// Retrieve time stamp count as early as possible
//
@@ -241,6 +203,23 @@ WriteBootToOsPerformanceData (
CountUp = FALSE;
}
if (mAcpiLowMemoryBase == 0x0FFFFFFFF) {
VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
Status = gRT->GetVariable (
L"PerfDataMemAddr",
&gPerformanceProtocolGuid,
NULL,
&VarSize,
&mAcpiLowMemoryBase
);
if (EFI_ERROR (Status)) {
//
// Fail to get the variable, return.
//
return;
}
}
//
// Put Detailed performance data into memory
//
@@ -257,7 +236,7 @@ WriteBootToOsPerformanceData (
}
Ptr = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));
LimitCount = (mAcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);
NumPerfEntries = 0;
LogEntryKey = 0;