]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/Dp.c
PerformancePkg/Dp_App: Add check to avoid NULL pointer deference
[mirror_edk2.git] / PerformancePkg / Dp_App / Dp.c
index 283b61ccd4e07c52f44275bfc1c06234849af1ab..4cdc39edb42e75ccf0221839550df5fa9fab0f2b 100644 (file)
@@ -13,7 +13,7 @@
   Dp uses this information to group records in different ways.  It also uses\r
   timer information to calculate elapsed time for each measurement.\r
  \r
   Dp uses this information to group records in different ways.  It also uses\r
   timer information to calculate elapsed time for each measurement.\r
  \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -30,7 +30,6 @@
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/UefiHiiServicesLib.h>\r
 #include <Library/HiiLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/UefiHiiServicesLib.h>\r
 #include <Library/HiiLib.h>\r
@@ -114,7 +113,7 @@ InitialShellParamList( void )
   //\r
   // Allocate one more for the end tag.\r
   //\r
   //\r
   // Allocate one more for the end tag.\r
   //\r
-  ListLength = sizeof (ParamList) / sizeof (ParamList[0]) + 1;  \r
+  ListLength = ARRAY_SIZE (ParamList) + 1;  \r
   DpParamList = AllocatePool (sizeof (SHELL_PARAM_ITEM) * ListLength);\r
   ASSERT (DpParamList != NULL);\r
   \r
   DpParamList = AllocatePool (sizeof (SHELL_PARAM_ITEM) * ListLength);\r
   ASSERT (DpParamList != NULL);\r
   \r
@@ -183,25 +182,6 @@ DumpStatistics( void )
   FreePool (StringPtrUnknown);\r
 }\r
 \r
   FreePool (StringPtrUnknown);\r
 }\r
 \r
-/**\r
-  Initialize the cumulative data.\r
-\r
-**/\r
-VOID\r
-InitCumulativeData (\r
-  VOID\r
-  )\r
-{\r
-  UINTN                             Index;\r
-\r
-  for (Index = 0; Index < NumCum; ++Index) {\r
-    CumData[Index].Count = 0;\r
-    CumData[Index].MinDur = PERF_MAXDUR;\r
-    CumData[Index].MaxDur = 0;\r
-    CumData[Index].Duration = 0;\r
-  }\r
-}\r
-\r
 /**\r
   Dump performance data.\r
   \r
 /**\r
   Dump performance data.\r
   \r
@@ -220,14 +200,13 @@ InitializeDp (
   IN EFI_SYSTEM_TABLE         *SystemTable\r
   )\r
 {\r
   IN EFI_SYSTEM_TABLE         *SystemTable\r
   )\r
 {\r
-  UINT64                    Freq;\r
-  UINT64                    Ticker;\r
-  UINT32                    ListIndex;\r
-  \r
-  LIST_ENTRY                *ParamPackage;\r
-  CONST CHAR16              *CmdLineArg;\r
-  EFI_STRING                StringPtr;\r
-  UINTN                     Number2Display;\r
+  PERFORMANCE_PROPERTY          *PerformanceProperty;\r
+  UINT32                        ListIndex;\r
+\r
+  LIST_ENTRY                    *ParamPackage;\r
+  CONST CHAR16                  *CmdLineArg;\r
+  EFI_STRING                    StringPtr;\r
+  UINTN                         Number2Display;\r
 \r
   EFI_STATUS                    Status;\r
   BOOLEAN                       SummaryMode;\r
 \r
   EFI_STATUS                    Status;\r
   BOOLEAN                       SummaryMode;\r
@@ -240,6 +219,7 @@ InitializeDp (
   BOOLEAN                       CumulativeMode;\r
   CONST CHAR16                  *CustomCumulativeToken;\r
   PERF_CUM_DATA                 *CustomCumulativeData;\r
   BOOLEAN                       CumulativeMode;\r
   CONST CHAR16                  *CustomCumulativeToken;\r
   PERF_CUM_DATA                 *CustomCumulativeData;\r
+  UINTN                         NameSize;\r
   EFI_HII_PACKAGE_LIST_HEADER   *PackageList;\r
 \r
   EFI_STRING                StringDpOptionQh;\r
   EFI_HII_PACKAGE_LIST_HEADER   *PackageList;\r
 \r
   EFI_STRING                StringDpOptionQh;\r
@@ -285,11 +265,6 @@ InitializeDp (
   StringDpOptionLc = NULL;\r
   StringPtr        = NULL;\r
 \r
   StringDpOptionLc = NULL;\r
   StringPtr        = NULL;\r
 \r
-  // Get DP's entry time as soon as possible.\r
-  // This is used as the Shell-Phase end time.\r
-  //\r
-  Ticker  = GetPerformanceCounter ();\r
-\r
   //\r
   // Retrieve HII package list from ImageHandle\r
   //\r
   //\r
   // Retrieve HII package list from ImageHandle\r
   //\r
@@ -411,8 +386,9 @@ InitializeDp (
     CustomCumulativeData->MaxDur = 0;\r
     CustomCumulativeData->Count  = 0;\r
     CustomCumulativeData->Duration = 0;\r
     CustomCumulativeData->MaxDur = 0;\r
     CustomCumulativeData->Count  = 0;\r
     CustomCumulativeData->Duration = 0;\r
-    CustomCumulativeData->Name   = AllocateZeroPool (StrLen (CustomCumulativeToken) + 1);\r
-    UnicodeStrToAsciiStr (CustomCumulativeToken, CustomCumulativeData->Name);\r
+    NameSize = StrLen (CustomCumulativeToken) + 1;\r
+    CustomCumulativeData->Name   = AllocateZeroPool (NameSize);\r
+    UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize);\r
   }\r
 \r
 /****************************************************************************\r
   }\r
 \r
 /****************************************************************************\r
@@ -423,10 +399,16 @@ InitializeDp (
       //    StartCount = Value loaded into the counter when it starts counting\r
       //      EndCount = Value counter counts to before it needs to be reset\r
       //\r
       //    StartCount = Value loaded into the counter when it starts counting\r
       //      EndCount = Value counter counts to before it needs to be reset\r
       //\r
-      Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r
+      Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
+      if (EFI_ERROR (Status) || (PerformanceProperty == NULL)) {\r
+        PrintToken (STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND));\r
+        goto Done;\r
+      }\r
 \r
       // Convert the Frequency from Hz to KHz\r
 \r
       // Convert the Frequency from Hz to KHz\r
-      TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r
+      TimerInfo.Frequency  = (UINT32)DivU64x32 (PerformanceProperty->Frequency, 1000);\r
+      TimerInfo.StartCount = PerformanceProperty->TimerStartValue;\r
+      TimerInfo.EndCount   = PerformanceProperty->TimerEndValue;\r
 \r
       // Determine in which direction the performance counter counts.\r
       TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
 \r
       // Determine in which direction the performance counter counts.\r
       TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
@@ -504,7 +486,7 @@ InitializeDp (
       else {\r
         //------------- Begin Cooked Mode Processing\r
         if (TraceMode) {\r
       else {\r
         //------------- Begin Cooked Mode Processing\r
         if (TraceMode) {\r
-          ProcessPhases ( Ticker );\r
+          ProcessPhases ();\r
           if ( ! SummaryMode) {\r
             Status = ProcessHandles ( ExcludeMode);\r
             if (Status == EFI_ABORTED) {\r
           if ( ! SummaryMode) {\r
             Status = ProcessHandles ( ExcludeMode);\r
             if (Status == EFI_ABORTED) {\r