1. Bug fix for "EDK GenericBds WriteBootToOsPerformanceData() uses AcpiReclaimMemory";
[mirror_edk2.git] / EdkNt32Pkg / Library / EdkGenericBdsLib / Performance.c
index 320d6b7c44fe59540789205b72508ce17bbe49ac..80b98563f067bba215341e813da49b31d6c02ce0 100644 (file)
@@ -28,6 +28,9 @@ ClearDebugRegisters (
   VOID\r
   )\r
 {\r
+  //\r
+  // BugBug: We should not need to do this. We need to root cause this bug!!!!\r
+  //\r
   AsmWriteDr0 (0);\r
   AsmWriteDr1 (0);\r
 }\r
@@ -85,6 +88,8 @@ Returns:
   return ;\r
 }\r
 \r
+\r
+\r
 STATIC\r
 CHAR8 *\r
 GetPdbPath (\r
@@ -107,51 +112,18 @@ Returns:
 \r
 --*/\r
 {\r
-  CHAR8                           *PdbPath;\r
-  UINT32                          DirCount;\r
-  EFI_IMAGE_DOS_HEADER            *DosHdr;\r
-  EFI_IMAGE_NT_HEADERS            *NtHdr;\r
-  EFI_IMAGE_OPTIONAL_HEADER       *OptionalHdr;\r
-  EFI_IMAGE_DATA_DIRECTORY        *DirectoryEntry;\r
-  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
-  VOID                            *CodeViewEntryPointer;\r
-\r
-  CodeViewEntryPointer  = NULL;\r
-  PdbPath               = NULL;\r
-  DosHdr                = ImageBase;\r
-\r
-  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-    NtHdr           = (EFI_IMAGE_NT_HEADERS *) ((UINT8 *) DosHdr + DosHdr->e_lfanew);\r
-    OptionalHdr     = (VOID *) &NtHdr->OptionalHeader;\r
-    DirectoryEntry  = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-    if (DirectoryEntry->VirtualAddress != 0) {\r
-      for (DirCount = 0;\r
-           (DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && CodeViewEntryPointer == NULL;\r
-           DirCount++\r
-          ) {\r
-        DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (DirectoryEntry->VirtualAddress + (UINTN) ImageBase + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\r
-        if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
-          CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageBase);\r
-          switch (*(UINT32 *) CodeViewEntryPointer) {\r
-          case CODEVIEW_SIGNATURE_NB10:\r
-            PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);\r
-            break;\r
-\r
-          case CODEVIEW_SIGNATURE_RSDS:\r
-            PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
-            break;\r
-\r
-          default:\r
-            break;\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
+\r
+  ZeroMem (&ImageContext, sizeof (ImageContext));\r
+  ImageContext.Handle    = ImageBase;\r
+  ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;\r
 \r
-  return PdbPath;\r
+  PeCoffLoaderGetImageInfo (&ImageContext);\r
+\r
+  return ImageContext.PdbPointer;\r
 }\r
 \r
+\r
 STATIC\r
 VOID\r
 GetNameFromHandle (\r
@@ -260,9 +232,10 @@ Returns:
   //\r
   // Allocate a block of memory that contain performance data to OS\r
   //\r
+  mAcpiLowMemoryBase = 0xFFFFFFFF;\r
   Status = gBS->AllocatePages (\r
-                  AllocateAnyPages,\r
-                  EfiACPIReclaimMemory,\r
+                  AllocateMaxAddress,\r
+                  EfiReservedMemoryType,\r
                   4,\r
                   &mAcpiLowMemoryBase\r
                   );\r
@@ -270,7 +243,7 @@ Returns:
     return ;\r
   }\r
 \r
-  mAcpiLowMemoryLength  = 0x1000;\r
+  mAcpiLowMemoryLength  = EFI_PAGES_TO_SIZE(4);\r
 \r
   Ptr                   = (UINT8 *) ((UINT32) mAcpiLowMemoryBase + sizeof (PERF_HEADER));\r
   LimitCount            = (mAcpiLowMemoryLength - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);\r
@@ -289,7 +262,7 @@ Returns:
                   &Cpu\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePages (mAcpiLowMemoryBase, 1);\r
+    gBS->FreePages (mAcpiLowMemoryBase, 4);\r
     return ;\r
   }\r
   //\r
@@ -297,7 +270,7 @@ Returns:
   //\r
   Status = Cpu->GetTimerValue (Cpu, 0, &(CurrentTicker), &TimerPeriod);\r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePages (mAcpiLowMemoryBase, 1);\r
+    gBS->FreePages (mAcpiLowMemoryBase, 4);\r
     return ;\r
   }\r
 \r
@@ -322,7 +295,7 @@ Returns:
                   &Handles\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePages (mAcpiLowMemoryBase, 1);\r
+    gBS->FreePages (mAcpiLowMemoryBase, 4);\r
     return ;\r
   }\r
   //\r