]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
MdeModulePkg: Fix potential integer overflow issue
[mirror_edk2.git] / MdeModulePkg / Library / SmmCorePerformanceLib / SmmCorePerformanceLib.c
index 98426c302c2d3d8d0c4fd420564e1bceb0c18d69..e59cc28d537fa8b1db93443a3ec06b6371dc20d6 100644 (file)
@@ -3,13 +3,20 @@
 \r
   This library provides the performance measurement interfaces and initializes performance\r
   logging for the SMM phase.\r
-  It initializes SMM phase performance logging by publishing the Performance Protocol,\r
+  It initializes SMM phase performance logging by publishing the SMM Performance and PerformanceEx Protocol,\r
   which is consumed by SmmPerformanceLib to logging performance data in SMM phase.\r
 \r
   This library is mainly used by SMM Core to start performance logging to ensure that\r
-  SMM Performance Protocol is installed at the very beginning of SMM phase.\r
+  SMM Performance and PerformanceEx Protocol are installed at the very beginning of SMM phase.\r
 \r
-Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+ Caution: This module requires additional review when modified.\r
+ This driver will have external input - performance data and communicate buffer in SMM mode.\r
+ This external input must be validated carefully to avoid security issue like\r
+ buffer overflow, integer overflow.\r
+\r
+ SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.\r
+\r
+Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -44,11 +51,8 @@ BOOLEAN                 mPerformanceMeasurementEnabled;
 \r
 SPIN_LOCK               mSmmPerfLock;\r
 \r
-EFI_SMRAM_DESCRIPTOR    *mSmramRanges;\r
-UINTN                   mSmramRangeCount;\r
-\r
 //\r
-// Interfaces for performance protocol.\r
+// Interfaces for SMM Performance Protocol.\r
 //\r
 PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
   StartGauge,\r
@@ -56,11 +60,20 @@ PERFORMANCE_PROTOCOL mPerformanceInterface = {
   GetGauge\r
 };\r
 \r
