]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
MdeModulePkg: remove PE/COFF header workaround for ELILO on IPF
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / MemoryProfileRecord.c
index 1ba8488a0e041761c67e3fa5e25cc74684106c01..ff1940431c2f7f429245021fa1ce4445d557c64e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for UEFI memory profile.\r
 \r
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2018, 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
@@ -63,10 +63,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext
 };\r
 GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;\r
 \r
-BOOLEAN mMemoryProfileGettingStatus = FALSE;\r
-BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
-EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;\r
-UINTN                    mMemoryProfileDriverPathSize;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath;\r
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN                    mMemoryProfileDriverPathSize;\r
 \r
 /**\r
   Get memory profile data.\r
@@ -75,10 +76,10 @@ UINTN                    mMemoryProfileDriverPathSize;
   @param[in, out] ProfileSize       On entry, points to the size in bytes of the ProfileBuffer.\r
                                     On return, points to the size of the data returned in ProfileBuffer.\r
   @param[out]     ProfileBuffer     Profile buffer.\r
-                      \r
+\r
   @return EFI_SUCCESS               Get the memory profile data successfully.\r
   @return EFI_UNSUPPORTED           Memory profile is unsupported.\r
-  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data. \r
+  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data.\r
                                     ProfileSize is updated with the size required.\r
 \r
 **/\r
@@ -208,7 +209,7 @@ ProfileProtocolRecord (
   IN CHAR8                              *ActionString OPTIONAL\r
   );\r
 \r
-EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {\r
   ProfileProtocolGetData,\r
   ProfileProtocolRegisterImage,\r
   ProfileProtocolUnregisterImage,\r
@@ -218,46 +219,39 @@ EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = {
 };\r
 \r
 /**\r
-  Return memory profile context.\r
-\r
-  @return Memory profile context.\r
-\r
+  Acquire lock on mMemoryProfileLock.\r
 **/\r
-MEMORY_PROFILE_CONTEXT_DATA *\r
-GetMemoryProfileContext (\r
+VOID\r
+CoreAcquireMemoryProfileLock (\r
   VOID\r
   )\r
 {\r
-  return mMemoryProfileContextPtr;\r
+  CoreAcquireLock (&mMemoryProfileLock);\r
 }\r
 \r
 /**\r
-  Retrieves the magic value from the PE/COFF header.\r
+  Release lock on mMemoryProfileLock.\r
+**/\r
+VOID\r
+CoreReleaseMemoryProfileLock (\r
+  VOID\r
+  )\r
+{\r
+  CoreReleaseLock (&mMemoryProfileLock);\r
+}\r
 \r
-  @param Hdr    The buffer in which to return the PE32, PE32+, or TE header.\r
+/**\r
+  Return memory profile context.\r
 \r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
+  @return Memory profile context.\r
 \r
 **/\r
-UINT16\r
-InternalPeCoffGetPeHeaderMagicValue (\r
-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr\r
+MEMORY_PROFILE_CONTEXT_DATA *\r
+GetMemoryProfileContext (\r
+  VOID\r
   )\r
 {\r
-  //\r
-  // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value\r
-  //       in the PE/COFF Header.  If the MachineType is Itanium(IA64) and the\r
-  //       Magic value in the OptionalHeader is  EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
-  //       then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
-  //\r
-  if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-    return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
-  }\r
-  //\r
-  // Return the magic value from the PC/COFF Optional Header\r
-  //\r
-  return Hdr.Pe32->OptionalHeader.Magic;\r
+  return mMemoryProfileContextPtr;\r
 }\r
 \r
 /**\r
@@ -296,7 +290,7 @@ InternalPeCoffGetSubsystem (
   if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
     return Hdr.Te->Subsystem;\r
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
-    Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr);\r
+    Magic = Hdr.Pe32->OptionalHeader.Magic;\r
     if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       return Hdr.Pe32->OptionalHeader.Subsystem;\r
     } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
@@ -419,6 +413,7 @@ BuildDriverInfo (
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
+  ASSERT (DriverInfoData != NULL);\r
 \r
   ZeroMem (DriverInfoData, sizeof (*DriverInfoData));\r
 \r
@@ -490,7 +485,7 @@ NeedRecordThisDriver (
     //\r
     return TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Record FilePath without END node.\r
   //\r
@@ -1260,6 +1255,9 @@ CoreUpdateProfileFree (
       }\r
     }\r
 \r
+    ASSERT (DriverInfoData != NULL);\r
+    ASSERT (AllocInfoData != NULL);\r
+\r
     Found = TRUE;\r
 \r
     Context = &ContextData->Context;\r
@@ -1383,6 +1381,7 @@ CoreUpdateProfile (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  CoreAcquireMemoryProfileLock ();\r
   switch (BasicAction) {\r
     case MemoryProfileActionAllocatePages:\r
       Status = CoreUpdateProfileAllocate (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);\r
@@ -1401,6 +1400,8 @@ CoreUpdateProfile (
       Status = EFI_UNSUPPORTED;\r
       break;\r
   }\r
+  CoreReleaseMemoryProfileLock ();\r
+\r
   return Status;\r
 }\r
 \r
@@ -1542,10 +1543,10 @@ MemoryProfileCopyData (
   @param[in, out] ProfileSize       On entry, points to the size in bytes of the ProfileBuffer.\r
                                     On return, points to the size of the data returned in ProfileBuffer.\r
   @param[out]     ProfileBuffer     Profile buffer.\r
-                      \r
+\r
   @return EFI_SUCCESS               Get the memory profile data successfully.\r
   @return EFI_UNSUPPORTED           Memory profile is unsupported.\r
-  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data. \r
+  @return EFI_BUFFER_TO_SMALL       The ProfileSize is too small for the resulting data.\r
                                     ProfileSize is updated with the size required.\r
 \r
 **/\r