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