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