+//\r
+// Interfaces for SMM PerformanceEx Protocol.\r
+//\r
+PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r
+  StartGaugeEx,\r
+  EndGaugeEx,\r
+  GetGaugeEx\r
+};\r
+\r
 /**\r
-  Searches in the gauge array with keyword Handle, Token and Module.\r
+  Searches in the gauge array with keyword Handle, Token, Module and Identfier.\r
 \r
   This internal function searches for the gauge entry in the gauge array.\r
-  If there is an entry that exactly matches the given key word triple\r
+  If there is an entry that exactly matches the given keywords\r
   and its end time stamp is zero, then the index of that gauge entry is returned;\r
   otherwise, the the number of gauge entries in the array is returned.\r
 \r
@@ -70,6 +83,7 @@ PERFORMANCE_PROTOCOL mPerformanceInterface = {
                                   that identifies the component being measured.\r
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
+  @param  Identifier              32-bit identifier.\r
 \r
   @retval The index of gauge entry in the array.\r
 \r
@@ -78,12 +92,14 @@ UINT32
 SmmSearchForGaugeEntry (\r
   IN CONST VOID                 *Handle,  OPTIONAL\r
   IN CONST CHAR8                *Token,   OPTIONAL\r
-  IN CONST CHAR8                *Module   OPTIONAL\r
+  IN CONST CHAR8                *Module,   OPTIONAL\r
+  IN CONST UINT32               Identifier\r
   )\r
 {\r
   UINT32                    Index;\r
+  UINT32                    Index2;\r
   UINT32                    NumberOfEntries;\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
 \r
   if (Token == NULL) {\r
     Token = "";\r
@@ -93,13 +109,18 @@ SmmSearchForGaugeEntry (
   }\r
 \r
   NumberOfEntries = mGaugeData->NumberOfEntries;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+\r
+  Index2 = 0;\r
 \r
   for (Index = 0; Index < NumberOfEntries; Index++) {\r
-    if ((GaugeEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
-         AsciiStrnCmp (GaugeEntryArray[Index].Token, Token, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         AsciiStrnCmp (GaugeEntryArray[Index].Module, Module, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         GaugeEntryArray[Index].EndTimeStamp == 0) {\r
+    Index2 = NumberOfEntries - 1 - Index;\r
+    if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&\r
+        (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
+        AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+        AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+        (GaugeEntryExArray[Index2].Identifier == Identifier)) {\r
+      Index = Index2;\r
       break;\r
     }\r
   }\r
@@ -112,7 +133,7 @@ SmmSearchForGaugeEntry (
   that records the start time of a performance measurement.\r
 \r
   Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, and Module.\r
+  that contains the Handle, Token, Module and Identifier.\r
   The end time of the new record must be set to zero.\r
   If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
   If TimeStamp is zero, the start time in the record is filled in with the value\r
@@ -125,6 +146,8 @@ SmmSearchForGaugeEntry (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
+                                  is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\r
 \r
   @retval EFI_SUCCESS             The data was read correctly from the device.\r
   @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
@@ -132,15 +155,17 @@ SmmSearchForGaugeEntry (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-StartGauge (\r
+StartGaugeEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
   UINTN                     GaugeDataSize;\r
+  GAUGE_DATA_HEADER         *NewGaugeData;\r
   UINTN                     OldGaugeDataSize;\r
   GAUGE_DATA_HEADER         *OldGaugeData;\r
   UINT32                    Index;\r
@@ -153,15 +178,19 @@ StartGauge (
     // Try to enlarge the scale of gauge array.\r
     //\r
     OldGaugeData      = mGaugeData;\r
-    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;\r
 \r
-    mMaxGaugeRecords *= 2;\r
-    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;\r
 \r
-    mGaugeData = AllocateZeroPool (GaugeDataSize);\r
-    if (mGaugeData == NULL) {\r
+    NewGaugeData = AllocateZeroPool (GaugeDataSize);\r
+    if (NewGaugeData == NULL) {\r
+      ReleaseSpinLock (&mSmmPerfLock);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
+    mGaugeData = NewGaugeData;\r
+    mMaxGaugeRecords *= 2;\r
+\r
     //\r
     // Initialize new data array and migrate old data one.\r
     //\r
@@ -170,20 +199,23 @@ StartGauge (
     FreePool (OldGaugeData);\r
   }\r
 \r
-  GaugeEntryArray               = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
-  GaugeEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+  GaugeEntryExArray               = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+  GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
 \r
   if (Token != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, SMM_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (GaugeEntryExArray[Index].Token, SMM_PERFORMANCE_STRING_SIZE, Token, SMM_PERFORMANCE_STRING_LENGTH);\r
   }\r
   if (Module != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, SMM_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (GaugeEntryExArray[Index].Module, SMM_PERFORMANCE_STRING_SIZE, Module, SMM_PERFORMANCE_STRING_LENGTH);\r
   }\r
 \r
+  GaugeEntryExArray[Index].EndTimeStamp = 0;\r
+  GaugeEntryExArray[Index].Identifier = Identifier;\r
+\r
   if (TimeStamp == 0) {\r
     TimeStamp = GetPerformanceCounter ();\r
   }\r
-  GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r
+  GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;\r
 \r
   mGaugeData->NumberOfEntries++;\r
 \r
@@ -197,7 +229,7 @@ StartGauge (
   for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
   Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
   If the record can not be found then return EFI_NOT_FOUND.\r
   If the record is found and TimeStamp is not zero,\r
   then the end time in the record is filled in with the value specified by TimeStamp.\r
@@ -211,6 +243,8 @@ StartGauge (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
+                                  is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.\r
 \r
   @retval EFI_SUCCESS             The end of  the measurement was recorded.\r
   @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
@@ -218,57 +252,65 @@ StartGauge (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-EndGauge (\r
+EndGaugeEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY  *GaugeEntryArray;\r
-  UINT32            Index;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
+  UINT32              Index;\r
+\r
+  AcquireSpinLock (&mSmmPerfLock);\r
 \r
   if (TimeStamp == 0) {\r
     TimeStamp = GetPerformanceCounter ();\r
   }\r
 \r
-  Index = SmmSearchForGaugeEntry (Handle, Token, Module);\r
+  Index = SmmSearchForGaugeEntry (Handle, Token, Module, Identifier);\r
   if (Index >= mGaugeData->NumberOfEntries) {\r
+    ReleaseSpinLock (&mSmmPerfLock);\r
     return EFI_NOT_FOUND;\r
   }\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY  *) (mGaugeData + 1);\r
-  GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+  GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;\r
+\r
+  ReleaseSpinLock (&mSmmPerfLock);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Retrieves a previously logged performance measurement.\r
+  It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r
+  and then assign the Identifier with 0.\r
 \r
   Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
   If it stands for a valid entry, then EFI_SUCCESS is returned and\r
-  GaugeDataEntry stores the pointer to that entry.\r
+  GaugeDataEntryEx stores the pointer to that entry.\r
 \r
   @param  LogEntryKey             The key for the previous performance measurement log entry.\r
                                   If 0, then the first performance measurement log entry is retrieved.\r
-  @param  GaugeDataEntry          The indirect pointer to the gauge data entry specified by LogEntryKey\r
+  @param  GaugeDataEntryEx        The indirect pointer to the extended gauge data entry specified by LogEntryKey\r
                                   if the retrieval is successful.\r
 \r
-  @retval EFI_SUCCESS             The GuageDataEntry is successfully found based on LogEntryKey.\r
+  @retval EFI_SUCCESS             The GuageDataEntryEx is successfully found based on LogEntryKey.\r
   @retval EFI_NOT_FOUND           The LogEntryKey is the last entry (equals to the total entry number).\r
   @retval EFI_INVALIDE_PARAMETER  The LogEntryKey is not a valid entry (greater than the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL.\r
+  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntryEx is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-GetGauge (\r
-  IN  UINTN               LogEntryKey,\r
-  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
+GetGaugeEx (\r
+  IN  UINTN                 LogEntryKey,\r
+  OUT GAUGE_DATA_ENTRY_EX   **GaugeDataEntryEx\r
   )\r
 {\r
   UINTN               NumberOfEntries;\r
-  GAUGE_DATA_ENTRY    *LogEntryArray;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
 \r
   NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
   if (LogEntryKey > NumberOfEntries) {\r
@@ -278,48 +320,252 @@ GetGauge (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  LogEntryArray   = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
 \r
-  if (GaugeDataEntry == NULL) {\r
+  if (GaugeDataEntryEx == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r
+  *GaugeDataEntryEx = &GaugeEntryExArray[LogEntryKey];\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Adds a record at the end of the performance measurement log\r
+  that records the start time of a performance measurement.\r
+\r
+  Adds a record to the end of the performance measurement log\r
+  that contains the Handle, Token, and Module.\r
+  The end time of the new record must be set to zero.\r
+  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+  If TimeStamp is zero, the start time in the record is filled in with the value\r
+  read from the current time stamp.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval EFI_SUCCESS             The data was read correctly from the device.\r
+  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StartGauge (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
 \r
 /**\r
-  This function check if the address is in SMRAM.\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
-  @param Buffer  the buffer address to be checked.\r
-  @param Length  the buffer length to be checked.\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+  If the record can not be found then return EFI_NOT_FOUND.\r
+  If the record is found and TimeStamp is not zero,\r
+  then the end time in the record is filled in with the value specified by TimeStamp.\r
+  If the record is found and TimeStamp is zero, then the end time in the matching record\r
+  is filled in with the current time stamp value.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval EFI_SUCCESS             The end of  the measurement was recorded.\r
+  @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
 \r
-  @retval TRUE  this address is in SMRAM.\r
-  @retval FALSE this address is NOT in SMRAM.\r
 **/\r
