]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add ReallocatePool(), ReallocateRuntimePool(), and ReallocateReservedPool() to BaseMe...
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 22 Nov 2008 00:54:04 +0000 (00:54 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 22 Nov 2008 00:54:04 +0000 (00:54 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6679 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/Library/MemoryAllocationLib.h
MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c

index 347e45a24eb6c5b055922b108e8412f21a3c01ef..9b8e3aa62be4fe7616267e4c4c90763ccb4f885e 100644 (file)
@@ -378,6 +378,96 @@ AllocateReservedCopyPool (
   IN CONST VOID  *Buffer\r
   );\r
 \r
+/**\r
+  Reallocates a buffer of type EfiBootServicesData.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize with the memmory 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
+/**\r
+  Reallocates a buffer of type EfiRuntimeServicesData.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize with the memmory 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
+/**\r
+  Reallocates a buffer of type EfiReservedMemoryType.\r
+\r
+  Allocates and zeros the number bytes specified by NewSize with the memmory 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
 /**\r
   Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
   Memory Allocation Library.\r
index e2aeccd546e0c32b4cd1dae0e5dd67090c6dd841..c94f3a7c20585a6390262f405f4f4663b39ceba5 100644 (file)
@@ -128,6 +128,7 @@ AllocateReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the page allocation services of the Memory\r
   Allocation Library.\r
+  \r
   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
   If Pages is zero, then ASSERT().\r
@@ -242,6 +243,7 @@ InternalAllocateAlignedPages (
   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
   returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
   request, then NULL is returned.\r
+  \r
   If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
 \r
   @param  Pages                 The number of 4 KB pages to allocate.\r
@@ -268,6 +270,7 @@ AllocateAlignedPages (
   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
   returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
   request, then NULL is returned.\r
+  \r
   If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
 \r
   @param  Pages                 The number of 4 KB pages to allocate.\r
@@ -294,6 +297,7 @@ AllocateAlignedRuntimePages (
   alignment specified by Alignment.  The allocated buffer is returned.  If Pages is 0, then NULL is\r
   returned.  If there is not enough memory at the specified alignment remaining to satisfy the\r
   request, then NULL is returned.\r
+  \r
   If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
 \r
   @param  Pages                 The number of 4 KB pages to allocate.\r
@@ -320,6 +324,7 @@ AllocateAlignedReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the aligned page allocation services of the Memory\r
   Allocation Library.\r
+  \r
   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
   Library, then ASSERT().\r
   If Pages is zero, then ASSERT().\r
@@ -598,6 +603,7 @@ AllocateCopyPool (
   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
   is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  \r
   If Buffer is NULL, then ASSERT().\r
   If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
@@ -624,6 +630,7 @@ AllocateRuntimeCopyPool (
   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
   is not enough memory remaining to satisfy the request, then NULL is returned.\r
+  \r
   If Buffer is NULL, then ASSERT().\r
   If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
 \r
@@ -643,12 +650,154 @@ 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 with the memmory 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 with the memmory 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 with the memmory 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 with the memmory 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
 \r
   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
   pool allocation services of the Memory Allocation Library.\r
+  \r
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
 \r