Cc: Jiewen Yao <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <[email protected]>
---
 .../DxeCoreMemoryAllocationLib.inf                 |  15 +-
 .../DxeCoreMemoryAllocationLib.uni                 |  12 +-
 .../DxeCoreMemoryProfileLib.c                      |  57 +++++
 .../DxeCoreMemoryProfileServices.h                 |  54 ++++
 .../MemoryAllocationLib.c                          | 277 +++++++++++++++++++--
 5 files changed, 383 insertions(+), 32 deletions(-)
 create mode 100644 
MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileLib.c
 create mode 100644 
MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileServices.h

diff --git 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
index 0747f6e69759..ee638343c25e 100644
--- 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
+++ 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
@@ -1,10 +1,10 @@
 ## @file
-# Memory Allocation Library instance dedicated to DXE Core.
-# The implementation borrows the DxeCore Memory Allocation services as the 
primitive
-# for memory allocation instead of using UEFI boot servces in an indirect way.
+# Memory Allocation/Profile Library instance dedicated to DXE Core.
+# The implementation borrows the DxeCore Memory Allocation/profile services as 
the primitive
+# for memory allocation/profile instead of using UEFI boot services or memory 
profile protocol in an indirect way.
 # It is assumed that this library instance must be linked with DxeCore in this 
package. 
 #
-# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -24,7 +24,8 @@ [Defines]
   MODULE_TYPE                    = DXE_CORE
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = MemoryAllocationLib|DXE_CORE
-  
+  LIBRARY_CLASS                  = MemoryProfileLib|DXE_CORE
+
 #
 # The following information is for reference only and not required by the 
build tools.
 #
@@ -34,10 +35,12 @@ [Defines]
 [Sources]
   MemoryAllocationLib.c
   DxeCoreMemoryAllocationServices.h
+  DxeCoreMemoryProfileLib.c
+  DxeCoreMemoryProfileServices.h
 
 [Packages]
   MdePkg/MdePkg.dec
-
+  MdeModulePkg/MdeModulePkg.dec
 
 [LibraryClasses]
   DebugLib
diff --git 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.uni
 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.uni
index 85f8c7ec27ca..82cdca62aa39 100644
--- 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.uni
+++ 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.uni
@@ -1,11 +1,11 @@
 // /** @file
-// Memory Allocation Library instance dedicated to DXE Core.
+// Memory Allocation/Profile Library instance dedicated to DXE Core.
 //
-// The implementation borrows the DxeCore Memory Allocation services as the 
primitive
-// for memory allocation instead of using UEFI boot servces in an indirect way.
+// The implementation borrows the DxeCore Memory Allocation/Profile services 
as the primitive
+// for memory allocation/profile instead of using UEFI boot services or memory 
profile protocol in an indirect way.
 // It is assumed that this library instance must be linked with DxeCore in 
this package.
 //
-// Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
+// Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
 //
 // This program and the accompanying materials
 // are licensed and made available under the terms and conditions of the BSD 
License
@@ -17,7 +17,7 @@
 // **/
 
 
-#string STR_MODULE_ABSTRACT             #language en-US "Memory Allocation 
Library instance dedicated to DXE Core"
+#string STR_MODULE_ABSTRACT             #language en-US "Memory 
Allocation/Profile Library instance dedicated to DXE Core"
 
-#string STR_MODULE_DESCRIPTION          #language en-US "The implementation 
borrows the DxeCore Memory Allocation services as the primitive for memory 
allocation instead of using UEFI boot services in an indirect way. It is 
assumed that this library instance must be linked with DxeCore in this package."
+#string STR_MODULE_DESCRIPTION          #language en-US "The implementation 
borrows the DxeCore Memory Allocation/Profile services as the primitive for 
memory allocation/profile instead of using UEFI boot services or memory profile 
protocol in an indirect way. It is assumed that this library instance must be 
linked with DxeCore in this package."
 
