]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / MemoryProfileRecord.c
index 14c4959f9fe220857cf7640be6e0ab0fc18ef275..2ca0417b070065a2379462ff19eb66e691159225 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Support routines for UEFI memory profile.\r
 \r
-  Copyright (c) 2014 - 2016, 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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -63,11 +57,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext
 };\r
 GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL;\r
 \r
-EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);\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
@@ -76,10 +70,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
@@ -209,7 +203,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
@@ -254,35 +248,6 @@ GetMemoryProfileContext (
   return mMemoryProfileContextPtr;\r
 }\r
 \r
-/**\r
-  Retrieves the magic value from the PE/COFF header.\r
-\r
-  @param Hdr    The buffer in which to return the PE32, PE32+, or TE header.\r
-\r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
-  @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
-\r
-**/\r
-UINT16\r
-InternalPeCoffGetPeHeaderMagicValue (\r
-  IN  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr\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
-}\r
-\r
 /**\r
   Retrieves and returns the Subsystem of a PE/COFF image that has been loaded into system memory.\r
   If Pe32Data is NULL, then ASSERT().\r
@@ -319,7 +284,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
@@ -442,6 +407,7 @@ BuildDriverInfo (
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
+  ASSERT (DriverInfoData != NULL);\r
 \r
   ZeroMem (DriverInfoData, sizeof (*DriverInfoData));\r
 \r
@@ -513,7 +479,7 @@ NeedRecordThisDriver (
     //\r
     return TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Record FilePath without END node.\r
   //\r
@@ -1283,6 +1249,9 @@ CoreUpdateProfileFree (
       }\r
     }\r
 \r
+    ASSERT (DriverInfoData != NULL);\r
+    ASSERT (AllocInfoData != NULL);\r
+\r
     Found = TRUE;\r
 \r
     Context = &ContextData->Context;\r
@@ -1568,10 +1537,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