]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add reallocate functions to the PEI Memory Allocation Library
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 24 Nov 2008 08:31:51 +0000 (08:31 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 24 Nov 2008 08:31:51 +0000 (08:31 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6706 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c

index a94a5508866ca2280adb741c61ecb7801a7dbc1e..6ce460a8c2752d46d3c033c1f06ee5d77b1d8537 100644 (file)
@@ -626,6 +626,147 @@ AllocateReservedCopyPool (
   return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
 }\r
 \r
+/**\r
+  Reallocates a buffer of a specified memory type.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize from memory of the type\r
+  specified by PoolType.  If OldBuffer is not NULL, then the smaller of OldSize and \r
+  NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
+  OldBuffer is freed.  A pointer to the newly allocated buffer is returned.  \r
+  If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not \r
+  enough memory remaining to satisfy the request, then NULL is returned.\r
+  \r
+  If OldBuffer is NULL, then ASSERT().\r
+  If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+  If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+\r
+  @param  PoolType       The type of pool to allocate.\r
+  @param  OldSize        The size, in bytes, of OldBuffer.\r
+  @param  NewSize        The size, in bytes, of the buffer to reallocate.\r
+  @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional \r
+                         parameter that may be NULL.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+InternalReallocatePool (\r
+  IN EFI_MEMORY_TYPE  PoolType,  \r
+  IN UINTN            OldSize,\r
+  IN UINTN            NewSize,\r
+  IN VOID             *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  VOID  *NewBuffer;\r
+\r
+  NewBuffer = AllocateZeroPool (NewSize);\r
+  if (NewBuffer != NULL && OldBuffer != NULL) {\r
+    CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
+    FreePool (OldBuffer);\r
+  }\r
+  return NewBuffer;\r
+}\r
+\r
+/**\r
+  Reallocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize from memory of type\r
+  EfiBootServicesData.  If OldBuffer is not NULL, then the smaller of OldSize and \r
+  NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
+  OldBuffer is freed.  A pointer to the newly allocated buffer is returned.  \r
+  If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not \r
+  enough memory remaining to satisfy the request, then NULL is returned.\r
+  \r
+  If OldBuffer is NULL, then ASSERT().\r
+  If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+  If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+\r
+  @param  OldSize        The size, in bytes, of OldBuffer.\r
+  @param  NewSize        The size, in bytes, of the buffer to reallocate.\r
+  @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional \r
+                         parameter that may be NULL.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+ReallocatePool (\r
+  IN UINTN  OldSize,\r
+  IN UINTN  NewSize,\r
+  IN VOID   *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer);\r
+}\r
+\r
+/**\r
+  Reallocates a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize from memory of type\r
+  EfiRuntimeServicesData.  If OldBuffer is not NULL, then the smaller of OldSize and \r
+  NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
+  OldBuffer is freed.  A pointer to the newly allocated buffer is returned.  \r
+  If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not \r
+  enough memory remaining to satisfy the request, then NULL is returned.\r
+\r
+  If OldBuffer is NULL, then ASSERT().\r
+  If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+  If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+\r
+  @param  OldSize        The size, in bytes, of OldBuffer.\r
+  @param  NewSize        The size, in bytes, of the buffer to reallocate.\r
+  @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional \r
+                         parameter that may be NULL.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+ReallocateRuntimePool (\r
+  IN UINTN  OldSize,\r
+  IN UINTN  NewSize,\r
+  IN VOID   *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);\r
+}\r
+\r
+/**\r
+  Reallocates a buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize from memory of type\r
+  EfiReservedMemoryType.  If OldBuffer is not NULL, then the smaller of OldSize and \r
+  NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
+  OldBuffer is freed.  A pointer to the newly allocated buffer is returned.  \r
+  If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not \r
+  enough memory remaining to satisfy the request, then NULL is returned.\r
+  \r
+  If OldBuffer is NULL, then ASSERT().\r
+  If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+  If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
+\r
+  @param  OldSize        The size, in bytes, of OldBuffer.\r
+  @param  NewSize        The size, in bytes, of the buffer to reallocate.\r
+  @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional \r
+                         parameter that may be NULL.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+ReallocateReservedPool (\r
+  IN UINTN  OldSize,\r
+  IN UINTN  NewSize,\r
+  IN VOID   *OldBuffer  OPTIONAL\r
+  )\r
+{\r
+  return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer);\r
+}\r
+\r
 /**\r
   Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
   Memory Allocation Library.\r