]>
Commit | Line | Data |
---|---|---|
79e4f2a5 RN |
1 | /*++ @file\r |
2 | \r | |
3 | Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
4 | \r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "Base.h"\r | |
16 | #include "Library/BaseMemoryLib.h"\r | |
17 | #include "Library/MemoryAllocationLib.h"\r | |
18 | \r | |
19 | #include <stdlib.h>\r | |
20 | \r | |
21 | /**\r | |
22 | Allocates a buffer of type EfiBootServicesData.\r | |
23 | \r | |
24 | Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a\r | |
25 | pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is\r | |
26 | returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.\r | |
27 | \r | |
28 | @param AllocationSize The number of bytes to allocate.\r | |
29 | \r | |
30 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
31 | \r | |
32 | **/\r | |
33 | VOID *\r | |
34 | EFIAPI\r | |
35 | AllocatePool (\r | |
36 | IN UINTN AllocationSize\r | |
37 | )\r | |
38 | {\r | |
39 | return (VOID*) malloc (AllocationSize);\r | |
40 | }\r | |
41 | \r | |
42 | \r | |
43 | /**\r | |
44 | Allocates and zeros a buffer of type EfiBootServicesData.\r | |
45 | \r | |
46 | Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the\r | |
47 | buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a\r | |
48 | valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the\r | |
49 | request, then NULL is returned.\r | |
50 | \r | |
51 | @param AllocationSize The number of bytes to allocate and zero.\r | |
52 | \r | |
53 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
54 | \r | |
55 | **/\r | |
56 | VOID *\r | |
57 | EFIAPI\r | |
58 | AllocateZeroPool (\r | |
59 | IN UINTN AllocationSize\r | |
60 | )\r | |
61 | {\r | |
62 | VOID *Buffer;\r | |
63 | \r | |
64 | Buffer = AllocatePool (AllocationSize);\r | |
65 | if (Buffer == NULL) {\r | |
66 | return NULL;\r | |
67 | }\r | |
68 | \r | |
69 | ZeroMem (Buffer, AllocationSize);\r | |
70 | \r | |
71 | return Buffer;\r | |
72 | }\r | |
73 | \r | |
74 | \r | |
75 | /**\r | |
76 | Reallocates a buffer of type EfiBootServicesData.\r | |
77 | \r | |
78 | Allocates and zeros the number bytes specified by NewSize from memory of type\r | |
79 | EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and\r | |
80 | NewSize bytes are copied from OldBuffer to the newly allocated buffer, and\r | |
81 | OldBuffer is freed. A pointer to the newly allocated buffer is returned.\r | |
82 | If NewSize is 0, then a valid buffer of 0 size is returned. If there is not\r | |
83 | enough memory remaining to satisfy the request, then NULL is returned.\r | |
84 | \r | |
85 | If the allocation of the new buffer is successful and the smaller of NewSize and OldSize\r | |
86 | is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().\r | |
87 | \r | |
88 | @param OldSize The size, in bytes, of OldBuffer.\r | |
89 | @param NewSize The size, in bytes, of the buffer to reallocate.\r | |
90 | @param OldBuffer The buffer to copy to the allocated buffer. This is an optional\r | |
91 | parameter that may be NULL.\r | |
92 | \r | |
93 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
94 | \r | |
95 | **/\r | |
96 | VOID *\r | |
97 | EFIAPI\r | |
98 | ReallocatePool (\r | |
99 | IN UINTN OldSize,\r | |
100 | IN UINTN NewSize,\r | |
101 | IN VOID *OldBuffer OPTIONAL\r | |
102 | )\r | |
103 | {\r | |
104 | VOID *NewBuffer;\r | |
105 | \r | |
106 | NewBuffer = AllocatePool (NewSize);\r | |
107 | if (NewBuffer == NULL) {\r | |
108 | return NULL;\r | |
109 | }\r | |
110 | \r | |
111 | if (OldBuffer != NULL) {\r | |
112 | if (OldSize > 0) {\r | |
113 | CopyMem (NewBuffer, OldBuffer, OldSize);\r | |
114 | }\r | |
115 | \r | |
116 | FreePool (OldBuffer);\r | |
117 | }\r | |
118 | \r | |
119 | return NewBuffer;\r | |
120 | }\r | |
121 | \r | |
122 | \r | |
123 | /**\r | |
124 | Frees a buffer that was previously allocated with one of the pool allocation functions in the\r | |
125 | Memory Allocation Library.\r | |
126 | \r | |
127 | Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the\r | |
128 | pool allocation services of the Memory Allocation Library. If it is not possible to free pool\r | |
129 | resources, then this function will perform no actions.\r | |
130 | \r | |
131 | If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r | |
132 | then ASSERT().\r | |
133 | \r | |
134 | @param Buffer Pointer to the buffer to free.\r | |
135 | \r | |
136 | **/\r | |
137 | VOID\r | |
138 | EFIAPI\r | |
139 | FreePool (\r | |
140 | IN VOID *Buffer\r | |
141 | )\r | |
142 | {\r | |
143 | free ((void *) Buffer);\r | |
144 | }\r | |
145 | \r |