MemoryAllocationLib.c revision 6babbe1f8cfe5b7e7657e0c14045bff608b6b04c
1/** @file 2 Support routines for memory allocation routines 3 based on PeiService for PEI phase drivers. 4 5 Copyright (c) 2006 - 2008, Intel Corporation<BR> 6 All rights reserved. This program and the accompanying materials 7 are licensed and made available under the terms and conditions of the BSD License 8 which accompanies this distribution. The full text of the license may be found at 9 http://opensource.org/licenses/bsd-license.php 10 11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14**/ 15 16 17#include <PiPei.h> 18 19 20#include <Library/MemoryAllocationLib.h> 21#include <Library/PeiServicesLib.h> 22#include <Library/BaseMemoryLib.h> 23#include <Library/DebugLib.h> 24 25 26/** 27 Allocates one or more 4KB pages of a certain memory type. 28 29 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated 30 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. 31 If there is not enough memory remaining to satisfy the request, then NULL is returned. 32 33 @param MemoryType The type of memory to allocate. 34 @param Pages The number of 4 KB pages to allocate. 35 36 @return A pointer to the allocated buffer or NULL if allocation fails. 37 38**/ 39VOID * 40InternalAllocatePages ( 41 IN EFI_MEMORY_TYPE MemoryType, 42 IN UINTN Pages 43 ) 44{ 45 EFI_STATUS Status; 46 EFI_PHYSICAL_ADDRESS Memory; 47 48 if (Pages == 0) { 49 return NULL; 50 } 51 52 Status = PeiServicesAllocatePages (MemoryType, Pages, &Memory); 53 if (EFI_ERROR (Status)) { 54 return NULL; 55 } 56 return (VOID *) (UINTN) Memory; 57} 58 59/** 60 Allocates one or more 4KB pages of type EfiBootServicesData. 61 62 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the 63 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL 64 is returned. If there is not enough memory remaining to satisfy the request, then NULL is 65 returned. 66 67 @param Pages The number of 4 KB pages to allocate. 68 69 @return A pointer to the allocated buffer or NULL if allocation fails. 70 71**/ 72VOID * 73EFIAPI 74AllocatePages ( 75 IN UINTN Pages 76 ) 77{ 78 return InternalAllocatePages (EfiBootServicesData, Pages); 79} 80 81/** 82 Allocates one or more 4KB pages of type EfiRuntimeServicesData. 83 84 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the 85 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL 86 is returned. If there is not enough memory remaining to satisfy the request, then NULL is 87 returned. 88 89 @param Pages The number of 4 KB pages to allocate. 90 91 @return A pointer to the allocated buffer or NULL if allocation fails. 92 93**/ 94VOID * 95EFIAPI 96AllocateRuntimePages ( 97 IN UINTN Pages 98 ) 99{ 100 return InternalAllocatePages (EfiRuntimeServicesData, Pages); 101} 102 103/** 104 Allocates one or more 4KB pages of type EfiReservedMemoryType. 105 106 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the 107 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL 108 is returned. If there is not enough memory remaining to satisfy the request, then NULL is 109 returned. 110 111 @param Pages The number of 4 KB pages to allocate. 112 113 @return A pointer to the allocated buffer or NULL if allocation fails. 114 115**/ 116VOID * 117EFIAPI 118AllocateReservedPages ( 119 IN UINTN Pages 120 ) 121{ 122 return InternalAllocatePages (EfiReservedMemoryType, Pages); 123} 124 125/** 126 Frees one or more 4KB pages that were previously allocated with one of the page allocation 127 functions in the Memory Allocation Library. 128 129 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer 130 must have been allocated on a previous call to the page allocation services of the Memory 131 Allocation Library. 132 133 If Buffer was not allocated with a page allocation function in the Memory Allocation Library, 134 then ASSERT(). 135 If Pages is zero, then ASSERT(). 136 137 @param Buffer Pointer to the buffer of pages to free. 138 @param Pages The number of 4 KB pages to free. 139 140**/ 141VOID 142EFIAPI 143FreePages ( 144 IN VOID *Buffer, 145 IN UINTN Pages 146 ) 147{ 148 // 149 // PEI phase does not support to free pages, so leave it as NOP. 150 // 151} 152 153/** 154 Allocates one or more 4KB pages of a certain memory type at a specified alignment. 155 156 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment 157 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. 158 If there is not enough memory at the specified alignment remaining to satisfy the request, then 159 NULL is returned. 160 If Alignment is not a power of two and Alignment is not zero, then ASSERT(). 161 162 @param MemoryType The type of memory to allocate. 163 @param Pages The number of 4 KB pages to allocate. 164 @param Alignment The requested alignment of the allocation. Must be a power of two. 165 If Alignment is zero, then byte alignment is used. 166 167 @return A pointer to the allocated buffer or NULL if allocation fails. 168 169**/ 170VOID * 171InternalAllocateAlignedPages ( 172 IN EFI_MEMORY_TYPE MemoryType, 173 IN UINTN Pages, 174 IN UINTN Alignment 175 ) 176{ 177 VOID *Memory; 178 UINTN AlignmentMask; 179 180 // 181 // Alignment must be a power of two or zero. 182 // 183 ASSERT ((Alignment & (Alignment - 1)) == 0); 184 185 if (Pages == 0) { 186 return NULL; 187 } 188 // 189 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. 190 // 191 ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment))); 192 // 193 // We would rather waste some memory to save PEI code size. 194 // 195 Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment)); 196 if (Alignment == 0) { 197 AlignmentMask = Alignment; 198 } else { 199 AlignmentMask = Alignment - 1; 200 } 201 return (VOID *) (UINTN) (((UINTN) Memory + AlignmentMask) & ~AlignmentMask); 202} 203 204/** 205 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. 206 207 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an 208 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is 209 returned. If there is not enough memory at the specified alignment remaining to satisfy the 210 request, then NULL is returned. 211 212 If Alignment is not a power of two and Alignment is not zero, then ASSERT(). 213 214 @param Pages The number of 4 KB pages to allocate. 215 @param Alignment The requested alignment of the allocation. Must be a power of two. 216 If Alignment is zero, then byte alignment is used. 217 218 @return A pointer to the allocated buffer or NULL if allocation fails. 219 220**/ 221VOID * 222EFIAPI 223AllocateAlignedPages ( 224 IN UINTN Pages, 225 IN UINTN Alignment 226 ) 227{ 228 return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment); 229} 230 231/** 232 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment. 233 234 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an 235 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is 236 returned. If there is not enough memory at the specified alignment remaining to satisfy the 237 request, then NULL is returned. 238 239 If Alignment is not a power of two and Alignment is not zero, then ASSERT(). 240 241 @param Pages The number of 4 KB pages to allocate. 242 @param Alignment The requested alignment of the allocation. Must be a power of two. 243 If Alignment is zero, then byte alignment is used. 244 245 @return A pointer to the allocated buffer or NULL if allocation fails. 246 247**/ 248VOID * 249EFIAPI 250AllocateAlignedRuntimePages ( 251 IN UINTN Pages, 252 IN UINTN Alignment 253 ) 254{ 255 return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment); 256} 257 258/** 259 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment. 260 261 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an 262 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is 263 returned. If there is not enough memory at the specified alignment remaining to satisfy the 264 request, then NULL is returned. 265 266 If Alignment is not a power of two and Alignment is not zero, then ASSERT(). 267 268 @param Pages The number of 4 KB pages to allocate. 269 @param Alignment The requested alignment of the allocation. Must be a power of two. 270 If Alignment is zero, then byte alignment is used. 271 272 @return A pointer to the allocated buffer or NULL if allocation fails. 273 274**/ 275VOID * 276EFIAPI 277AllocateAlignedReservedPages ( 278 IN UINTN Pages, 279 IN UINTN Alignment 280 ) 281{ 282 return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment); 283} 284 285/** 286 Frees one or more 4KB pages that were previously allocated with one of the aligned page 287 allocation functions in the Memory Allocation Library. 288 289 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer 290 must have been allocated on a previous call to the aligned page allocation services of the Memory 291 Allocation Library. 292 293 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation 294 Library, then ASSERT(). 295 If Pages is zero, then ASSERT(). 296 297 @param Buffer Pointer to the buffer of pages to free. 298 @param Pages The number of 4 KB pages to free. 299 300**/ 301VOID 302EFIAPI 303FreeAlignedPages ( 304 IN VOID *Buffer, 305 IN UINTN Pages 306 ) 307{ 308 // 309 // PEI phase does not support to free pages, so leave it as NOP. 310 // 311} 312 313/** 314 Allocates a buffer of a certain pool type. 315 316 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a 317 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is 318 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. 319 320 @param MemoryType The type of memory to allocate. 321 @param AllocationSize The number of bytes to allocate. 322 323 @return A pointer to the allocated buffer or NULL if allocation fails. 324 325**/ 326VOID * 327InternalAllocatePool ( 328 IN EFI_MEMORY_TYPE MemoryType, 329 IN UINTN AllocationSize 330 ) 331{ 332 // 333 // If we need lots of small runtime/reserved memory type from PEI in the future, 334 // we can consider providing a more complex algorithm that allocates runtime pages and 335 // provide pool allocations from those pages. 336 // 337 return InternalAllocatePages (MemoryType, EFI_SIZE_TO_PAGES (AllocationSize)); 338} 339 340/** 341 Allocates a buffer of type EfiBootServicesData. 342 343 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a 344 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is 345 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. 346 347 @param AllocationSize The number of bytes to allocate. 348 349 @return A pointer to the allocated buffer or NULL if allocation fails. 350 351**/ 352VOID * 353EFIAPI 354AllocatePool ( 355 IN UINTN AllocationSize 356 ) 357{ 358 EFI_STATUS Status; 359 VOID *Buffer; 360 361 Status = PeiServicesAllocatePool (AllocationSize, &Buffer); 362 if (EFI_ERROR (Status)) { 363 Buffer = NULL; 364 } 365 return Buffer; 366} 367 368/** 369 Allocates a buffer of type EfiRuntimeServicesData. 370 371 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns 372 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is 373 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. 374 375 @param AllocationSize The number of bytes to allocate. 376 377 @return A pointer to the allocated buffer or NULL if allocation fails. 378 379**/ 380VOID * 381EFIAPI 382AllocateRuntimePool ( 383 IN UINTN AllocationSize 384 ) 385{ 386 return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize); 387} 388 389/** 390 Allocates a buffer of type EfiReservedMemoryType. 391 392 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns 393 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is 394 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. 395 396 @param AllocationSize The number of bytes to allocate. 397 398 @return A pointer to the allocated buffer or NULL if allocation fails. 399 400**/ 401VOID * 402EFIAPI 403AllocateReservedPool ( 404 IN UINTN AllocationSize 405 ) 406{ 407 return InternalAllocatePool (EfiReservedMemoryType, AllocationSize); 408} 409 410/** 411 Allocates and zeros a buffer of a certian pool type. 412 413 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer 414 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid 415 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, 416 then NULL is returned. 417 418 @param PoolType The type of memory to allocate. 419 @param AllocationSize The number of bytes to allocate and zero. 420 421 @return A pointer to the allocated buffer or NULL if allocation fails. 422 423**/ 424VOID * 425InternalAllocateZeroPool ( 426 IN EFI_MEMORY_TYPE PoolType, 427 IN UINTN AllocationSize 428 ) 429{ 430 VOID *Memory; 431 432 Memory = InternalAllocatePool (PoolType, AllocationSize); 433 if (Memory != NULL) { 434 Memory = ZeroMem (Memory, AllocationSize); 435 } 436 return Memory; 437} 438 439/** 440 Allocates and zeros a buffer of type EfiBootServicesData. 441 442 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the 443 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a 444 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the 445 request, then NULL is returned. 446 447 @param AllocationSize The number of bytes to allocate and zero. 448 449 @return A pointer to the allocated buffer or NULL if allocation fails. 450 451**/ 452VOID * 453EFIAPI 454AllocateZeroPool ( 455 IN UINTN AllocationSize 456 ) 457{ 458 VOID *Memory; 459 460 Memory = AllocatePool (AllocationSize); 461 if (Memory != NULL) { 462 Memory = ZeroMem (Memory, AllocationSize); 463 } 464 return Memory; 465} 466 467/** 468 Allocates and zeros a buffer of type EfiRuntimeServicesData. 469 470 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the 471 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a 472 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the 473 request, then NULL is returned. 474 475 @param AllocationSize The number of bytes to allocate and zero. 476 477 @return A pointer to the allocated buffer or NULL if allocation fails. 478 479**/ 480VOID * 481EFIAPI 482AllocateRuntimeZeroPool ( 483 IN UINTN AllocationSize 484 ) 485{ 486 return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize); 487} 488 489/** 490 Allocates and zeros a buffer of type EfiReservedMemoryType. 491 492 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the 493 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a 494 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the 495 request, then NULL is returned. 496 497 @param AllocationSize The number of bytes to allocate and zero. 498 499 @return A pointer to the allocated buffer or NULL if allocation fails. 500 501**/ 502VOID * 503EFIAPI 504AllocateReservedZeroPool ( 505 IN UINTN AllocationSize 506 ) 507{ 508 return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize); 509} 510 511/** 512 Copies a buffer to an allocated buffer of a certian pool type. 513 514 Allocates the number bytes specified by AllocationSize of a certian pool type, copies 515 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the 516 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there 517 is not enough memory remaining to satisfy the request, then NULL is returned. 518 If Buffer is NULL, then ASSERT(). 519 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 520 521 @param PoolType The type of pool to allocate. 522 @param AllocationSize The number of bytes to allocate and zero. 523 @param Buffer The buffer to copy to the allocated buffer. 524 525 @return A pointer to the allocated buffer or NULL if allocation fails. 526 527**/ 528VOID * 529InternalAllocateCopyPool ( 530 IN EFI_MEMORY_TYPE PoolType, 531 IN UINTN AllocationSize, 532 IN CONST VOID *Buffer 533 ) 534{ 535 VOID *Memory; 536 537 ASSERT (Buffer != NULL); 538 ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1)); 539 540 Memory = InternalAllocatePool (PoolType, AllocationSize); 541 if (Memory != NULL) { 542 Memory = CopyMem (Memory, Buffer, AllocationSize); 543 } 544 return Memory; 545} 546 547/** 548 Copies a buffer to an allocated buffer of type EfiBootServicesData. 549 550 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies 551 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the 552 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there 553 is not enough memory remaining to satisfy the request, then NULL is returned. 554 555 If Buffer is NULL, then ASSERT(). 556 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 557 558 @param AllocationSize The number of bytes to allocate and zero. 559 @param Buffer The buffer to copy to the allocated buffer. 560 561 @return A pointer to the allocated buffer or NULL if allocation fails. 562 563**/ 564VOID * 565EFIAPI 566AllocateCopyPool ( 567 IN UINTN AllocationSize, 568 IN CONST VOID *Buffer 569 ) 570{ 571 VOID *Memory; 572 573 ASSERT (Buffer != NULL); 574 ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1)); 575 576 Memory = AllocatePool (AllocationSize); 577 if (Memory != NULL) { 578 Memory = CopyMem (Memory, Buffer, AllocationSize); 579 } 580 return Memory; 581} 582 583/** 584 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData. 585 586 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies 587 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the 588 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there 589 is not enough memory remaining to satisfy the request, then NULL is returned. 590 591 If Buffer is NULL, then ASSERT(). 592 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 593 594 @param AllocationSize The number of bytes to allocate and zero. 595 @param Buffer The buffer to copy to the allocated buffer. 596 597 @return A pointer to the allocated buffer or NULL if allocation fails. 598 599**/ 600VOID * 601EFIAPI 602AllocateRuntimeCopyPool ( 603 IN UINTN AllocationSize, 604 IN CONST VOID *Buffer 605 ) 606{ 607 return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer); 608} 609 610/** 611 Copies a buffer to an allocated buffer of type EfiReservedMemoryType. 612 613 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies 614 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the 615 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there 616 is not enough memory remaining to satisfy the request, then NULL is returned. 617 618 If Buffer is NULL, then ASSERT(). 619 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 620 621 @param AllocationSize The number of bytes to allocate and zero. 622 @param Buffer The buffer to copy to the allocated buffer. 623 624 @return A pointer to the allocated buffer or NULL if allocation fails. 625 626**/ 627VOID * 628EFIAPI 629AllocateReservedCopyPool ( 630 IN UINTN AllocationSize, 631 IN CONST VOID *Buffer 632 ) 633{ 634 return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer); 635} 636 637/** 638 Reallocates a buffer of a specified memory type. 639 640 Allocates and zeros the number bytes specified by NewSize from memory of the type 641 specified by PoolType. If OldBuffer is not NULL, then the smaller of OldSize and 642 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and 643 OldBuffer is freed. A pointer to the newly allocated buffer is returned. 644 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not 645 enough memory remaining to satisfy the request, then NULL is returned. 646 647 If the smaller of NewSize and OldSize is greater than (MAX_ADDRESS - OldBuffer + 1), 648 then ASSERT(). 649 650 @param PoolType The type of pool to allocate. 651 @param OldSize The size, in bytes, of OldBuffer. 652 @param NewSize The size, in bytes, of the buffer to reallocate. 653 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional 654 parameter that may be NULL. 655 656 @return A pointer to the allocated buffer or NULL if allocation fails. 657 658**/ 659VOID * 660InternalReallocatePool ( 661 IN EFI_MEMORY_TYPE PoolType, 662 IN UINTN OldSize, 663 IN UINTN NewSize, 664 IN VOID *OldBuffer OPTIONAL 665 ) 666{ 667 VOID *NewBuffer; 668 669 NewBuffer = InternalAllocateZeroPool (PoolType, NewSize); 670 if (NewBuffer != NULL && OldBuffer != NULL) { 671 CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize)); 672 FreePool (OldBuffer); 673 } 674 return NewBuffer; 675} 676 677/** 678 Reallocates a buffer of type EfiBootServicesData. 679 680 Allocates and zeros the number bytes specified by NewSize from memory of type 681 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and 682 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and 683 OldBuffer is freed. A pointer to the newly allocated buffer is returned. 684 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not 685 enough memory remaining to satisfy the request, then NULL is returned. 686 687 If the smaller of NewSize and OldSize is greater than (MAX_ADDRESS - OldBuffer + 1), 688 then ASSERT(). 689 690 @param OldSize The size, in bytes, of OldBuffer. 691 @param NewSize The size, in bytes, of the buffer to reallocate. 692 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional 693 parameter that may be NULL. 694 695 @return A pointer to the allocated buffer or NULL if allocation fails. 696 697**/ 698VOID * 699EFIAPI 700ReallocatePool ( 701 IN UINTN OldSize, 702 IN UINTN NewSize, 703 IN VOID *OldBuffer OPTIONAL 704 ) 705{ 706 return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer); 707} 708 709/** 710 Reallocates a buffer of type EfiRuntimeServicesData. 711 712 Allocates and zeros the number bytes specified by NewSize from memory of type 713 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and 714 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and 715 OldBuffer is freed. A pointer to the newly allocated buffer is returned. 716 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not 717 enough memory remaining to satisfy the request, then NULL is returned. 718 719 If the smaller of NewSize and OldSize is greater than (MAX_ADDRESS - OldBuffer + 1), 720 then ASSERT(). 721 722 @param OldSize The size, in bytes, of OldBuffer. 723 @param NewSize The size, in bytes, of the buffer to reallocate. 724 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional 725 parameter that may be NULL. 726 727 @return A pointer to the allocated buffer or NULL if allocation fails. 728 729**/ 730VOID * 731EFIAPI 732ReallocateRuntimePool ( 733 IN UINTN OldSize, 734 IN UINTN NewSize, 735 IN VOID *OldBuffer OPTIONAL 736 ) 737{ 738 return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer); 739} 740 741/** 742 Reallocates a buffer of type EfiReservedMemoryType. 743 744 Allocates and zeros the number bytes specified by NewSize from memory of type 745 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and 746 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and 747 OldBuffer is freed. A pointer to the newly allocated buffer is returned. 748 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not 749 enough memory remaining to satisfy the request, then NULL is returned. 750 751 If the smaller of NewSize and OldSize is greater than (MAX_ADDRESS - OldBuffer + 1), 752 then ASSERT(). 753 754 @param OldSize The size, in bytes, of OldBuffer. 755 @param NewSize The size, in bytes, of the buffer to reallocate. 756 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional 757 parameter that may be NULL. 758 759 @return A pointer to the allocated buffer or NULL if allocation fails. 760 761**/ 762VOID * 763EFIAPI 764ReallocateReservedPool ( 765 IN UINTN OldSize, 766 IN UINTN NewSize, 767 IN VOID *OldBuffer OPTIONAL 768 ) 769{ 770 return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer); 771} 772 773/** 774 Frees a buffer that was previously allocated with one of the pool allocation functions in the 775 Memory Allocation Library. 776 777 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the 778 pool allocation services of the Memory Allocation Library. 779 780 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, 781 then ASSERT(). 782 783 @param Buffer Pointer to the buffer to free. 784 785**/ 786VOID 787EFIAPI 788FreePool ( 789 IN VOID *Buffer 790 ) 791{ 792 // 793 // PEI phase does not support to free pool, so leave it as NOP. 794 // 795} 796 797 798