]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/MemoryAllocationLib.h
2 Provides services to allocate and free memory buffers of various memory types and alignments.
4 The Memory Allocation Library abstracts various common memory allocation operations. This library
5 allows code to be written in a phase-independent manner because the allocation of memory in PEI, DXE,
6 and SMM (for example) is done via a different mechanism. Using a common library interface makes it
7 much easier to port algorithms from phase to phase.
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #ifndef __MEMORY_ALLOCATION_LIB_H__
15 #define __MEMORY_ALLOCATION_LIB_H__
18 Allocates one or more 4KB pages of type EfiBootServicesData.
20 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
21 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
22 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
25 @param Pages The number of 4 KB pages to allocate.
27 @return A pointer to the allocated buffer or NULL if allocation fails.
37 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
39 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
40 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
41 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
44 @param Pages The number of 4 KB pages to allocate.
46 @return A pointer to the allocated buffer or NULL if allocation fails.
51 AllocateRuntimePages (
56 Allocates one or more 4KB pages of type EfiReservedMemoryType.
58 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
59 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
60 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
63 @param Pages The number of 4 KB pages to allocate.
65 @return A pointer to the allocated buffer or NULL if allocation fails.
70 AllocateReservedPages (
75 Frees one or more 4KB pages that were previously allocated with one of the page allocation
76 functions in the Memory Allocation Library.
78 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
79 must have been allocated on a previous call to the page allocation services of the Memory
80 Allocation Library. If it is not possible to free allocated pages, then this function will
83 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
85 If Pages is zero, then ASSERT().
87 @param Buffer Pointer to the buffer of pages to free.
88 @param Pages The number of 4 KB pages to free.
99 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
101 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
102 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
103 returned. If there is not enough memory at the specified alignment remaining to satisfy the
104 request, then NULL is returned.
106 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
107 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
109 @param Pages The number of 4 KB pages to allocate.
110 @param Alignment The requested alignment of the allocation. Must be a power of two.
111 If Alignment is zero, then byte alignment is used.
113 @return A pointer to the allocated buffer or NULL if allocation fails.
118 AllocateAlignedPages (
124 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
126 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
127 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
128 returned. If there is not enough memory at the specified alignment remaining to satisfy the
129 request, then NULL is returned.
131 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
132 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
134 @param Pages The number of 4 KB pages to allocate.
135 @param Alignment The requested alignment of the allocation. Must be a power of two.
136 If Alignment is zero, then byte alignment is used.
138 @return A pointer to the allocated buffer or NULL if allocation fails.
143 AllocateAlignedRuntimePages (
149 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
151 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
152 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
153 returned. If there is not enough memory at the specified alignment remaining to satisfy the
154 request, then NULL is returned.
156 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
157 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
159 @param Pages The number of 4 KB pages to allocate.
160 @param Alignment The requested alignment of the allocation. Must be a power of two.
161 If Alignment is zero, then byte alignment is used.
163 @return A pointer to the allocated buffer or NULL if allocation fails.
168 AllocateAlignedReservedPages (
174 Frees one or more 4KB pages that were previously allocated with one of the aligned page
175 allocation functions in the Memory Allocation Library.
177 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
178 must have been allocated on a previous call to the aligned page allocation services of the Memory
179 Allocation Library. If it is not possible to free allocated pages, then this function will
182 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
183 Library, then ASSERT().
184 If Pages is zero, then ASSERT().
186 @param Buffer Pointer to the buffer of pages to free.
187 @param Pages The number of 4 KB pages to free.
198 Allocates a buffer of type EfiBootServicesData.
200 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
201 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
202 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
204 @param AllocationSize The number of bytes to allocate.
206 @return A pointer to the allocated buffer or NULL if allocation fails.
212 IN UINTN AllocationSize
216 Allocates a buffer of type EfiRuntimeServicesData.
218 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
219 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
220 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
222 @param AllocationSize The number of bytes to allocate.
224 @return A pointer to the allocated buffer or NULL if allocation fails.
229 AllocateRuntimePool (
230 IN UINTN AllocationSize
234 Allocates a buffer of type EfiReservedMemoryType.
236 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
237 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
238 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
240 @param AllocationSize The number of bytes to allocate.
242 @return A pointer to the allocated buffer or NULL if allocation fails.
247 AllocateReservedPool (
248 IN UINTN AllocationSize
252 Allocates and zeros a buffer of type EfiBootServicesData.
254 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
255 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
256 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
257 request, then NULL is returned.
259 @param AllocationSize The number of bytes to allocate and zero.
261 @return A pointer to the allocated buffer or NULL if allocation fails.
267 IN UINTN AllocationSize
271 Allocates and zeros a buffer of type EfiRuntimeServicesData.
273 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
274 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
275 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
276 request, then NULL is returned.
278 @param AllocationSize The number of bytes to allocate and zero.
280 @return A pointer to the allocated buffer or NULL if allocation fails.
285 AllocateRuntimeZeroPool (
286 IN UINTN AllocationSize
290 Allocates and zeros a buffer of type EfiReservedMemoryType.
292 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
293 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
294 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
295 request, then NULL is returned.
297 @param AllocationSize The number of bytes to allocate and zero.
299 @return A pointer to the allocated buffer or NULL if allocation fails.
304 AllocateReservedZeroPool (
305 IN UINTN AllocationSize
309 Copies a buffer to an allocated buffer of type EfiBootServicesData.
311 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
312 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
313 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
314 is not enough memory remaining to satisfy the request, then NULL is returned.
316 If Buffer is NULL, then ASSERT().
317 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
319 @param AllocationSize The number of bytes to allocate and zero.
320 @param Buffer The buffer to copy to the allocated buffer.
322 @return A pointer to the allocated buffer or NULL if allocation fails.
328 IN UINTN AllocationSize
,
329 IN CONST VOID
*Buffer
333 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
335 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
336 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
337 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
338 is not enough memory remaining to satisfy the request, then NULL is returned.
340 If Buffer is NULL, then ASSERT().
341 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
343 @param AllocationSize The number of bytes to allocate and zero.
344 @param Buffer The buffer to copy to the allocated buffer.
346 @return A pointer to the allocated buffer or NULL if allocation fails.
351 AllocateRuntimeCopyPool (
352 IN UINTN AllocationSize
,
353 IN CONST VOID
*Buffer
357 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
359 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
360 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
361 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
362 is not enough memory remaining to satisfy the request, then NULL is returned.
364 If Buffer is NULL, then ASSERT().
365 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
367 @param AllocationSize The number of bytes to allocate and zero.
368 @param Buffer The buffer to copy to the allocated buffer.
370 @return A pointer to the allocated buffer or NULL if allocation fails.
375 AllocateReservedCopyPool (
376 IN UINTN AllocationSize
,
377 IN CONST VOID
*Buffer
381 Reallocates a buffer of type EfiBootServicesData.
383 Allocates and zeros the number bytes specified by NewSize from memory of type
384 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
385 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
386 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
387 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
388 enough memory remaining to satisfy the request, then NULL is returned.
390 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
391 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
393 @param OldSize The size, in bytes, of OldBuffer.
394 @param NewSize The size, in bytes, of the buffer to reallocate.
395 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
396 parameter that may be NULL.
398 @return A pointer to the allocated buffer or NULL if allocation fails.
406 IN VOID
*OldBuffer OPTIONAL
410 Reallocates a buffer of type EfiRuntimeServicesData.
412 Allocates and zeros the number bytes specified by NewSize from memory of type
413 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
414 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
415 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
416 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
417 enough memory remaining to satisfy the request, then NULL is returned.
419 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
420 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
422 @param OldSize The size, in bytes, of OldBuffer.
423 @param NewSize The size, in bytes, of the buffer to reallocate.
424 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
425 parameter that may be NULL.
427 @return A pointer to the allocated buffer or NULL if allocation fails.
432 ReallocateRuntimePool (
435 IN VOID
*OldBuffer OPTIONAL
439 Reallocates a buffer of type EfiReservedMemoryType.
441 Allocates and zeros the number bytes specified by NewSize from memory of type
442 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
443 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
444 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
445 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
446 enough memory remaining to satisfy the request, then NULL is returned.
448 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
449 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
451 @param OldSize The size, in bytes, of OldBuffer.
452 @param NewSize The size, in bytes, of the buffer to reallocate.
453 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
454 parameter that may be NULL.
456 @return A pointer to the allocated buffer or NULL if allocation fails.
461 ReallocateReservedPool (
464 IN VOID
*OldBuffer OPTIONAL
468 Frees a buffer that was previously allocated with one of the pool allocation functions in the
469 Memory Allocation Library.
471 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
472 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
473 resources, then this function will perform no actions.
475 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
478 @param Buffer Pointer to the buffer to free.