-BOOLEAN\r
-IsAddressInSmram (\r
-  IN EFI_PHYSICAL_ADDRESS  Buffer,\r
-  IN UINT64                Length\r
+EFI_STATUS\r
+EFIAPI\r
+EndGauge (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
   )\r
 {\r
-  UINTN  Index;\r
+  return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
 \r
-  for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
-    if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
-        ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
-      return TRUE;\r
-    }\r
+/**\r
+  Retrieves a previously logged performance measurement.\r
+  It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,\r
+  and then eliminate the Identifier.\r
+\r
+  Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
+  If it stands for a valid entry, then EFI_SUCCESS is returned and\r
+  GaugeDataEntry stores the pointer to that entry.\r
+\r
+  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
+                                  If 0, then the first performance measurement log entry is retrieved.\r
+  @param  GaugeDataEntry          The indirect pointer to the gauge data entry specified by LogEntryKey\r
+                                  if the retrieval is successful.\r
+\r
+  @retval EFI_SUCCESS             The GuageDataEntry is successfully found based on LogEntryKey.\r
+  @retval EFI_NOT_FOUND           The LogEntryKey is the last entry (equals to the total entry number).\r
+  @retval EFI_INVALIDE_PARAMETER  The LogEntryKey is not a valid entry (greater than the total entry number).\r
+  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetGauge (\r
+  IN  UINTN               LogEntryKey,\r
+  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  GAUGE_DATA_ENTRY_EX *GaugeEntryEx;\r
+\r
+  GaugeEntryEx = NULL;\r
+\r
+  Status = GetGaugeEx (LogEntryKey, &GaugeEntryEx);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (GaugeDataEntry == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Communication service SMI Handler entry.\r
+\r
+  This SMI handler provides services for the performance wrapper driver.\r
+  \r
+   Caution: This function may receive untrusted input.\r
+   Communicate buffer and buffer size are external input, so this function will do basic validation.\r
+\r
+  @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param[in]     RegisterContext Points to an optional handler context which was specified when the\r
+                                 handler was registered.\r
+  @param[in, out] CommBuffer     A pointer to a collection of data in memory that will\r
+                                 be conveyed from a non-SMM environment into an SMM environment.\r
+  @param[in, out] CommBufferSize The size of the CommBuffer.\r
+\r
+  @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers \r
+                                              should still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED  The interrupt has been quiesced but other handlers should \r
+                                              still be called.\r
+  @retval EFI_WARN_INTERRUPT_SOURCE_PENDING   The interrupt is still pending and other handlers should still \r
+                                              be called.\r
+  @retval EFI_INTERRUPT_PENDING               The interrupt could not be quiesced.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmPerformanceHandlerEx (\r
+  IN     EFI_HANDLE                    DispatchHandle,\r
+  IN     CONST VOID                   *RegisterContext,\r
+  IN OUT VOID                          *CommBuffer,\r
+  IN OUT UINTN                         *CommBufferSize\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  SMM_PERF_COMMUNICATE_EX   *SmmPerfCommData;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
+  UINT64                    DataSize;\r
+  UINTN                     Index;\r
+  GAUGE_DATA_ENTRY_EX       *GaugeDataEx;\r
+  UINTN                     NumberOfEntries;\r
+  UINTN                     LogEntryKey;\r
+  UINTN                     TempCommBufferSize;\r
+\r
+  GaugeEntryExArray = NULL;\r
+\r
+  //\r
+  // If input is invalid, stop processing this SMI\r
+  //\r
+  if (CommBuffer == NULL || CommBufferSize == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  TempCommBufferSize = *CommBufferSize;\r
+\r
+  if(TempCommBufferSize < sizeof (SMM_PERF_COMMUNICATE_EX)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+    DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM communcation data buffer in SMRAM or overflow!\n"));\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  SmmPerfCommData = (SMM_PERF_COMMUNICATE_EX *)CommBuffer;\r
+\r
+  switch (SmmPerfCommData->Function) {\r
+    case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r
+       SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r
+       Status = EFI_SUCCESS;\r
+       break;\r
+\r
+    case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r
+      GaugeDataEx = SmmPerfCommData->GaugeDataEx;\r
+      NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r
+      LogEntryKey = SmmPerfCommData->LogEntryKey;\r
+       if (GaugeDataEx == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r
+           NumberOfEntries > mGaugeData->NumberOfEntries || LogEntryKey > (mGaugeData->NumberOfEntries - NumberOfEntries)) {\r
+         Status = EFI_INVALID_PARAMETER;\r
+         break;\r
+       }\r
+\r
+       //\r
+       // Sanity check\r
+       //\r
+       DataSize = MultU64x32 (NumberOfEntries, sizeof(GAUGE_DATA_ENTRY_EX));\r
+       if (!SmmIsBufferOutsideSmmValid ((UINTN) GaugeDataEx, DataSize)) {\r
+         DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
+         Status = EFI_ACCESS_DENIED;\r
+         break;\r
+       }\r
+\r
+       GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+\r
+       for (Index = 0; Index < NumberOfEntries; Index++) {\r
+         CopyMem (\r
+           (UINT8 *) &GaugeDataEx[Index],\r
+           (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r
+           sizeof (GAUGE_DATA_ENTRY_EX)\r
+           );\r
+       }\r
+       Status = EFI_SUCCESS;\r
+       break;\r
+\r
+    default:\r
+       Status = EFI_UNSUPPORTED;\r
   }\r
 \r
-  return FALSE;\r
+\r
+  SmmPerfCommData->ReturnStatus = Status;\r
+  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Communication service SMI Handler entry.\r
 \r
-  This SMI handler provides services for the variable wrapper driver.\r
+  This SMI handler provides services for the performance wrapper driver.\r
+\r
+  Caution: This function may receive untrusted input.\r
+  Communicate buffer and buffer size are external input, so this function will do basic validation.\r
 \r
   @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
   @param[in]     RegisterContext Points to an optional handler context which was specified when the\r
@@ -341,68 +587,93 @@ EFIAPI
 SmmPerformanceHandler (\r
   IN     EFI_HANDLE                    DispatchHandle,\r
   IN     CONST VOID                   *RegisterContext,\r
-  IN OUT VOID                           *CommBuffer,\r
-  IN OUT UINTN                          *CommBufferSize\r
+  IN OUT VOID                          *CommBuffer,\r
+  IN OUT UINTN                         *CommBufferSize\r
   )\r
 {\r
   EFI_STATUS            Status;\r
   SMM_PERF_COMMUNICATE  *SmmPerfCommData;\r
-  GAUGE_DATA_ENTRY      *GaugeData; \r
-  UINTN                 DataSize;\r
+  GAUGE_DATA_ENTRY_EX   *GaugeEntryExArray;\r
+  UINT64                DataSize;\r
+  UINTN                 Index;\r
+  GAUGE_DATA_ENTRY      *GaugeData;\r
+  UINTN                 NumberOfEntries;\r
+  UINTN                 LogEntryKey;\r
+  UINTN                 TempCommBufferSize;\r
 \r
-  GaugeData = NULL;\r
-  \r
-  ASSERT (CommBuffer != NULL);\r
+  GaugeEntryExArray = NULL;\r
+\r
+  //\r
+  // If input is invalid, stop processing this SMI\r
+  //\r
+  if (CommBuffer == NULL || CommBufferSize == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  TempCommBufferSize = *CommBufferSize;\r
+\r
+  if(TempCommBufferSize < sizeof (SMM_PERF_COMMUNICATE)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+    DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM communcation data buffer in SMRAM or overflow!\n"));\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
-  SmmPerfCommData = (SMM_PERF_COMMUNICATE*)CommBuffer;\r
+  SmmPerfCommData = (SMM_PERF_COMMUNICATE *)CommBuffer;\r
 \r
   switch (SmmPerfCommData->Function) {\r
     case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r
        SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r
-       return Status = EFI_SUCCESS;\r
+       Status = EFI_SUCCESS;\r
        break;\r
 \r
     case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r
-       if ( SmmPerfCommData->GaugeData == NULL || SmmPerfCommData->NumberOfEntries <= 0 ||\r
-            (SmmPerfCommData->LogEntryKey + SmmPerfCommData->NumberOfEntries) > mGaugeData->NumberOfEntries) {\r
+       GaugeData = SmmPerfCommData->GaugeData;\r
+       NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r
+       LogEntryKey = SmmPerfCommData->LogEntryKey;\r
+       if (GaugeData == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r
+           NumberOfEntries > mGaugeData->NumberOfEntries || LogEntryKey > (mGaugeData->NumberOfEntries - NumberOfEntries)) {\r
          Status = EFI_INVALID_PARAMETER;\r
          break;\r
-       } \r
-\r
-       Status = GetGauge(SmmPerfCommData->LogEntryKey, &GaugeData);\r
-       if (EFI_ERROR(Status)) {\r
-         break;\r
        }\r
-          \r
+\r
        //\r
        // Sanity check\r
        //\r
-       DataSize = SmmPerfCommData->NumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r
-       if (IsAddressInSmram ((EFI_PHYSICAL_ADDRESS)(UINTN)SmmPerfCommData->GaugeData, DataSize)) {\r
-         DEBUG ((EFI_D_ERROR, "Smm Performance Data buffer is in SMRAM!\n"));\r
+       DataSize = MultU64x32 (NumberOfEntries, sizeof(GAUGE_DATA_ENTRY));\r
+       if (!SmmIsBufferOutsideSmmValid ((UINTN) GaugeData, DataSize)) {\r
+         DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
          Status = EFI_ACCESS_DENIED;\r
-         break ;\r
+         break;\r
        }\r
 \r
-       CopyMem(\r
-         (UINT8*)SmmPerfCommData->GaugeData, \r
-         (UINT8*)GaugeData, \r
-         DataSize\r
-         );\r
+       GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
+\r
+       for (Index = 0; Index < NumberOfEntries; Index++) {\r
+         CopyMem (\r
+           (UINT8 *) &GaugeData[Index],\r
+           (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r
+           sizeof (GAUGE_DATA_ENTRY)\r
+           );\r
+       }\r
+       Status = EFI_SUCCESS;\r
        break;\r
 \r
     default:\r
-       ASSERT (FALSE);\r
        Status = EFI_UNSUPPORTED;\r
-  }            \r
+  }\r
+\r
 \r
   SmmPerfCommData->ReturnStatus = Status;\r
+  \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   SmmBase2 protocol notify callback function, when SMST and SMM memory service get initialized \r
-  this function is callbacked to to initialize the Smm Performance Lib \r
+  this function is callbacked to initialize the Smm Performance Lib \r
 \r
   @param  Event    The event of notify protocol.\r
   @param  Context  Notify event context.\r
@@ -417,42 +688,17 @@ InitializeSmmCorePerformanceLib (
 {\r
   EFI_STATUS                Status;\r
   EFI_HANDLE                Handle;\r
-  EFI_SMM_ACCESS2_PROTOCOL  *SmmAccess;\r
-  UINTN                     Size;\r
-\r
 \r
   //\r
   // Initialize spin lock\r
   //\r
   InitializeSpinLock (&mSmmPerfLock);\r
 \r
-  mMaxGaugeRecords = INIT_SMM_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
+  mMaxGaugeRecords = INIT_SMM_GAUGE_DATA_ENTRIES;\r
 \r
-  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
+  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r
   ASSERT (mGaugeData != NULL);\r
   \r
-  //\r
-  // Get SMRAM information\r
-  //\r
-  Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Size = 0;\r
-  Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
-  ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
-  Status = gSmst->SmmAllocatePool (\r
-                    EfiRuntimeServicesData,\r
-                    Size,\r
-                    (VOID **)&mSmramRanges\r
-                    );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-\r
   //\r
   // Install the protocol interfaces.\r
   //\r
@@ -464,19 +710,27 @@ InitializeSmmCorePerformanceLib (
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gSmst->SmmInstallProtocolInterface (\r
+                    &mHandle,\r
+                    &gSmmPerformanceExProtocolGuid,\r
+                    EFI_NATIVE_INTERFACE,\r
+                    &mPerformanceExInterface\r
+                    );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   ///\r
   /// Register SMM Performance SMI handler\r
   ///\r
   Handle = NULL;\r
   Status = gSmst->SmiHandlerRegister (SmmPerformanceHandler, &gSmmPerformanceProtocolGuid, &Handle);\r
   ASSERT_EFI_ERROR (Status);\r
+  Status = gSmst->SmiHandlerRegister (SmmPerformanceHandlerEx, &gSmmPerformanceExProtocolGuid, &Handle);\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 /**\r
-  The constructor function initializes Performance infrastructure for DXE phase.\r
-\r
-  The constructor function publishes Performance protocol, allocates memory to log DXE performance\r
-  and merges PEI performance data to DXE performance log.\r
+  The constructor function initializes the Performance Measurement Enable flag and \r
+  registers SmmBase2 protocol notify callback.\r
   It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
 \r
   @param  ImageHandle   The firmware allocated handle for the EFI image.\r
@@ -535,7 +789,7 @@ SmmCorePerformanceLibConstructor (
   that records the start time of a performance measurement.\r
 \r
   Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, and Module.\r
+  that contains the Handle, Token, Module and Identifier.\r
   The end time of the new record must be set to zero.\r
   If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
   If TimeStamp is zero, the start time in the record is filled in with the value\r
@@ -548,6 +802,8 @@ SmmCorePerformanceLibConstructor (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
+                                  is same as the one created by StartPerformanceMeasurement.\r
 \r
   @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
   @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
@@ -555,17 +811,15 @@ SmmCorePerformanceLibConstructor (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-StartPerformanceMeasurement (\r
+StartPerformanceMeasurementEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = StartGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
@@ -573,7 +827,7 @@ StartPerformanceMeasurement (
   for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
   Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
   If the record can not be found then return RETURN_NOT_FOUND.\r
   If the record is found and TimeStamp is not zero,\r
   then the end time in the record is filled in with the value specified by TimeStamp.\r
@@ -587,6 +841,8 @@ StartPerformanceMeasurement (
   @param  Module                  Pointer to a Null-terminated ASCII string\r
                                   that identifies the module being measured.\r
   @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
+                                  is same as the one found by EndPerformanceMeasurement.\r
 \r
   @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
   @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
@@ -594,21 +850,21 @@ StartPerformanceMeasurement (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-EndPerformanceMeasurement (\r
+EndPerformanceMeasurementEx (\r
   IN CONST VOID   *Handle,  OPTIONAL\r
   IN CONST CHAR8  *Token,   OPTIONAL\r
   IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EndGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
 }\r
 \r
 /**\r
   Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
+  and then assign the Identifier with 0.\r
 \r
   Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
   zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
@@ -619,13 +875,14 @@ EndPerformanceMeasurement (
   retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
   log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
   is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
-  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
   If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
   If Handle is NULL, then ASSERT().\r
   If Token is NULL, then ASSERT().\r
   If Module is NULL, then ASSERT().\r
   If StartTimeStamp is NULL, then ASSERT().\r
   If EndTimeStamp is NULL, then ASSERT().\r
+  If Identifier is NULL, then ASSERT().\r
 \r
   @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
                                   0, then the first performance measurement log entry is retrieved.\r
@@ -640,23 +897,25 @@ EndPerformanceMeasurement (
                                   was started.\r
   @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
                                   was ended.\r
+  @param  Identifier              Pointer to the 32-bit identifier that was recorded.\r
 \r
   @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
-GetPerformanceMeasurement (\r
-  IN  UINTN       LogEntryKey,\r
+GetPerformanceMeasurementEx (\r
+  IN  UINTN       LogEntryKey, \r
   OUT CONST VOID  **Handle,\r
   OUT CONST CHAR8 **Token,\r
   OUT CONST CHAR8 **Module,\r
   OUT UINT64      *StartTimeStamp,\r
-  OUT UINT64      *EndTimeStamp\r
+  OUT UINT64      *EndTimeStamp,\r
+  OUT UINT32      *Identifier\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  GAUGE_DATA_ENTRY  *GaugeData;\r
+  EFI_STATUS           Status;\r
+  GAUGE_DATA_ENTRY_EX  *GaugeData;\r
 \r
   GaugeData = NULL;\r
   \r
@@ -665,8 +924,9 @@ GetPerformanceMeasurement (
   ASSERT (Module != NULL);\r
   ASSERT (StartTimeStamp != NULL);\r
   ASSERT (EndTimeStamp != NULL);\r
+  ASSERT (Identifier != NULL);\r
 \r
-  Status = GetGauge (LogEntryKey++, &GaugeData);\r
+  Status = GetGaugeEx (LogEntryKey++, &GaugeData);\r
 \r
   //\r
   // Make sure that LogEntryKey is a valid log entry key,\r
@@ -687,10 +947,136 @@ GetPerformanceMeasurement (
   *Module         = GaugeData->Module;\r
   *StartTimeStamp = GaugeData->StartTimeStamp;\r
   *EndTimeStamp   = GaugeData->EndTimeStamp;\r
+  *Identifier     = GaugeData->Identifier;\r
 \r
   return LogEntryKey;\r
 }\r
 \r
+/**\r
+  Adds a record at the end of the performance measurement log\r
+  that records the start time of a performance measurement.\r
+\r
+  Adds a record to the end of the performance measurement log\r
+  that contains the Handle, Token, and Module.\r
+  The end time of the new record must be set to zero.\r
+  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+  If TimeStamp is zero, the start time in the record is filled in with the value\r
+  read from the current time stamp.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
+  @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StartPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
+\r
+/**\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first matching record that contains a zero end time and fills in a valid end time.\r
+\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+  If the record can not be found then return RETURN_NOT_FOUND.\r
+  If the record is found and TimeStamp is not zero,\r
+  then the end time in the record is filled in with the value specified by TimeStamp.\r
+  If the record is found and TimeStamp is zero, then the end time in the matching record\r
+  is filled in with the current time stamp value.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+\r
+  @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
+  @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+EndPerformanceMeasurement (\r
+  IN CONST VOID   *Handle,  OPTIONAL\r
+  IN CONST CHAR8  *Token,   OPTIONAL\r
+  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN UINT64       TimeStamp\r
+  )\r
+{\r
+  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
+\r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
+  and then eliminate the Identifier.\r
+\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance log entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetPerformanceMeasurement (\r
+  IN  UINTN       LogEntryKey,\r
+  OUT CONST VOID  **Handle,\r
+  OUT CONST CHAR8 **Token,\r
+  OUT CONST CHAR8 **Module,\r
+  OUT UINT64      *StartTimeStamp,\r
+  OUT UINT64      *EndTimeStamp\r
+  )\r
+{\r
+  UINT32 Identifier;\r
+  return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
+}\r
+\r
 /**\r
   Returns TRUE if the performance measurement macros are enabled.\r
 \r
@@ -711,5 +1097,3 @@ PerformanceMeasurementEnabled (
 {\r
   return mPerformanceMeasurementEnabled;\r
 }\r
-\r
-\r