]>
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 - 2013, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #ifndef __MEMORY_ALLOCATION_LIB_H__
21 #define __MEMORY_ALLOCATION_LIB_H__
24 Allocates one or more 4KB pages of type EfiBootServicesData.
26 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
27 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
28 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
31 @param Pages The number of 4 KB pages to allocate.
33 @return A pointer to the allocated buffer or NULL if allocation fails.
43 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
45 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
46 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
47 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
50 @param Pages The number of 4 KB pages to allocate.
52 @return A pointer to the allocated buffer or NULL if allocation fails.
57 AllocateRuntimePages (
62 Allocates one or more 4KB pages of type EfiReservedMemoryType.
64 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
65 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
66 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
69 @param Pages The number of 4 KB pages to allocate.
71 @return A pointer to the allocated buffer or NULL if allocation fails.
76 AllocateReservedPages (
81 Frees one or more 4KB pages that were previously allocated with one of the page allocation
82 functions in the Memory Allocation Library.
84 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
85 must have been allocated on a previous call to the page allocation services of the Memory
86 Allocation Library. If it is not possible to free allocated pages, then this function will
89 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
91 If Pages is zero, then ASSERT().
93 @param Buffer Pointer to the buffer of pages to free.
94 @param Pages The number of 4 KB pages to free.
105 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
107 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
108 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
109 returned. If there is not enough memory at the specified alignment remaining to satisfy the
110 request, then NULL is returned.
112 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
113 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
115 @param Pages The number of 4 KB pages to allocate.
116 @param Alignment The requested alignment of the allocation. Must be a power of two.
117 If Alignment is zero, then byte alignment is used.
119 @return A pointer to the allocated buffer or NULL if allocation fails.
124 AllocateAlignedPages (
130 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
132 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
133 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
134 returned. If there is not enough memory at the specified alignment remaining to satisfy the
135 request, then NULL is returned.
137 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
138 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
140 @param Pages The number of 4 KB pages to allocate.
141 @param Alignment The requested alignment of the allocation. Must be a power of two.
142 If Alignment is zero, then byte alignment is used.
144 @return A pointer to the allocated buffer or NULL if allocation fails.
149 AllocateAlignedRuntimePages (
155 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
157 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
158 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
159 returned. If there is not enough memory at the specified alignment remaining to satisfy the
160 request, then NULL is returned.
162 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
163 If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
165 @param Pages The number of 4 KB pages to allocate.
166 @param Alignment The requested alignment of the allocation. Must be a power of two.
167 If Alignment is zero, then byte alignment is used.
169 @return A pointer to the allocated buffer or NULL if allocation fails.
174 AllocateAlignedReservedPages (
180 Frees one or more 4KB pages that were previously allocated with one of the aligned page
181 allocation functions in the Memory Allocation Library.
183 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
184 must have been allocated on a previous call to the aligned page allocation services of the Memory
185 Allocation Library. If it is not possible to free allocated pages, then this function will
188 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
189 Library, then ASSERT().
190 If Pages is zero, then ASSERT().
192 @param Buffer Pointer to the buffer of pages to free.
193 @param Pages The number of 4 KB pages to free.
204 Allocates a buffer of type EfiBootServicesData.
206 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
207 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
208 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
210 @param AllocationSize The number of bytes to allocate.
212 @return A pointer to the allocated buffer or NULL if allocation fails.
218 IN UINTN AllocationSize
222 Allocates a buffer of type EfiRuntimeServicesData.
224 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
225 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
226 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
228 @param AllocationSize The number of bytes to allocate.
230 @return A pointer to the allocated buffer or NULL if allocation fails.
235 AllocateRuntimePool (
236 IN UINTN AllocationSize
240 Allocates a buffer of type EfiReservedMemoryType.
242 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
243 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
244 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
246 @param AllocationSize The number of bytes to allocate.
248 @return A pointer to the allocated buffer or NULL if allocation fails.
253 AllocateReservedPool (
254 IN UINTN AllocationSize
258 Allocates and zeros a buffer of type EfiBootServicesData.
260 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
261 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
262 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
263 request, then NULL is returned.
265 @param AllocationSize The number of bytes to allocate and zero.
267 @return A pointer to the allocated buffer or NULL if allocation fails.
273 IN UINTN AllocationSize
277 Allocates and zeros a buffer of type EfiRuntimeServicesData.
279 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
280 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
281 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
282 request, then NULL is returned.
284 @param AllocationSize The number of bytes to allocate and zero.
286 @return A pointer to the allocated buffer or NULL if allocation fails.
291 AllocateRuntimeZeroPool (
292 IN UINTN AllocationSize
296 Allocates and zeros a buffer of type EfiReservedMemoryType.
298 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
299 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
300 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
301 request, then NULL is returned.
303 @param AllocationSize The number of bytes to allocate and zero.
305 @return A pointer to the allocated buffer or NULL if allocation fails.
310 AllocateReservedZeroPool (
311 IN UINTN AllocationSize
315 Copies a buffer to an allocated buffer of type EfiBootServicesData.
317 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
318 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
319 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
320 is not enough memory remaining to satisfy the request, then NULL is returned.
322 If Buffer is NULL, then ASSERT().
323 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
325 @param AllocationSize The number of bytes to allocate and zero.
326 @param Buffer The buffer to copy to the allocated buffer.
328 @return A pointer to the allocated buffer or NULL if allocation fails.
334 IN UINTN AllocationSize
,
335 IN CONST VOID
*Buffer
339 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
341 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
342 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
343 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
344 is not enough memory remaining to satisfy the request, then NULL is returned.
346 If Buffer is NULL, then ASSERT().
347 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
349 @param AllocationSize The number of bytes to allocate and zero.
350 @param Buffer The buffer to copy to the allocated buffer.
352 @return A pointer to the allocated buffer or NULL if allocation fails.
357 AllocateRuntimeCopyPool (
358 IN UINTN AllocationSize
,
359 IN CONST VOID
*Buffer
363 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
365 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
366 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
367 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
368 is not enough memory remaining to satisfy the request, then NULL is returned.
370 If Buffer is NULL, then ASSERT().
371 If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
373 @param AllocationSize The number of bytes to allocate and zero.
374 @param Buffer The buffer to copy to the allocated buffer.
376 @return A pointer to the allocated buffer or NULL if allocation fails.
381 AllocateReservedCopyPool (
382 IN UINTN AllocationSize
,
383 IN CONST VOID
*Buffer
387 Reallocates a buffer of type EfiBootServicesData.
389 Allocates and zeros the number bytes specified by NewSize from memory of type
390 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
391 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
392 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
393 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
394 enough memory remaining to satisfy the request, then NULL is returned.
396 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
397 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
399 @param OldSize The size, in bytes, of OldBuffer.
400 @param NewSize The size, in bytes, of the buffer to reallocate.
401 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
402 parameter that may be NULL.
404 @return A pointer to the allocated buffer or NULL if allocation fails.
412 IN VOID
*OldBuffer OPTIONAL
416 Reallocates a buffer of type EfiRuntimeServicesData.
418 Allocates and zeros the number bytes specified by NewSize from memory of type
419 EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
420 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
421 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
422 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
423 enough memory remaining to satisfy the request, then NULL is returned.
425 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
426 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
428 @param OldSize The size, in bytes, of OldBuffer.
429 @param NewSize The size, in bytes, of the buffer to reallocate.
430 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
431 parameter that may be NULL.
433 @return A pointer to the allocated buffer or NULL if allocation fails.
438 ReallocateRuntimePool (
441 IN VOID
*OldBuffer OPTIONAL
445 Reallocates a buffer of type EfiReservedMemoryType.
447 Allocates and zeros the number bytes specified by NewSize from memory of type
448 EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
449 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
450 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
451 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
452 enough memory remaining to satisfy the request, then NULL is returned.
454 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
455 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
457 @param OldSize The size, in bytes, of OldBuffer.
458 @param NewSize The size, in bytes, of the buffer to reallocate.
459 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
460 parameter that may be NULL.
462 @return A pointer to the allocated buffer or NULL if allocation fails.
467 ReallocateReservedPool (
470 IN VOID
*OldBuffer OPTIONAL
474 Frees a buffer that was previously allocated with one of the pool allocation functions in the
475 Memory Allocation Library.
477 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
478 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
479 resources, then this function will perform no actions.
481 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
484 @param Buffer Pointer to the buffer to free.