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