]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
Remove SafeFreePool from MemoryAllocationLib as this API's name is misleading. Its...
[mirror_edk2.git] / MdePkg / Library / UefiMemoryAllocationLib / MemoryAllocationLib.c
CommitLineData
e386b444 1/** @file\r
9e6fa6d2
LG
2 Support routines for memory allocation routines based \r
3 on boot services for Dxe phase drivers.\r
e386b444 4\r
9e6fa6d2 5 Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
e386b444 6 All rights reserved. This program and the accompanying materials \r
7 are licensed and made available under the terms and conditions of the BSD License \r
8 which accompanies this distribution. The full text of the license may be found at \r
9 http://opensource.org/licenses/bsd-license.php \r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
13\r
e386b444 14**/\r
15\r
c892d846 16\r
60c93673 17#include <Uefi.h>\r
c892d846 18\r
19\r
c7d265a9 20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23#include <Library/DebugLib.h>\r
e386b444 24\r
e386b444 25/**\r
26 Allocates one or more 4KB pages of a certain memory type.\r
27\r
28 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated\r
29 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.\r
30 If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
31\r
32 @param MemoryType The type of memory to allocate.\r
33 @param Pages The number of 4 KB pages to allocate.\r
34\r
35 @return A pointer to the allocated buffer or NULL if allocation fails.\r
36\r
37**/\r
38VOID *\r
39InternalAllocatePages (\r
40 IN EFI_MEMORY_TYPE MemoryType, \r
41 IN UINTN Pages\r
42 )\r
43{\r
44 EFI_STATUS Status;\r
45 EFI_PHYSICAL_ADDRESS Memory; \r
46\r
47 if (Pages == 0) {\r
48 return NULL;\r
49 }\r
50\r
51 Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r
52 if (EFI_ERROR (Status)) {\r
9e6fa6d2 53 return NULL;\r
e386b444 54 }\r
55 return (VOID *) (UINTN) Memory;\r
56}\r
57\r
58/**\r
59 Allocates one or more 4KB pages of type EfiBootServicesData.\r
60\r
61 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
62 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
63 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
64 returned.\r
65\r
66 @param Pages The number of 4 KB pages to allocate.\r
67\r
68 @return A pointer to the allocated buffer or NULL if allocation fails.\r
69\r
70**/\r
71VOID *\r
72EFIAPI\r
73AllocatePages (\r
74 IN UINTN Pages\r
75 )\r
76{\r
77 return InternalAllocatePages (EfiBootServicesData, Pages);\r
78}\r
79\r
80/**\r
81 Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
82\r
83 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
84 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
85 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
86 returned.\r
87\r
88 @param Pages The number of 4 KB pages to allocate.\r
89\r
90 @return A pointer to the allocated buffer or NULL if allocation fails.\r
91\r
92**/\r
93VOID *\r
94EFIAPI\r
95AllocateRuntimePages (\r
96 IN UINTN Pages\r
97 )\r
98{\r
99 return InternalAllocatePages (EfiRuntimeServicesData, Pages);\r
100}\r
101\r
102/**\r
103 Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
104\r
105 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
106 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
107 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
108 returned.\r
109\r
110 @param Pages The number of 4 KB pages to allocate.\r
111\r
112 @return A pointer to the allocated buffer or NULL if allocation fails.\r
113\r
114**/\r
115VOID *\r
116EFIAPI\r
117AllocateReservedPages (\r
118 IN UINTN Pages\r
119 )\r
120{\r
121 return InternalAllocatePages (EfiReservedMemoryType, Pages);\r
122}\r
123\r
124/**\r
125 Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
126 functions in the Memory Allocation Library.\r
127\r
128 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
129 must have been allocated on a previous call to the page allocation services of the Memory\r
130 Allocation Library.\r
131 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
132 then ASSERT().\r
133 If Pages is zero, then ASSERT().\r
134 \r
135 @param Buffer Pointer to the buffer of pages to free.\r
136 @param Pages The number of 4 KB pages to free.\r
137\r
138**/\r
139VOID\r
140EFIAPI\r
141FreePages (\r
142 IN VOID *Buffer,\r
143 IN UINTN Pages\r
144 )\r
145{\r
146 EFI_STATUS Status;\r
147\r
148 ASSERT (Pages != 0);\r
149 Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
150 ASSERT_EFI_ERROR (Status);\r
151}\r
152\r
153/**\r
154 Allocates one or more 4KB pages of a certain memory type at a specified alignment.\r
155\r
156 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment\r
157 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.\r
158 If there is not enough memory at the specified alignment remaining to satisfy the request, then\r
159 NULL is returned.\r
160 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
161\r
162 @param MemoryType The type of memory to allocate.\r
163 @param Pages The number of 4 KB pages to allocate.\r
164 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
165 If Alignment is zero, then byte alignment is used.\r
166\r
167 @return A pointer to the allocated buffer or NULL if allocation fails.\r
168\r
169**/\r
170VOID *\r
171InternalAllocateAlignedPages (\r
172 IN EFI_MEMORY_TYPE MemoryType, \r
173 IN UINTN Pages,\r
174 IN UINTN Alignment\r
175 )\r
176{\r
177 EFI_STATUS Status;\r
178 EFI_PHYSICAL_ADDRESS Memory;\r
179 UINTN AlignedMemory;\r
180 UINTN AlignmentMask;\r
181 UINTN UnalignedPages;\r
182 UINTN RealPages;\r
183\r
184 //\r
185 // Alignment must be a power of two or zero.\r
186 //\r
187 ASSERT ((Alignment & (Alignment - 1)) == 0);\r
188 \r
189 if (Pages == 0) {\r
190 return NULL;\r
191 }\r
192 if (Alignment > EFI_PAGE_SIZE) {\r
193 //\r
194 // Caculate the total number of pages since alignment is larger than page size.\r
195 //\r
196 AlignmentMask = Alignment - 1;\r
197 RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
198 //\r
199 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
200 //\r
201 ASSERT (RealPages > Pages);\r
202 \r
203 Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
204 if (EFI_ERROR (Status)) {\r
205 return NULL;\r
206 }\r
207 AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
e111752c 208 UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);\r
e386b444 209 if (UnalignedPages > 0) {\r
210 //\r
211 // Free first unaligned page(s).\r
212 //\r
213 Status = gBS->FreePages (Memory, UnalignedPages);\r
214 ASSERT_EFI_ERROR (Status);\r
215 }\r
216 Memory = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));\r
217 UnalignedPages = RealPages - Pages - UnalignedPages;\r
218 if (UnalignedPages > 0) {\r
219 //\r
220 // Free last unaligned page(s).\r
221 //\r
222 Status = gBS->FreePages (Memory, UnalignedPages);\r
223 ASSERT_EFI_ERROR (Status);\r
224 }\r
225 } else {\r
226 //\r
227 // Do not over-allocate pages in this case.\r
228 //\r
229 Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r
230 if (EFI_ERROR (Status)) {\r
231 return NULL;\r
232 }\r
233 AlignedMemory = (UINTN) Memory;\r
234 }\r
235 return (VOID *) AlignedMemory;\r
236}\r
237\r
238/**\r
239 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
240\r
241 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
242 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
243 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
244 request, then NULL is returned.\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 (EfiBootServicesData, 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 If Alignment is not a power of two and Alignment is not zero, 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 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
298\r
299 @param Pages The number of 4 KB pages to allocate.\r
300 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
301 If Alignment is zero, then byte alignment is used.\r
302\r
303 @return A pointer to the allocated buffer or NULL if allocation fails.\r
304\r
305**/\r
306VOID *\r
307EFIAPI\r
308AllocateAlignedReservedPages (\r
309 IN UINTN Pages,\r
310 IN UINTN Alignment\r
311 )\r
312{\r
313 return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);\r
314}\r
315\r
316/**\r
317 Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
318 allocation functions in the Memory Allocation Library.\r
319\r
320 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
321 must have been allocated on a previous call to the aligned page allocation services of the Memory\r
322 Allocation Library.\r
323 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
324 Library, then ASSERT().\r
325 If Pages is zero, then ASSERT().\r
326 \r
327 @param Buffer Pointer to the buffer of pages to free.\r
328 @param Pages The number of 4 KB pages to free.\r
329\r
330**/\r
331VOID\r
332EFIAPI\r
333FreeAlignedPages (\r
334 IN VOID *Buffer,\r
335 IN UINTN Pages\r
336 )\r
337{\r
338 EFI_STATUS Status;\r
339\r
340 ASSERT (Pages != 0);\r
341 Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
342 ASSERT_EFI_ERROR (Status);\r
343}\r
344\r
345/**\r
346 Allocates a buffer of a certain pool type.\r
347\r
348 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a\r
349 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
350 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
351\r
352 @param MemoryType The type of memory to allocate.\r
353 @param AllocationSize The number of bytes to allocate.\r
354\r
355 @return A pointer to the allocated buffer or NULL if allocation fails.\r
356\r
357**/\r
358VOID *\r
359InternalAllocatePool (\r
360 IN EFI_MEMORY_TYPE MemoryType, \r
361 IN UINTN AllocationSize\r
362 )\r
363{\r
364 EFI_STATUS Status;\r
365 VOID *Memory;\r
366\r
367 Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory);\r
368 if (EFI_ERROR (Status)) {\r
369 Memory = NULL;\r
370 }\r
371 return Memory;\r
372}\r
373\r
374/**\r
375 Allocates a buffer of type EfiBootServicesData.\r
376\r
377 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
378 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
379 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
380\r
381 @param AllocationSize The number of bytes to allocate.\r
382\r
383 @return A pointer to the allocated buffer or NULL if allocation fails.\r
384\r
385**/\r
386VOID *\r
387EFIAPI\r
388AllocatePool (\r
389 IN UINTN AllocationSize\r
390 )\r
391{\r
392 return InternalAllocatePool (EfiBootServicesData, AllocationSize);\r
393}\r
394\r
395/**\r
396 Allocates a buffer of type EfiRuntimeServicesData.\r
397\r
398 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
399 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
400 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
401\r
402 @param AllocationSize The number of bytes to allocate.\r
403\r
404 @return A pointer to the allocated buffer or NULL if allocation fails.\r
405\r
406**/\r
407VOID *\r
408EFIAPI\r
409AllocateRuntimePool (\r
410 IN UINTN AllocationSize\r
411 )\r
412{\r
413 return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
414}\r
415\r
416/**\r
417 Allocates a buffer of type EfieservedMemoryType.\r
418\r
419 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns\r
420 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
421 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
422\r
423 @param AllocationSize The number of bytes to allocate.\r
424\r
425 @return A pointer to the allocated buffer or NULL if allocation fails.\r
426\r
427**/\r
428VOID *\r
429EFIAPI\r
430AllocateReservedPool (\r
431 IN UINTN AllocationSize\r
432 )\r
433{\r
434 return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
435}\r
436\r
437/**\r
438 Allocates and zeros a buffer of a certian pool type.\r
439\r
440 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
441 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid\r
442 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,\r
443 then NULL is returned.\r
444\r
445 @param PoolType The type of memory to allocate.\r
446 @param AllocationSize The number of bytes to allocate and zero.\r
447\r
448 @return A pointer to the allocated buffer or NULL if allocation fails.\r
449\r
450**/\r
451VOID *\r
452InternalAllocateZeroPool (\r
453 IN EFI_MEMORY_TYPE PoolType, \r
454 IN UINTN AllocationSize\r
455 ) \r
456{\r
457 VOID *Memory;\r
458\r
459 Memory = InternalAllocatePool (PoolType, AllocationSize);\r
460 if (Memory != NULL) {\r
461 Memory = ZeroMem (Memory, AllocationSize);\r
462 }\r
463 return Memory;\r
464}\r
465\r
466/**\r
467 Allocates and zeros a buffer of type EfiBootServicesData.\r
468\r
469 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
470 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
471 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
472 request, then NULL is returned.\r
473\r
474 @param AllocationSize The number of bytes to allocate and zero.\r
475\r
476 @return A pointer to the allocated buffer or NULL if allocation fails.\r
477\r
478**/\r
479VOID *\r
480EFIAPI\r
481AllocateZeroPool (\r
482 IN UINTN AllocationSize\r
483 )\r
484{\r
485 return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r
486}\r
487\r
488/**\r
489 Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
490\r
491 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
492 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
493 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
494 request, then NULL is returned.\r
495\r
496 @param AllocationSize The number of bytes to allocate and zero.\r
497\r
498 @return A pointer to the allocated buffer or NULL if allocation fails.\r
499\r
500**/\r
501VOID *\r
502EFIAPI\r
503AllocateRuntimeZeroPool (\r
504 IN UINTN AllocationSize\r
505 )\r
506{\r
507 return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
508}\r
509\r
510/**\r
511 Allocates and zeros a buffer of type EfiReservedMemoryType.\r
512\r
513 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
514 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
515 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
516 request, then NULL is returned.\r
517\r
518 @param AllocationSize The number of bytes to allocate and zero.\r
519\r
520 @return A pointer to the allocated buffer or NULL if allocation fails.\r
521\r
522**/\r
523VOID *\r
524EFIAPI\r
525AllocateReservedZeroPool (\r
526 IN UINTN AllocationSize\r
527 )\r
528{\r
529 return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
530}\r
531\r
532/**\r
533 Copies a buffer to an allocated buffer of a certian pool type.\r
534\r
535 Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
536 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
537 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
538 is not enough memory remaining to satisfy the request, then NULL is returned.\r
539 If Buffer is NULL, then ASSERT().\r
9e6fa6d2 540 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e386b444 541\r
542 @param PoolType The type of pool to allocate.\r
543 @param AllocationSize The number of bytes to allocate and zero.\r
544 @param Buffer The buffer to copy to the allocated buffer.\r
545\r
546 @return A pointer to the allocated buffer or NULL if allocation fails.\r
547\r
548**/\r
549VOID *\r
550InternalAllocateCopyPool (\r
551 IN EFI_MEMORY_TYPE PoolType, \r
552 IN UINTN AllocationSize,\r
553 IN CONST VOID *Buffer\r
554 ) \r
555{\r
556 VOID *Memory;\r
557\r
558 ASSERT (Buffer != NULL);\r
559 ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
560\r
561 Memory = InternalAllocatePool (PoolType, AllocationSize);\r
562 if (Memory != NULL) {\r
563 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
564 }\r
565 return Memory;\r
566} \r
567\r
568/**\r
569 Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
570\r
571 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
572 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
573 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
574 is not enough memory remaining to satisfy the request, then NULL is returned.\r
575 If Buffer is NULL, then ASSERT().\r
9e6fa6d2 576 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e386b444 577\r
578 @param AllocationSize The number of bytes to allocate and zero.\r
579 @param Buffer The buffer to copy to the allocated buffer.\r
580\r
581 @return A pointer to the allocated buffer or NULL if allocation fails.\r
582\r
583**/\r
584VOID *\r
585EFIAPI\r
586AllocateCopyPool (\r
587 IN UINTN AllocationSize,\r
588 IN CONST VOID *Buffer\r
589 )\r
590{\r
591 return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r
592}\r
593\r
594/**\r
595 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
596\r
597 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
598 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
599 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
600 is not enough memory remaining to satisfy the request, then NULL is returned.\r
601 If Buffer is NULL, then ASSERT().\r
9e6fa6d2 602 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e386b444 603\r
604 @param AllocationSize The number of bytes to allocate and zero.\r
605 @param Buffer The buffer to copy to the allocated buffer.\r
606\r
607 @return A pointer to the allocated buffer or NULL if allocation fails.\r
608\r
609**/\r
610VOID *\r
611EFIAPI\r
612AllocateRuntimeCopyPool (\r
613 IN UINTN AllocationSize,\r
614 IN CONST VOID *Buffer\r
615 )\r
616{\r
617 return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
618}\r
619\r
620/**\r
621 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
622\r
623 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
624 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
625 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
626 is not enough memory remaining to satisfy the request, then NULL is returned.\r
627 If Buffer is NULL, then ASSERT().\r
9e6fa6d2 628 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
e386b444 629\r
630 @param AllocationSize The number of bytes to allocate and zero.\r
631 @param Buffer The buffer to copy to the allocated buffer.\r
632\r
633 @return A pointer to the allocated buffer or NULL if allocation fails.\r
634\r
635**/\r
636VOID *\r
637EFIAPI\r
638AllocateReservedCopyPool (\r
639 IN UINTN AllocationSize,\r
640 IN CONST VOID *Buffer\r
641 )\r
642{\r
643 return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
644}\r
645\r
646/**\r
647 Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
648 Memory Allocation Library.\r
649\r
650 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r
651 pool allocation services of the Memory Allocation Library.\r
652 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
653 then ASSERT().\r
654\r
655 @param Buffer Pointer to the buffer to free.\r
656\r
657**/\r
658VOID\r
659EFIAPI\r
660FreePool (\r
661 IN VOID *Buffer\r
662 )\r
663{\r
664 EFI_STATUS Status;\r
665\r
666 Status = gBS->FreePool (Buffer);\r
667 ASSERT_EFI_ERROR (Status);\r
668}\r
669\r