diff --git 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileLib.c 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileLib.c
new file mode 100644
index 000000000000..8f28b988f5e0
--- /dev/null
+++ b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileLib.c
@@ -0,0 +1,57 @@
+/** @file
+  Support routines for memory profile for DxeCore.
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  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        
+  http://opensource.org/licenses/bsd-license.php.                              
              
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,        
             
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.             
+
+**/
+
+
+#include <PiDxe.h>
+
+#include <Guid/MemoryProfile.h>
+
+#include "DxeCoreMemoryProfileServices.h"
+
+/**
+  Record memory profile of multilevel caller.
+
+  @param[in] CallerAddress      Address of caller.
+  @param[in] Action             Memory profile action.
+  @param[in] MemoryType         Memory type.
+                                EfiMaxMemoryType means the MemoryType is 
unknown.
+  @param[in] Buffer             Buffer address.
+  @param[in] Size               Buffer size.
+  @param[in] ActionString       String for memory profile action.
+                                Only needed for user defined allocate action.
+
+  @return EFI_SUCCESS           Memory profile is updated.
+  @return EFI_UNSUPPORTED       Memory profile is unsupported,
+                                or memory profile for the image is not 
required,
+                                or memory profile for the memory type is not 
required.
+  @return EFI_ACCESS_DENIED     It is during memory profile data getting.
+  @return EFI_ABORTED           Memory profile recording is not enabled.
+  @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile 
for allocate action.
+  @return EFI_NOT_FOUND         No matched allocate info found for free action.
+
+**/
+EFI_STATUS
+EFIAPI
+MemoryProfileLibRecord (
+  IN PHYSICAL_ADDRESS           CallerAddress,
+  IN MEMORY_PROFILE_ACTION      Action,
+  IN EFI_MEMORY_TYPE            MemoryType,
+  IN VOID                       *Buffer,
+  IN UINTN                      Size,
+  IN CHAR8                      *ActionString OPTIONAL
+  )
+{
+  return CoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, 
ActionString);
+}
+
diff --git 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileServices.h
 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileServices.h
