]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/MemoryAllocationLib.h
Add 2 functions to UefiLib library class: CatSPrint and CatVSPrint.
[mirror_edk2.git] / MdePkg / Include / Library / MemoryAllocationLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to allocate and free memory buffers of various memory types and alignments.\r
8789c5e0 3 \r
4 The Memory Allocation Library abstracts various common memory allocation operations. This library \r
5 allows code to be written in a phase-independent manner because the allocation of memory in PEI, DXE, \r
6 and SMM (for example) is done via a different mechanism. Using a common library interface makes it \r
7 much easier to port algorithms from phase to phase. \r
8 \r
9df063a0
HT
9Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
10This program and the accompanying materials\r
50a64e5b 11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
fb3df220 14\r
50a64e5b 15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
fb3df220 17\r
fb3df220 18**/\r
19\r
20#ifndef __MEMORY_ALLOCATION_LIB_H__\r
21#define __MEMORY_ALLOCATION_LIB_H__\r
22\r
23/**\r
24 Allocates one or more 4KB pages of type EfiBootServicesData.\r
25\r
26 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the\r
27 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
28 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
29 returned.\r
30\r
31 @param Pages The number of 4 KB pages to allocate.\r
32\r
33 @return A pointer to the allocated buffer or NULL if allocation fails.\r
34\r
35**/\r
36VOID *\r
37EFIAPI\r
38AllocatePages (\r
39 IN UINTN Pages\r
40 );\r
41\r
42/**\r
43 Allocates one or more 4KB pages of type EfiRuntimeServicesData.\r
44\r
45 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
46 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
47 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
48 returned.\r
49\r
50 @param Pages The number of 4 KB pages to allocate.\r
51\r
52 @return A pointer to the allocated buffer or NULL if allocation fails.\r
53\r
54**/\r
55VOID *\r
56EFIAPI\r
57AllocateRuntimePages (\r
58 IN UINTN Pages\r
59 );\r
60\r
61/**\r
62 Allocates one or more 4KB pages of type EfiReservedMemoryType.\r
63\r
64 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the\r
65 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
66 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
67 returned.\r
68\r
69 @param Pages The number of 4 KB pages to allocate.\r
70\r
71 @return A pointer to the allocated buffer or NULL if allocation fails.\r
72\r
73**/\r
74VOID *\r
75EFIAPI\r
76AllocateReservedPages (\r
77 IN UINTN Pages\r
78 );\r
79\r
80/**\r
81 Frees one or more 4KB pages that were previously allocated with one of the page allocation\r
82 functions in the Memory Allocation Library.\r
83\r
84 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
85 must have been allocated on a previous call to the page allocation services of the Memory\r
6e10b70a 86 Allocation Library. If it is not possible to free allocated pages, then this function will\r
446b94b0 87 perform no actions.\r
8789c5e0 88 \r
fb3df220 89 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
90 then ASSERT().\r
91 If Pages is zero, then ASSERT().\r
92 \r
93 @param Buffer Pointer to the buffer of pages to free.\r
94 @param Pages The number of 4 KB pages to free.\r
95\r
96**/\r
97VOID\r
98EFIAPI\r
99FreePages (\r
100 IN VOID *Buffer,\r
101 IN UINTN Pages\r
102 );\r
103\r
104/**\r
105 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
106\r
107 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
108 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
109 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
110 request, then NULL is returned.\r
8789c5e0 111 \r
fb3df220 112 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
113\r
114 @param Pages The number of 4 KB pages to allocate.\r
115 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
116 If Alignment is zero, then byte alignment is used.\r
117\r
118 @return A pointer to the allocated buffer or NULL if allocation fails.\r
119\r
120**/\r
121VOID *\r
122EFIAPI\r
123AllocateAlignedPages (\r
124 IN UINTN Pages,\r
125 IN UINTN Alignment\r
126 );\r
127\r
128/**\r
129 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
130\r
131 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
132 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
133 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
134 request, then NULL is returned.\r
8789c5e0 135 \r
fb3df220 136 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
137\r
138 @param Pages The number of 4 KB pages to allocate.\r
139 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
140 If Alignment is zero, then byte alignment is used.\r
141\r
142 @return A pointer to the allocated buffer or NULL if allocation fails.\r
143\r
144**/\r
145VOID *\r
146EFIAPI\r
147AllocateAlignedRuntimePages (\r
148 IN UINTN Pages,\r
149 IN UINTN Alignment\r
150 );\r
151\r
152/**\r
153 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
154\r
155 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
156 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
157 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
158 request, then NULL is returned.\r
8789c5e0 159 \r
fb3df220 160 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
161\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
170EFIAPI\r
171AllocateAlignedReservedPages (\r
172 IN UINTN Pages,\r
173 IN UINTN Alignment\r
174 );\r
175\r
176/**\r
177 Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
178 allocation functions in the Memory Allocation Library.\r
179\r
180 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
181 must have been allocated on a previous call to the aligned page allocation services of the Memory\r
6e10b70a 182 Allocation Library. If it is not possible to free allocated pages, then this function will \r
446b94b0 183 perform no actions.\r
8789c5e0 184 \r
fb3df220 185 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
186 Library, then ASSERT().\r
187 If Pages is zero, then ASSERT().\r
188 \r
189 @param Buffer Pointer to the buffer of pages to free.\r
190 @param Pages The number of 4 KB pages to free.\r
191\r
192**/\r
193VOID\r
194EFIAPI\r
195FreeAlignedPages (\r
196 IN VOID *Buffer,\r
197 IN UINTN Pages\r
198 );\r
199\r
200/**\r
201 Allocates a buffer of type EfiBootServicesData.\r
202\r
203 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
204 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
205 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
206\r
207 @param AllocationSize The number of bytes to allocate.\r
208\r
209 @return A pointer to the allocated buffer or NULL if allocation fails.\r
210\r
211**/\r
212VOID *\r
213EFIAPI\r
214AllocatePool (\r
215 IN UINTN AllocationSize\r
216 );\r
217\r
218/**\r
219 Allocates a buffer of type EfiRuntimeServicesData.\r
220\r
221 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
222 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
223 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
224\r
225 @param AllocationSize The number of bytes to allocate.\r
226\r
227 @return A pointer to the allocated buffer or NULL if allocation fails.\r
228\r
229**/\r
230VOID *\r
231EFIAPI\r
232AllocateRuntimePool (\r
233 IN UINTN AllocationSize\r
234 );\r
235\r
236/**\r
8789c5e0 237 Allocates a buffer of type EfiReservedMemoryType.\r
fb3df220 238\r
8789c5e0 239 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns\r
fb3df220 240 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
241 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
242\r
243 @param AllocationSize The number of bytes to allocate.\r
244\r
245 @return A pointer to the allocated buffer or NULL if allocation fails.\r
246\r
247**/\r
248VOID *\r
249EFIAPI\r
250AllocateReservedPool (\r
251 IN UINTN AllocationSize\r
252 );\r
253\r
254/**\r
255 Allocates and zeros a buffer of type EfiBootServicesData.\r
256\r
257 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
258 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
259 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
260 request, then NULL is returned.\r
261\r
262 @param AllocationSize The number of bytes to allocate and zero.\r
263\r
264 @return A pointer to the allocated buffer or NULL if allocation fails.\r
265\r
266**/\r
267VOID *\r
268EFIAPI\r
269AllocateZeroPool (\r
270 IN UINTN AllocationSize\r
271 );\r
272\r
273/**\r
274 Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
275\r
276 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
277 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
278 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
279 request, then NULL is returned.\r
280\r
281 @param AllocationSize The number of bytes to allocate and zero.\r
282\r
283 @return A pointer to the allocated buffer or NULL if allocation fails.\r
284\r
285**/\r
286VOID *\r
287EFIAPI\r
288AllocateRuntimeZeroPool (\r
289 IN UINTN AllocationSize\r
290 );\r
291\r
292/**\r
293 Allocates and zeros a buffer of type EfiReservedMemoryType.\r
294\r
295 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
296 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
297 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
298 request, then NULL is returned.\r
299\r
300 @param AllocationSize The number of bytes to allocate and zero.\r
301\r
302 @return A pointer to the allocated buffer or NULL if allocation fails.\r
303\r
304**/\r
305VOID *\r
306EFIAPI\r
307AllocateReservedZeroPool (\r
308 IN UINTN AllocationSize\r
309 );\r
310\r
311/**\r
312 Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
313\r
314 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
315 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
316 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
317 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 318 \r
fb3df220 319 If Buffer is NULL, then ASSERT().\r
cc4e0485 320 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 321\r
322 @param AllocationSize The number of bytes to allocate and zero.\r
323 @param Buffer The buffer to copy to the allocated buffer.\r
324\r
325 @return A pointer to the allocated buffer or NULL if allocation fails.\r
326\r
327**/\r
328VOID *\r
329EFIAPI\r
330AllocateCopyPool (\r
331 IN UINTN AllocationSize,\r
332 IN CONST VOID *Buffer\r
333 );\r
334\r
335/**\r
336 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
337\r
338 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
339 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
340 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
341 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 342 \r
fb3df220 343 If Buffer is NULL, then ASSERT().\r
cc4e0485 344 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 345\r
346 @param AllocationSize The number of bytes to allocate and zero.\r
347 @param Buffer The buffer to copy to the allocated buffer.\r
348\r
349 @return A pointer to the allocated buffer or NULL if allocation fails.\r
350\r
351**/\r
352VOID *\r
353EFIAPI\r
354AllocateRuntimeCopyPool (\r
355 IN UINTN AllocationSize,\r
356 IN CONST VOID *Buffer\r
357 );\r
358\r
359/**\r
360 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
361\r
362 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
363 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
364 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
365 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 366 \r
fb3df220 367 If Buffer is NULL, then ASSERT().\r
cc4e0485 368 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 369\r
370 @param AllocationSize The number of bytes to allocate and zero.\r
371 @param Buffer The buffer to copy to the allocated buffer.\r
372\r
373 @return A pointer to the allocated buffer or NULL if allocation fails.\r
374\r
375**/\r
376VOID *\r
377EFIAPI\r
378AllocateReservedCopyPool (\r
379 IN UINTN AllocationSize,\r
380 IN CONST VOID *Buffer\r
381 );\r
382\r
c2390431 383/**\r
384 Reallocates a buffer of type EfiBootServicesData.\r
385\r
ab95d5f2 386 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 387 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
388 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
389 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
390 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
391 enough memory remaining to satisfy the request, then NULL is returned.\r
392 \r
56304569 393 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
394 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 395\r
396 @param OldSize The size, in bytes, of OldBuffer.\r
397 @param NewSize The size, in bytes, of the buffer to reallocate.\r
398 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
399 parameter that may be NULL.\r
400\r
401 @return A pointer to the allocated buffer or NULL if allocation fails.\r
402\r
403**/\r
404VOID *\r
405EFIAPI\r
406ReallocatePool (\r
407 IN UINTN OldSize,\r
408 IN UINTN NewSize,\r
409 IN VOID *OldBuffer OPTIONAL\r
410 );\r
411\r
412/**\r
413 Reallocates a buffer of type EfiRuntimeServicesData.\r
414\r
ab95d5f2 415 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 416 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
417 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
418 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
419 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
420 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 421\r
56304569 422 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
423 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 424\r
425 @param OldSize The size, in bytes, of OldBuffer.\r
426 @param NewSize The size, in bytes, of the buffer to reallocate.\r
427 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
428 parameter that may be NULL.\r
429\r
430 @return A pointer to the allocated buffer or NULL if allocation fails.\r
431\r
432**/\r
433VOID *\r
434EFIAPI\r
435ReallocateRuntimePool (\r
436 IN UINTN OldSize,\r
437 IN UINTN NewSize,\r
438 IN VOID *OldBuffer OPTIONAL\r
439 );\r
440\r
441/**\r
442 Reallocates a buffer of type EfiReservedMemoryType.\r
443\r
ab95d5f2 444 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 445 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and \r
446 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
447 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
448 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
449 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 450\r
56304569 451 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r
452 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r
c2390431 453\r
454 @param OldSize The size, in bytes, of OldBuffer.\r
455 @param NewSize The size, in bytes, of the buffer to reallocate.\r
456 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
457 parameter that may be NULL.\r
458\r
459 @return A pointer to the allocated buffer or NULL if allocation fails.\r
460\r
461**/\r
462VOID *\r
463EFIAPI\r
464ReallocateReservedPool (\r
465 IN UINTN OldSize,\r
466 IN UINTN NewSize,\r
467 IN VOID *OldBuffer OPTIONAL\r
468 );\r
469\r
fb3df220 470/**\r
471 Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
472 Memory Allocation Library.\r
473\r
474 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r
6e10b70a 475 pool allocation services of the Memory Allocation Library. If it is not possible to free pool\r
446b94b0 476 resources, then this function will perform no actions.\r
8789c5e0 477 \r
fb3df220 478 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
479 then ASSERT().\r
480\r
481 @param Buffer Pointer to the buffer to free.\r
482\r
483**/\r
484VOID\r
485EFIAPI\r
486FreePool (\r
487 IN VOID *Buffer\r
488 );\r
489\r
fb3df220 490#endif\r