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