]>
git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Unix/Host/MemoryAllocationLib.c
3 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "Library/BaseMemoryLib.h"
11 #include "Library/MemoryAllocationLib.h"
16 Allocates a buffer of type EfiBootServicesData.
18 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
19 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
20 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
22 @param AllocationSize The number of bytes to allocate.
24 @return A pointer to the allocated buffer or NULL if allocation fails.
30 IN UINTN AllocationSize
33 return (VOID
*) malloc (AllocationSize
);
38 Allocates and zeros a buffer of type EfiBootServicesData.
40 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
41 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
42 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
43 request, then NULL is returned.
45 @param AllocationSize The number of bytes to allocate and zero.
47 @return A pointer to the allocated buffer or NULL if allocation fails.
53 IN UINTN AllocationSize
58 Buffer
= AllocatePool (AllocationSize
);
63 ZeroMem (Buffer
, AllocationSize
);
70 Reallocates a buffer of type EfiBootServicesData.
72 Allocates and zeros the number bytes specified by NewSize from memory of type
73 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
74 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
75 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
76 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
77 enough memory remaining to satisfy the request, then NULL is returned.
79 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
80 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
82 @param OldSize The size, in bytes, of OldBuffer.
83 @param NewSize The size, in bytes, of the buffer to reallocate.
84 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
85 parameter that may be NULL.
87 @return A pointer to the allocated buffer or NULL if allocation fails.
95 IN VOID
*OldBuffer OPTIONAL
100 NewBuffer
= AllocatePool (NewSize
);
101 if (NewBuffer
== NULL
) {
105 if (OldBuffer
!= NULL
) {
107 CopyMem (NewBuffer
, OldBuffer
, OldSize
);
110 FreePool (OldBuffer
);
118 Frees a buffer that was previously allocated with one of the pool allocation functions in the
119 Memory Allocation Library.
121 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
122 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
123 resources, then this function will perform no actions.
125 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
128 @param Buffer Pointer to the buffer to free.
137 free ((void *) Buffer
);