X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FMem%2FMemoryProfileRecord.c;h=ff1940431c2f7f429245021fa1ce4445d557c64e;hp=1ba8488a0e041761c67e3fa5e25cc74684106c01;hb=05cfd73f011f67541cf4add560ab213daa8a99ed;hpb=1d60fe96422206d37e1d74198bb11b2cf6195157 diff --git a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c index 1ba8488a0e..ff1940431c 100644 --- a/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c +++ b/MdeModulePkg/Core/Dxe/Mem/MemoryProfileRecord.c @@ -1,7 +1,7 @@ /** @file Support routines for UEFI memory profile. - Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -63,10 +63,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA mMemoryProfileContext }; GLOBAL_REMOVE_IF_UNREFERENCED MEMORY_PROFILE_CONTEXT_DATA *mMemoryProfileContextPtr = NULL; -BOOLEAN mMemoryProfileGettingStatus = FALSE; -BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE; -EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath; -UINTN mMemoryProfileDriverPathSize; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_LOCK mMemoryProfileLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY); +GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileGettingStatus = FALSE; +GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mMemoryProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_PROTOCOL *mMemoryProfileDriverPath; +GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMemoryProfileDriverPathSize; /** Get memory profile data. @@ -75,10 +76,10 @@ UINTN mMemoryProfileDriverPathSize; @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer. On return, points to the size of the data returned in ProfileBuffer. @param[out] ProfileBuffer Profile buffer. - + @return EFI_SUCCESS Get the memory profile data successfully. @return EFI_UNSUPPORTED Memory profile is unsupported. - @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. + @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. ProfileSize is updated with the size required. **/ @@ -208,7 +209,7 @@ ProfileProtocolRecord ( IN CHAR8 *ActionString OPTIONAL ); -EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = { +GLOBAL_REMOVE_IF_UNREFERENCED EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = { ProfileProtocolGetData, ProfileProtocolRegisterImage, ProfileProtocolUnregisterImage, @@ -218,46 +219,39 @@ EDKII_MEMORY_PROFILE_PROTOCOL mProfileProtocol = { }; /** - Return memory profile context. - - @return Memory profile context. - + Acquire lock on mMemoryProfileLock. **/ -MEMORY_PROFILE_CONTEXT_DATA * -GetMemoryProfileContext ( +VOID +CoreAcquireMemoryProfileLock ( VOID ) { - return mMemoryProfileContextPtr; + CoreAcquireLock (&mMemoryProfileLock); } /** - Retrieves the magic value from the PE/COFF header. + Release lock on mMemoryProfileLock. +**/ +VOID +CoreReleaseMemoryProfileLock ( + VOID + ) +{ + CoreReleaseLock (&mMemoryProfileLock); +} - @param Hdr The buffer in which to return the PE32, PE32+, or TE header. +/** + Return memory profile context. - @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 - @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ + @return Memory profile context. **/ -UINT16 -InternalPeCoffGetPeHeaderMagicValue ( - IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr +MEMORY_PROFILE_CONTEXT_DATA * +GetMemoryProfileContext ( + VOID ) { - // - // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value - // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the - // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - // - if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; - } - // - // Return the magic value from the PC/COFF Optional Header - // - return Hdr.Pe32->OptionalHeader.Magic; + return mMemoryProfileContextPtr; } /** @@ -296,7 +290,7 @@ InternalPeCoffGetSubsystem ( if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { return Hdr.Te->Subsystem; } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { - Magic = InternalPeCoffGetPeHeaderMagicValue (Hdr); + Magic = Hdr.Pe32->OptionalHeader.Magic; if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { return Hdr.Pe32->OptionalHeader.Subsystem; } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { @@ -419,6 +413,7 @@ BuildDriverInfo ( if (EFI_ERROR (Status)) { return NULL; } + ASSERT (DriverInfoData != NULL); ZeroMem (DriverInfoData, sizeof (*DriverInfoData)); @@ -490,7 +485,7 @@ NeedRecordThisDriver ( // return TRUE; } - + // // Record FilePath without END node. // @@ -1260,6 +1255,9 @@ CoreUpdateProfileFree ( } } + ASSERT (DriverInfoData != NULL); + ASSERT (AllocInfoData != NULL); + Found = TRUE; Context = &ContextData->Context; @@ -1383,6 +1381,7 @@ CoreUpdateProfile ( return EFI_UNSUPPORTED; } + CoreAcquireMemoryProfileLock (); switch (BasicAction) { case MemoryProfileActionAllocatePages: Status = CoreUpdateProfileAllocate (CallerAddress, Action, MemoryType, Size, Buffer, ActionString); @@ -1401,6 +1400,8 @@ CoreUpdateProfile ( Status = EFI_UNSUPPORTED; break; } + CoreReleaseMemoryProfileLock (); + return Status; } @@ -1542,10 +1543,10 @@ MemoryProfileCopyData ( @param[in, out] ProfileSize On entry, points to the size in bytes of the ProfileBuffer. On return, points to the size of the data returned in ProfileBuffer. @param[out] ProfileBuffer Profile buffer. - + @return EFI_SUCCESS Get the memory profile data successfully. @return EFI_UNSUPPORTED Memory profile is unsupported. - @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. + @return EFI_BUFFER_TO_SMALL The ProfileSize is too small for the resulting data. ProfileSize is updated with the size required. **/