]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c
Use SmmMemLib to check communication buffer.
[mirror_edk2.git] / MdeModulePkg / Core / PiSmmCore / SmramProfileRecord.c
index 24ab1b1de4ed3903d65645c097e86439e43cc632..a78442901bafa80d036c58ce4a9fb0f3bc49dbbd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for SMRAM profile.\r
 \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2015, 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
@@ -824,6 +824,8 @@ SmmCoreUpdateProfileAllocate (
   MEMORY_PROFILE_ALLOC_INFO_DATA    *AllocInfoData;\r
   EFI_MEMORY_TYPE                   ProfileMemoryIndex;\r
 \r
+  AllocInfoData = NULL;\r
+\r
   ContextData = GetSmramProfileContext ();\r
   if (ContextData == NULL) {\r
     return FALSE;\r
@@ -1173,61 +1175,6 @@ SmramProfileReadyToLock (
 \r
 ////////////////////\r
 \r
-/**\r
-  This function check if the address is in SMRAM.\r
-\r
-  @param Buffer  the buffer address to be checked.\r
-  @param Length  the buffer length to be checked.\r
-\r
-  @retval TRUE  this address is in SMRAM.\r
-  @retval FALSE this address is NOT in SMRAM.\r
-\r
-**/\r
-BOOLEAN\r
-InternalIsAddressInSmram (\r
-  IN PHYSICAL_ADDRESS   Buffer,\r
-  IN UINT64             Length\r
-  )\r
-{\r
-  UINTN  Index;\r
-\r
-  for (Index = 0; Index < mFullSmramRangeCount; Index ++) {\r
-    if (((Buffer >= mFullSmramRanges[Index].CpuStart) && (Buffer < mFullSmramRanges[Index].CpuStart + mFullSmramRanges[Index].PhysicalSize)) ||\r
-        ((mFullSmramRanges[Index].CpuStart >= Buffer) && (mFullSmramRanges[Index].CpuStart < Buffer + Length))) {\r
-      return TRUE;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-/**\r
-  This function check if the address refered by Buffer and Length is valid.\r
-\r
-  @param Buffer  the buffer address to be checked.\r
-  @param Length  the buffer length to be checked.\r
-\r
-  @retval TRUE  this address is valid.\r
-  @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressValid (\r
-  IN UINTN                 Buffer,\r
-  IN UINTN                 Length\r
-  )\r
-{\r
-  if (Buffer > (MAX_ADDRESS - Length)) {\r
-    //\r
-    // Overflow happen\r
-    //\r
-    return FALSE;\r
-  }\r
-  if (InternalIsAddressInSmram ((PHYSICAL_ADDRESS) Buffer, (UINT64)Length)) {\r
-    return FALSE;\r
-  }\r
-  return TRUE;\r
-}\r
-\r
 /**\r
   Get SMRAM profile data size.\r
 \r
@@ -1483,7 +1430,7 @@ SmramProfileHandlerGetData (
   //\r
   // Sanity check\r
   //\r
-  if (!InternalIsAddressValid ((UINTN) SmramProfileGetData.ProfileBuffer, (UINTN) ProfileSize)) {\r
+  if (!SmmIsBufferOutsideSmmValid ((UINTN) SmramProfileGetData.ProfileBuffer, (UINTN) ProfileSize)) {\r
     DEBUG ((EFI_D_ERROR, "SmramProfileHandlerGetData: SMM ProfileBuffer in SMRAM or overflow!\n"));\r
     SmramProfileParameterGetData->ProfileSize = ProfileSize;\r
     SmramProfileParameterGetData->Header.ReturnStatus = (UINT64) (INT64) (INTN) EFI_ACCESS_DENIED;\r
@@ -1608,7 +1555,7 @@ SmramProfileHandler (
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (mSmramReadyToLock && !InternalIsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+  if (mSmramReadyToLock && !SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
     DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
     return EFI_SUCCESS;\r
   }\r