]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/MemoryAllocationLib.h
Comments have been checked with spec
[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
50a64e5b 9Copyright (c) 2006 - 2008, Intel Corporation\r
10All rights reserved. This program and the accompanying materials\r
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
86 Allocation Library.\r
8789c5e0 87 \r
fb3df220 88 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
89 then ASSERT().\r
90 If Pages is zero, then ASSERT().\r
91 \r
92 @param Buffer Pointer to the buffer of pages to free.\r
93 @param Pages The number of 4 KB pages to free.\r
94\r
95**/\r
96VOID\r
97EFIAPI\r
98FreePages (\r
99 IN VOID *Buffer,\r
100 IN UINTN Pages\r
101 );\r
102\r
103/**\r
104 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.\r
105\r
106 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an\r
107 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
108 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
109 request, then NULL is returned.\r
8789c5e0 110 \r
fb3df220 111 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
112\r
113 @param Pages The number of 4 KB pages to allocate.\r
114 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
115 If Alignment is zero, then byte alignment is used.\r
116\r
117 @return A pointer to the allocated buffer or NULL if allocation fails.\r
118\r
119**/\r
120VOID *\r
121EFIAPI\r
122AllocateAlignedPages (\r
123 IN UINTN Pages,\r
124 IN UINTN Alignment\r
125 );\r
126\r
127/**\r
128 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.\r
129\r
130 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an\r
131 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
132 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
133 request, then NULL is returned.\r
8789c5e0 134 \r
fb3df220 135 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
136\r
137 @param Pages The number of 4 KB pages to allocate.\r
138 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
139 If Alignment is zero, then byte alignment is used.\r
140\r
141 @return A pointer to the allocated buffer or NULL if allocation fails.\r
142\r
143**/\r
144VOID *\r
145EFIAPI\r
146AllocateAlignedRuntimePages (\r
147 IN UINTN Pages,\r
148 IN UINTN Alignment\r
149 );\r
150\r
151/**\r
152 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.\r
153\r
154 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an\r
155 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is\r
156 returned. If there is not enough memory at the specified alignment remaining to satisfy the\r
157 request, then NULL is returned.\r
8789c5e0 158 \r
fb3df220 159 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
160\r
161 @param Pages The number of 4 KB pages to allocate.\r
162 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
163 If Alignment is zero, then byte alignment is used.\r
164\r
165 @return A pointer to the allocated buffer or NULL if allocation fails.\r
166\r
167**/\r
168VOID *\r
169EFIAPI\r
170AllocateAlignedReservedPages (\r
171 IN UINTN Pages,\r
172 IN UINTN Alignment\r
173 );\r
174\r
175/**\r
176 Frees one or more 4KB pages that were previously allocated with one of the aligned page\r
177 allocation functions in the Memory Allocation Library.\r
178\r
179 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer\r
180 must have been allocated on a previous call to the aligned page allocation services of the Memory\r
181 Allocation Library.\r
8789c5e0 182 \r
fb3df220 183 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
184 Library, then ASSERT().\r
185 If Pages is zero, then ASSERT().\r
186 \r
187 @param Buffer Pointer to the buffer of pages to free.\r
188 @param Pages The number of 4 KB pages to free.\r
189\r
190**/\r
191VOID\r
192EFIAPI\r
193FreeAlignedPages (\r
194 IN VOID *Buffer,\r
195 IN UINTN Pages\r
196 );\r
197\r
198/**\r
199 Allocates a buffer of type EfiBootServicesData.\r
200\r
201 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r
202 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
203 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
204\r
205 @param AllocationSize The number of bytes to allocate.\r
206\r
207 @return A pointer to the allocated buffer or NULL if allocation fails.\r
208\r
209**/\r
210VOID *\r
211EFIAPI\r
212AllocatePool (\r
213 IN UINTN AllocationSize\r
214 );\r
215\r
216/**\r
217 Allocates a buffer of type EfiRuntimeServicesData.\r
218\r
219 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns\r
220 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
221 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
222\r
223 @param AllocationSize The number of bytes to allocate.\r
224\r
225 @return A pointer to the allocated buffer or NULL if allocation fails.\r
226\r
227**/\r
228VOID *\r
229EFIAPI\r
230AllocateRuntimePool (\r
231 IN UINTN AllocationSize\r
232 );\r
233\r
234/**\r
8789c5e0 235 Allocates a buffer of type EfiReservedMemoryType.\r
fb3df220 236\r
8789c5e0 237 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns\r
fb3df220 238 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r
239 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r
240\r
241 @param AllocationSize The number of bytes to allocate.\r
242\r
243 @return A pointer to the allocated buffer or NULL if allocation fails.\r
244\r
245**/\r
246VOID *\r
247EFIAPI\r
248AllocateReservedPool (\r
249 IN UINTN AllocationSize\r
250 );\r
251\r
252/**\r
253 Allocates and zeros a buffer of type EfiBootServicesData.\r
254\r
255 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r
256 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
257 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
258 request, then NULL is returned.\r
259\r
260 @param AllocationSize The number of bytes to allocate and zero.\r
261\r
262 @return A pointer to the allocated buffer or NULL if allocation fails.\r
263\r
264**/\r
265VOID *\r
266EFIAPI\r
267AllocateZeroPool (\r
268 IN UINTN AllocationSize\r
269 );\r
270\r
271/**\r
272 Allocates and zeros a buffer of type EfiRuntimeServicesData.\r
273\r
274 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the\r
275 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
276 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
277 request, then NULL is returned.\r
278\r
279 @param AllocationSize The number of bytes to allocate and zero.\r
280\r
281 @return A pointer to the allocated buffer or NULL if allocation fails.\r
282\r
283**/\r
284VOID *\r
285EFIAPI\r
286AllocateRuntimeZeroPool (\r
287 IN UINTN AllocationSize\r
288 );\r
289\r
290/**\r
291 Allocates and zeros a buffer of type EfiReservedMemoryType.\r
292\r
293 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the\r
294 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r
295 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r
296 request, then NULL is returned.\r
297\r
298 @param AllocationSize The number of bytes to allocate and zero.\r
299\r
300 @return A pointer to the allocated buffer or NULL if allocation fails.\r
301\r
302**/\r
303VOID *\r
304EFIAPI\r
305AllocateReservedZeroPool (\r
306 IN UINTN AllocationSize\r
307 );\r
308\r
309/**\r
310 Copies a buffer to an allocated buffer of type EfiBootServicesData.\r
311\r
312 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies\r
313 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
314 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
315 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 316 \r
fb3df220 317 If Buffer is NULL, then ASSERT().\r
cc4e0485 318 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 319\r
320 @param AllocationSize The number of bytes to allocate and zero.\r
321 @param Buffer The buffer to copy to the allocated buffer.\r
322\r
323 @return A pointer to the allocated buffer or NULL if allocation fails.\r
324\r
325**/\r
326VOID *\r
327EFIAPI\r
328AllocateCopyPool (\r
329 IN UINTN AllocationSize,\r
330 IN CONST VOID *Buffer\r
331 );\r
332\r
333/**\r
334 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.\r
335\r
336 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies\r
337 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
338 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
339 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 340 \r
fb3df220 341 If Buffer is NULL, then ASSERT().\r
cc4e0485 342 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 343\r
344 @param AllocationSize The number of bytes to allocate and zero.\r
345 @param Buffer The buffer to copy to the allocated buffer.\r
346\r
347 @return A pointer to the allocated buffer or NULL if allocation fails.\r
348\r
349**/\r
350VOID *\r
351EFIAPI\r
352AllocateRuntimeCopyPool (\r
353 IN UINTN AllocationSize,\r
354 IN CONST VOID *Buffer\r
355 );\r
356\r
357/**\r
358 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.\r
359\r
360 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies\r
361 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
362 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
363 is not enough memory remaining to satisfy the request, then NULL is returned.\r
8789c5e0 364 \r
fb3df220 365 If Buffer is NULL, then ASSERT().\r
cc4e0485 366 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
fb3df220 367\r
368 @param AllocationSize The number of bytes to allocate and zero.\r
369 @param Buffer The buffer to copy to the allocated buffer.\r
370\r
371 @return A pointer to the allocated buffer or NULL if allocation fails.\r
372\r
373**/\r
374VOID *\r
375EFIAPI\r
376AllocateReservedCopyPool (\r
377 IN UINTN AllocationSize,\r
378 IN CONST VOID *Buffer\r
379 );\r
380\r
c2390431 381/**\r
382 Reallocates a buffer of type EfiBootServicesData.\r
383\r
ab95d5f2 384 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 385 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
386 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
387 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
388 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
389 enough memory remaining to satisfy the request, then NULL is returned.\r
390 \r
c2390431 391 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
392 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
393\r
394 @param OldSize The size, in bytes, of OldBuffer.\r
395 @param NewSize The size, in bytes, of the buffer to reallocate.\r
396 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
397 parameter that may be NULL.\r
398\r
399 @return A pointer to the allocated buffer or NULL if allocation fails.\r
400\r
401**/\r
402VOID *\r
403EFIAPI\r
404ReallocatePool (\r
405 IN UINTN OldSize,\r
406 IN UINTN NewSize,\r
407 IN VOID *OldBuffer OPTIONAL\r
408 );\r
409\r
410/**\r
411 Reallocates a buffer of type EfiRuntimeServicesData.\r
412\r
ab95d5f2 413 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 414 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and \r
415 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
416 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
417 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
418 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 419\r
c2390431 420 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
421 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
422\r
423 @param OldSize The size, in bytes, of OldBuffer.\r
424 @param NewSize The size, in bytes, of the buffer to reallocate.\r
425 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
426 parameter that may be NULL.\r
427\r
428 @return A pointer to the allocated buffer or NULL if allocation fails.\r
429\r
430**/\r
431VOID *\r
432EFIAPI\r
433ReallocateRuntimePool (\r
434 IN UINTN OldSize,\r
435 IN UINTN NewSize,\r
436 IN VOID *OldBuffer OPTIONAL\r
437 );\r
438\r
439/**\r
440 Reallocates a buffer of type EfiReservedMemoryType.\r
441\r
ab95d5f2 442 Allocates and zeros the number bytes specified by NewSize from memory of type\r
c2390431 443 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and \r
444 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and \r
445 OldBuffer is freed. A pointer to the newly allocated buffer is returned. \r
446 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not \r
447 enough memory remaining to satisfy the request, then NULL is returned.\r
2297186d 448\r
c2390431 449 If NewSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
450 If OldSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
451\r
452 @param OldSize The size, in bytes, of OldBuffer.\r
453 @param NewSize The size, in bytes, of the buffer to reallocate.\r
454 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional \r
455 parameter that may be NULL.\r
456\r
457 @return A pointer to the allocated buffer or NULL if allocation fails.\r
458\r
459**/\r
460VOID *\r
461EFIAPI\r
462ReallocateReservedPool (\r
463 IN UINTN OldSize,\r
464 IN UINTN NewSize,\r
465 IN VOID *OldBuffer OPTIONAL\r
466 );\r
467\r
fb3df220 468/**\r
469 Frees a buffer that was previously allocated with one of the pool allocation functions in the\r
470 Memory Allocation Library.\r
471\r
472 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r
473 pool allocation services of the Memory Allocation Library.\r
8789c5e0 474 \r
fb3df220 475 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
476 then ASSERT().\r
477\r
478 @param Buffer Pointer to the buffer to free.\r
479\r
480**/\r
481VOID\r
482EFIAPI\r
483FreePool (\r
484 IN VOID *Buffer\r
485 );\r
486\r
fb3df220 487#endif\r