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