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