]>
git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/Unix/Host/MemoryAllocationLib.c
3 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "Library/BaseMemoryLib.h"
17 #include "Library/MemoryAllocationLib.h"
22 Allocates a buffer of type EfiBootServicesData.
24 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
25 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
26 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
28 @param AllocationSize The number of bytes to allocate.
30 @return A pointer to the allocated buffer or NULL if allocation fails.
36 IN UINTN AllocationSize
39 return (VOID
*) malloc (AllocationSize
);
44 Allocates and zeros a buffer of type EfiBootServicesData.
46 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
47 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
48 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
49 request, then NULL is returned.
51 @param AllocationSize The number of bytes to allocate and zero.
53 @return A pointer to the allocated buffer or NULL if allocation fails.
59 IN UINTN AllocationSize
64 Buffer
= AllocatePool (AllocationSize
);
69 ZeroMem (Buffer
, AllocationSize
);
76 Reallocates a buffer of type EfiBootServicesData.
78 Allocates and zeros the number bytes specified by NewSize from memory of type
79 EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
80 NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
81 OldBuffer is freed. A pointer to the newly allocated buffer is returned.
82 If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
83 enough memory remaining to satisfy the request, then NULL is returned.
85 If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
86 is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
88 @param OldSize The size, in bytes, of OldBuffer.
89 @param NewSize The size, in bytes, of the buffer to reallocate.
90 @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
91 parameter that may be NULL.
93 @return A pointer to the allocated buffer or NULL if allocation fails.
101 IN VOID
*OldBuffer OPTIONAL
106 NewBuffer
= AllocatePool (NewSize
);
107 if (NewBuffer
== NULL
) {
111 if (OldBuffer
!= NULL
) {
113 CopyMem (NewBuffer
, OldBuffer
, OldSize
);
116 FreePool (OldBuffer
);
124 Frees a buffer that was previously allocated with one of the pool allocation functions in the
125 Memory Allocation Library.
127 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
128 pool allocation services of the Memory Allocation Library. If it is not possible to free pool
129 resources, then this function will perform no actions.
131 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
134 @param Buffer Pointer to the buffer to free.
143 free ((void *) Buffer
);