new file mode 100644
index 000000000000..619d7add9a6d
--- /dev/null
+++ 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryProfileServices.h
@@ -0,0 +1,54 @@
+/** @file
+  Contains function prototypes for Memory Profile Services in DxeCore.
+
+  This header file borrows the DxeCore Memory Profile services as the primitive
+  for memory profile.
+
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+  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        
+  http://opensource.org/licenses/bsd-license.php                               
             
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,        
             
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.             
+
+**/
+
+#ifndef _DXE_CORE_MEMORY_PROFILE_SERVICES_H_
+#define _DXE_CORE_MEMORY_PROFILE_SERVICES_H_
+
+/**
+  Update memory profile information.
+
+  @param CallerAddress  Address of caller who call Allocate or Free.
+  @param Action         This Allocate or Free action.
+  @param MemoryType     Memory type.
+                        EfiMaxMemoryType means the MemoryType is unknown.
+  @param Size           Buffer size.
+  @param Buffer         Buffer address.
+  @param ActionString   String for memory profile action.
+                        Only needed for user defined allocate action.
+
+  @return EFI_SUCCESS           Memory profile is updated.
+  @return EFI_UNSUPPORTED       Memory profile is unsupported,
+                                or memory profile for the image is not 
required,
+                                or memory profile for the memory type is not 
required.
+  @return EFI_ACCESS_DENIED     It is during memory profile data getting.
+  @return EFI_ABORTED           Memory profile recording is not enabled.
+  @return EFI_OUT_OF_RESOURCES  No enough resource to update memory profile 
for allocate action.
+  @return EFI_NOT_FOUND         No matched allocate info found for free action.
+
+**/
+EFI_STATUS
+EFIAPI
+CoreUpdateProfile (
+  IN PHYSICAL_ADDRESS       CallerAddress,
+  IN MEMORY_PROFILE_ACTION  Action,
+  IN EFI_MEMORY_TYPE        MemoryType,
+  IN UINTN                  Size,       // Valid for 
AllocatePages/FreePages/AllocatePool
+  IN VOID                   *Buffer,
+  IN CHAR8                  *ActionString OPTIONAL
+  );
+
+#endif
diff --git 
a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c 
b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
index d7d9ff311e16..89c19e7c83dc 100644
--- a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
@@ -1,8 +1,9 @@
 /** @file
   Support routines for memory allocation routines based 
-  on boot services for Dxe phase drivers.
+  on DxeCore Memory Allocation services for DxeCore,
+  with memory profile support.
 
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
   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        
@@ -22,6 +23,8 @@
 #include <Library/DebugLib.h>
 #include "DxeCoreMemoryAllocationServices.h"
 
+#include <Library/MemoryProfileLib.h>
+
 /**
   Allocates one or more 4KB pages of a certain memory type.
 
@@ -74,7 +77,20 @@ AllocatePages (
   IN UINTN  Pages
   )
 {
-  return InternalAllocatePages (EfiBootServicesData, Pages);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePages (EfiBootServicesData, Pages);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,
+      EfiBootServicesData,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -96,7 +112,20 @@ AllocateRuntimePages (
   IN UINTN  Pages
   )
 {
-  return InternalAllocatePages (EfiRuntimeServicesData, Pages);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePages (EfiRuntimeServicesData, Pages);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,
+      EfiRuntimeServicesData,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -118,7 +147,20 @@ AllocateReservedPages (
   IN UINTN  Pages
   )
 {
-  return InternalAllocatePages (EfiReservedMemoryType, Pages);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePages (EfiReservedMemoryType, Pages);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,
+      EfiReservedMemoryType,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -263,7 +305,20 @@ AllocateAlignedPages (
   IN UINTN  Alignment
   )
 {
-  return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateAlignedPages (EfiBootServicesData, Pages, 
Alignment);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,
+      EfiBootServicesData,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -291,7 +346,20 @@ AllocateAlignedRuntimePages (
   IN UINTN  Alignment
   )
 {
-  return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, 
Alignment);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, 
Alignment);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,
+      EfiRuntimeServicesData,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -319,7 +387,20 @@ AllocateAlignedReservedPages (
   IN UINTN  Alignment
   )
 {
-  return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, 
Alignment);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, 
Alignment);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES,
+      EfiReservedMemoryType,
+      Buffer,
+      EFI_PAGES_TO_SIZE (Pages),
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -402,7 +483,20 @@ AllocatePool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocatePool (EfiBootServicesData, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePool (EfiBootServicesData, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,
+      EfiBootServicesData,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -423,7 +517,20 @@ AllocateRuntimePool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,
+      EfiRuntimeServicesData,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -444,7 +551,20 @@ AllocateReservedPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocatePool (EfiReservedMemoryType, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL,
+      EfiReservedMemoryType,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -495,7 +615,20 @@ AllocateZeroPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,
+      EfiBootServicesData,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -517,7 +650,20 @@ AllocateRuntimeZeroPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,
+      EfiRuntimeServicesData,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -539,7 +685,20 @@ AllocateReservedZeroPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);
+  VOID  *Buffer;
+
+  Buffer = InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL,
+      EfiReservedMemoryType,
+      Buffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -602,7 +761,20 @@ AllocateCopyPool (
   IN CONST VOID  *Buffer
   )
 {
-  return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, 
Buffer);
+  VOID  *NewBuffer;
+
+  NewBuffer = InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, 
Buffer);
+  if (NewBuffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,
+      EfiBootServicesData,
+      NewBuffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return NewBuffer;
 }
 
 /**
@@ -629,7 +801,20 @@ AllocateRuntimeCopyPool (
   IN CONST VOID  *Buffer
   )
 {
-  return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, 
Buffer);
+  VOID  *NewBuffer;
+
+  NewBuffer = InternalAllocateCopyPool (EfiRuntimeServicesData, 
AllocationSize, Buffer);
+  if (NewBuffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,
+      EfiRuntimeServicesData,
+      NewBuffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return NewBuffer;
 }
 
 /**
@@ -656,7 +841,20 @@ AllocateReservedCopyPool (
   IN CONST VOID  *Buffer
   )
 {
-  return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, 
Buffer);
+  VOID  *NewBuffer;
+
+  NewBuffer = InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, 
Buffer);
+  if (NewBuffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL,
+      EfiRuntimeServicesData,
+      NewBuffer,
+      AllocationSize,
+      NULL
+      );
+  }
+  return NewBuffer;
 }
 
 /**
@@ -728,7 +926,20 @@ ReallocatePool (
   IN VOID   *OldBuffer  OPTIONAL
   )
 {
-  return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, 
OldBuffer);
+  VOID  *Buffer;
+
+  Buffer = InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, 
OldBuffer);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,
+      EfiBootServicesData,
+      Buffer,
+      NewSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -760,7 +971,20 @@ ReallocateRuntimePool (
   IN VOID   *OldBuffer  OPTIONAL
   )
 {
-  return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, 
OldBuffer);
+  VOID  *Buffer;
+
+  Buffer = InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, 
OldBuffer);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,
+      EfiRuntimeServicesData,
+      Buffer,
+      NewSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
@@ -792,7 +1016,20 @@ ReallocateReservedPool (
   IN VOID   *OldBuffer  OPTIONAL
   )
 {
-  return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, 
OldBuffer);
+  VOID  *Buffer;
+
+  Buffer = InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, 
OldBuffer);
+  if (Buffer != NULL) {
+    MemoryProfileLibRecord (
+      (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+      MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,
+      EfiReservedMemoryType,
+      Buffer,
+      NewSize,
+      NULL
+      );
+  }
+  return Buffer;
 }
 
 /**
-- 
2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to