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