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