]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
Comments have been checked with spec
[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 - 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 **/
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.
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 **/
141 VOID
142 EFIAPI
143 FreePages (
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 **/
170 VOID *
171 InternalAllocateAlignedPages (
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 **/
221 VOID *
222 EFIAPI
223 AllocateAlignedPages (
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 **/
248 VOID *
249 EFIAPI
250 AllocateAlignedRuntimePages (
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 **/
275 VOID *
276 EFIAPI
277 AllocateAlignedReservedPages (
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 **/
301 VOID
302 EFIAPI
303 FreeAlignedPages (
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 **/
326 VOID *
327 InternalAllocatePool (
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 **/
352 VOID *
353 EFIAPI
354 AllocatePool (
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 **/
380 VOID *
381 EFIAPI
382 AllocateRuntimePool (
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 **/
401 VOID *
402 EFIAPI
403 AllocateReservedPool (
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 **/
424 VOID *
425 InternalAllocateZeroPool (
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 **/
452 VOID *
453 EFIAPI
454 AllocateZeroPool (
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 **/
480 VOID *
481 EFIAPI
482 AllocateRuntimeZeroPool (
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 **/
502 VOID *
503 EFIAPI
504 AllocateReservedZeroPool (
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 **/
528 VOID *
529 InternalAllocateCopyPool (
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 **/
564 VOID *
565 EFIAPI
566 AllocateCopyPool (
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 **/
600 VOID *
601 EFIAPI
602 AllocateRuntimeCopyPool (
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 **/
627 VOID *
628 EFIAPI
629 AllocateReservedCopyPool (
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 OldBuffer is NULL, then ASSERT().
648 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
649 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
650
651 @param PoolType The type of pool to allocate.
652 @param OldSize The size, in bytes, of OldBuffer.
653 @param NewSize The size, in bytes, of the buffer to reallocate.
654 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
655 parameter that may be NULL.
656
657 @return A pointer to the allocated buffer or NULL if allocation fails.
658
659 **/
660 VOID *
661 InternalReallocatePool (
662 IN EFI_MEMORY_TYPE PoolType,
663 IN UINTN OldSize,
664 IN UINTN NewSize,
665 IN VOID *OldBuffer OPTIONAL
666 )
667 {
668 VOID *NewBuffer;
669
670 NewBuffer = AllocateZeroPool (NewSize);
671 if (NewBuffer != NULL && OldBuffer != NULL) {
672 CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
673 FreePool (OldBuffer);
674 }
675 return NewBuffer;
676 }
677
678 /**
679 Reallocates a buffer of type EfiBootServicesData.
680
681 Allocates and zeros the number bytes specified by NewSize from memory of type
682 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
683 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
684 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
685 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
686 enough memory remaining to satisfy the request, then NULL is returned.
687
688 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
689 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
690
691 @param OldSize The size, in bytes, of OldBuffer.
692 @param NewSize The size, in bytes, of the buffer to reallocate.
693 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
694 parameter that may be NULL.
695
696 @return A pointer to the allocated buffer or NULL if allocation fails.
697
698 **/
699 VOID *
700 EFIAPI
701 ReallocatePool (
702 IN UINTN OldSize,
703 IN UINTN NewSize,
704 IN VOID *OldBuffer OPTIONAL
705 )
706 {
707 return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer);
708 }
709
710 /**
711 Reallocates a buffer of type EfiRuntimeServicesData.
712
713 Allocates and zeros the number bytes specified by NewSize from memory of type
714 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
715 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
716 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
717 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
718 enough memory remaining to satisfy the request, then NULL is returned.
719
720 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
721 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
722
723 @param OldSize The size, in bytes, of OldBuffer.
724 @param NewSize The size, in bytes, of the buffer to reallocate.
725 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
726 parameter that may be NULL.
727
728 @return A pointer to the allocated buffer or NULL if allocation fails.
729
730 **/
731 VOID *
732 EFIAPI
733 ReallocateRuntimePool (
734 IN UINTN OldSize,
735 IN UINTN NewSize,
736 IN VOID *OldBuffer OPTIONAL
737 )
738 {
739 return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
740 }
741
742 /**
743 Reallocates a buffer of type EfiReservedMemoryType.
744
745 Allocates and zeros the number bytes specified by NewSize from memory of type
746 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
747 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
748 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
749 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
750 enough memory remaining to satisfy the request, then NULL is returned.
751
752 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
753 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
754
755 @param OldSize The size, in bytes, of OldBuffer.
756 @param NewSize The size, in bytes, of the buffer to reallocate.
757 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
758 parameter that may be NULL.
759
760 @return A pointer to the allocated buffer or NULL if allocation fails.
761
762 **/
763 VOID *
764 EFIAPI
765 ReallocateReservedPool (
766 IN UINTN OldSize,
767 IN UINTN NewSize,
768 IN VOID *OldBuffer OPTIONAL
769 )
770 {
771 return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer);
772 }
773
774 /**
775 Frees a buffer that was previously allocated with one of the pool allocation functions in the
776 Memory Allocation Library.
777
778 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
779 pool allocation services of the Memory Allocation Library.
780
781 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
782 then ASSERT().
783
784 @param Buffer Pointer to the buffer to free.
785
786 **/
787 VOID
788 EFIAPI
789 FreePool (
790 IN VOID *Buffer
791 )
792 {
793 //
794 // PEI phase does not support to free pool, so leave it as NOP.
795 //
796 }
797
798