fb3df220 |
1 | /** @file\r |
2 | Memory-only library functions with no library constructor/destructor\r |
3 | \r |
4 | Copyright (c) 2006, Intel Corporation\r |
5 | All rights reserved. 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 | Module Name: BaseMemoryLib.h\r |
14 | \r |
15 | **/\r |
16 | \r |
17 | #ifndef __BASE_MEMORY_LIB__\r |
18 | #define __BASE_MEMORY_LIB__\r |
19 | \r |
20 | /**\r |
21 | Copies a source buffer to a destination buffer, and returns the destination buffer.\r |
22 | \r |
23 | This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns\r |
24 | DestinationBuffer. The implementation must be reentrant, and it must handle the case\r |
25 | where SourceBuffer overlaps DestinationBuffer.\r |
8693ca5d |
26 | If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r |
27 | If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r |
fb3df220 |
28 | \r |
29 | @param DestinationBuffer Pointer to the destination buffer of the memory copy.\r |
30 | @param SourceBuffer Pointer to the source buffer of the memory copy.\r |
31 | @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer.\r |
32 | \r |
33 | @return DestinationBuffer.\r |
34 | \r |
35 | **/\r |
36 | VOID *\r |
37 | EFIAPI\r |
38 | CopyMem (\r |
39 | OUT VOID *DestinationBuffer,\r |
40 | IN CONST VOID *SourceBuffer,\r |
41 | IN UINTN Length\r |
42 | );\r |
43 | \r |
44 | /**\r |
45 | Fills a target buffer with a byte value, and returns the target buffer.\r |
46 | \r |
47 | This function fills Length bytes of Buffer with Value, and returns Buffer.\r |
8693ca5d |
48 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
49 | \r |
50 | @param Buffer Memory to set.\r |
51 | @param Length Number of bytes to set.\r |
52 | @param Value Value of the set operation.\r |
53 | \r |
54 | @return Buffer.\r |
55 | \r |
56 | **/\r |
57 | VOID *\r |
58 | EFIAPI\r |
59 | SetMem (\r |
60 | OUT VOID *Buffer,\r |
61 | IN UINTN Length,\r |
62 | IN UINT8 Value\r |
63 | );\r |
64 | \r |
65 | /**\r |
66 | Fills a target buffer with a 16-bit value, and returns the target buffer.\r |
67 | \r |
68 | This function fills Length bytes of Buffer with the 16-bit value specified by\r |
69 | Value, and returns Buffer. Value is repeated every 16-bits in for Length\r |
70 | bytes of Buffer.\r |
71 | \r |
72 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
73 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
74 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r |
75 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r |
76 | \r |
77 | @param Buffer Pointer to the target buffer to fill.\r |
78 | @param Length Number of bytes in Buffer to fill.\r |
79 | @param Value Value with which to fill Length bytes of Buffer.\r |
80 | \r |
81 | @return Buffer.\r |
82 | \r |
83 | **/\r |
84 | VOID *\r |
85 | EFIAPI\r |
86 | SetMem16 (\r |
87 | OUT VOID *Buffer,\r |
88 | IN UINTN Length,\r |
89 | IN UINT16 Value\r |
90 | );\r |
91 | \r |
92 | /**\r |
93 | Fills a target buffer with a 32-bit value, and returns the target buffer.\r |
94 | \r |
95 | This function fills Length bytes of Buffer with the 32-bit value specified by\r |
96 | Value, and returns Buffer. Value is repeated every 32-bits in for Length\r |
97 | bytes of Buffer.\r |
98 | \r |
99 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
100 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
101 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r |
102 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r |
103 | \r |
104 | @param Buffer Pointer to the target buffer to fill.\r |
105 | @param Length Number of bytes in Buffer to fill.\r |
106 | @param Value Value with which to fill Length bytes of Buffer.\r |
107 | \r |
108 | @return Buffer.\r |
109 | \r |
110 | **/\r |
111 | VOID *\r |
112 | EFIAPI\r |
113 | SetMem32 (\r |
114 | OUT VOID *Buffer,\r |
115 | IN UINTN Length,\r |
116 | IN UINT32 Value\r |
117 | );\r |
118 | \r |
119 | /**\r |
120 | Fills a target buffer with a 64-bit value, and returns the target buffer.\r |
121 | \r |
122 | This function fills Length bytes of Buffer with the 64-bit value specified by\r |
123 | Value, and returns Buffer. Value is repeated every 64-bits in for Length\r |
124 | bytes of Buffer.\r |
125 | \r |
126 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
127 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
128 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r |
129 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r |
130 | \r |
131 | @param Buffer Pointer to the target buffer to fill.\r |
132 | @param Length Number of bytes in Buffer to fill.\r |
133 | @param Value Value with which to fill Length bytes of Buffer.\r |
134 | \r |
135 | @return Buffer.\r |
136 | \r |
137 | **/\r |
138 | VOID *\r |
139 | EFIAPI\r |
140 | SetMem64 (\r |
141 | OUT VOID *Buffer,\r |
142 | IN UINTN Length,\r |
143 | IN UINT64 Value\r |
144 | );\r |
145 | \r |
146 | /**\r |
147 | Fills a target buffer with zeros, and returns the target buffer.\r |
148 | \r |
149 | This function fills Length bytes of Buffer with zeros, and returns Buffer.\r |
150 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
8693ca5d |
151 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
152 | \r |
153 | @param Buffer Pointer to the target buffer to fill with zeros.\r |
154 | @param Length Number of bytes in Buffer to fill with zeros.\r |
155 | \r |
156 | @return Buffer.\r |
157 | \r |
158 | **/\r |
159 | VOID *\r |
160 | EFIAPI\r |
161 | ZeroMem (\r |
162 | OUT VOID *Buffer,\r |
163 | IN UINTN Length\r |
164 | );\r |
165 | \r |
166 | /**\r |
167 | Compares the contents of two buffers.\r |
168 | \r |
169 | This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r |
170 | If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the\r |
171 | value returned is the first mismatched byte in SourceBuffer subtracted from the first\r |
172 | mismatched byte in DestinationBuffer.\r |
173 | If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT().\r |
174 | If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT().\r |
8693ca5d |
175 | If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r |
176 | If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r |
fb3df220 |
177 | \r |
178 | @param DestinationBuffer Pointer to the destination buffer to compare.\r |
179 | @param SourceBuffer Pointer to the source buffer to compare.\r |
180 | @param Length Number of bytes to compare.\r |
181 | \r |
182 | @return 0 All Length bytes of the two buffers are identical.\r |
183 | @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first\r |
184 | mismatched byte in DestinationBuffer.\r |
185 | \r |
186 | **/\r |
187 | INTN\r |
188 | EFIAPI\r |
189 | CompareMem (\r |
190 | IN CONST VOID *DestinationBuffer,\r |
191 | IN CONST VOID *SourceBuffer,\r |
192 | IN UINTN Length\r |
193 | );\r |
194 | \r |
195 | /**\r |
196 | Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r |
197 | in the target buffer.\r |
198 | \r |
199 | This function searches target the buffer specified by Buffer and Length from the lowest\r |
200 | address to the highest address for an 8-bit value that matches Value. If a match is found,\r |
201 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r |
202 | then NULL is returned. If Length is 0, then NULL is returned.\r |
203 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
8693ca5d |
204 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
205 | \r |
206 | @param Buffer Pointer to the target buffer to scan.\r |
207 | @param Length Number of bytes in Buffer to scan.\r |
208 | @param Value Value to search for in the target buffer.\r |
209 | \r |
210 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r |
211 | \r |
212 | **/\r |
213 | VOID *\r |
214 | EFIAPI\r |
215 | ScanMem8 (\r |
216 | IN CONST VOID *Buffer,\r |
217 | IN UINTN Length,\r |
218 | IN UINT8 Value\r |
219 | );\r |
220 | \r |
221 | /**\r |
222 | Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r |
223 | in the target buffer.\r |
224 | \r |
225 | This function searches target the buffer specified by Buffer and Length from the lowest\r |
226 | address to the highest address for a 16-bit value that matches Value. If a match is found,\r |
227 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r |
228 | then NULL is returned. If Length is 0, then NULL is returned.\r |
229 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
230 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r |
231 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r |
8693ca5d |
232 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
233 | \r |
234 | @param Buffer Pointer to the target buffer to scan.\r |
235 | @param Length Number of bytes in Buffer to scan.\r |
236 | @param Value Value to search for in the target buffer.\r |
237 | \r |
238 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r |
239 | \r |
240 | **/\r |
241 | VOID *\r |
242 | EFIAPI\r |
243 | ScanMem16 (\r |
244 | IN CONST VOID *Buffer,\r |
245 | IN UINTN Length,\r |
246 | IN UINT16 Value\r |
247 | );\r |
248 | \r |
249 | /**\r |
250 | Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r |
251 | in the target buffer.\r |
252 | \r |
253 | This function searches target the buffer specified by Buffer and Length from the lowest\r |
254 | address to the highest address for a 32-bit value that matches Value. If a match is found,\r |
255 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r |
256 | then NULL is returned. If Length is 0, then NULL is returned.\r |
257 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
258 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r |
259 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r |
8693ca5d |
260 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
261 | \r |
262 | @param Buffer Pointer to the target buffer to scan.\r |
263 | @param Length Number of bytes in Buffer to scan.\r |
264 | @param Value Value to search for in the target buffer.\r |
265 | \r |
266 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r |
267 | \r |
268 | **/\r |
269 | VOID *\r |
270 | EFIAPI\r |
271 | ScanMem32 (\r |
272 | IN CONST VOID *Buffer,\r |
273 | IN UINTN Length,\r |
274 | IN UINT32 Value\r |
275 | );\r |
276 | \r |
277 | /**\r |
278 | Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r |
279 | in the target buffer.\r |
280 | \r |
281 | This function searches target the buffer specified by Buffer and Length from the lowest\r |
282 | address to the highest address for a 64-bit value that matches Value. If a match is found,\r |
283 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r |
284 | then NULL is returned. If Length is 0, then NULL is returned.\r |
285 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
286 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r |
287 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r |
8693ca5d |
288 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
289 | \r |
290 | @param Buffer Pointer to the target buffer to scan.\r |
291 | @param Length Number of bytes in Buffer to scan.\r |
292 | @param Value Value to search for in the target buffer.\r |
293 | \r |
294 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r |
295 | \r |
296 | **/\r |
297 | VOID *\r |
298 | EFIAPI\r |
299 | ScanMem64 (\r |
300 | IN CONST VOID *Buffer,\r |
301 | IN UINTN Length,\r |
302 | IN UINT64 Value\r |
303 | );\r |
304 | \r |
305 | /**\r |
306 | Copies a source GUID to a destination GUID.\r |
307 | \r |
308 | This function copies the contents of the 128-bit GUID specified by SourceGuid to\r |
309 | DestinationGuid, and returns DestinationGuid.\r |
310 | If DestinationGuid is NULL, then ASSERT().\r |
311 | If SourceGuid is NULL, then ASSERT().\r |
312 | \r |
313 | @param DestinationGuid Pointer to the destination GUID.\r |
314 | @param SourceGuid Pointer to the source GUID.\r |
315 | \r |
316 | @return DestinationGuid.\r |
317 | \r |
318 | **/\r |
319 | GUID *\r |
320 | EFIAPI\r |
321 | CopyGuid (\r |
322 | OUT GUID *DestinationGuid,\r |
323 | IN CONST GUID *SourceGuid\r |
324 | );\r |
325 | \r |
326 | /**\r |
327 | Compares two GUIDs.\r |
328 | \r |
329 | This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r |
330 | If there are any bit differences in the two GUIDs, then FALSE is returned.\r |
331 | If Guid1 is NULL, then ASSERT().\r |
332 | If Guid2 is NULL, then ASSERT().\r |
333 | \r |
334 | @param Guid1 A pointer to a 128 bit GUID.\r |
335 | @param Guid2 A pointer to a 128 bit GUID.\r |
336 | \r |
337 | @retval TRUE Guid1 and Guid2 are identical.\r |
338 | @retval FALSE Guid1 and Guid2 are not identical.\r |
339 | \r |
340 | **/\r |
341 | BOOLEAN\r |
342 | EFIAPI\r |
343 | CompareGuid (\r |
344 | IN CONST GUID *Guid1,\r |
345 | IN CONST GUID *Guid2\r |
346 | );\r |
347 | \r |
348 | /**\r |
349 | Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r |
350 | in the target buffer.\r |
351 | \r |
352 | This function searches target the buffer specified by Buffer and Length from\r |
353 | the lowest address to the highest address at 128-bit increments for the 128-bit\r |
354 | GUID value that matches Guid. If a match is found, then a pointer to the matching\r |
355 | GUID in the target buffer is returned. If no match is found, then NULL is returned.\r |
356 | If Length is 0, then NULL is returned.\r |
357 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
358 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r |
359 | If Length is not aligned on a 128-bit boundary, then ASSERT().\r |
8693ca5d |
360 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
fb3df220 |
361 | \r |
362 | @param Buffer Pointer to the target buffer to scan.\r |
363 | @param Length Number of bytes in Buffer to scan.\r |
364 | @param Guid Value to search for in the target buffer.\r |
365 | \r |
366 | @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r |
367 | \r |
368 | **/\r |
369 | VOID *\r |
370 | EFIAPI\r |
371 | ScanGuid (\r |
372 | IN CONST VOID *Buffer,\r |
373 | IN UINTN Length,\r |
374 | IN CONST GUID *Guid\r |
375 | );\r |
376 | \r |
377 | #endif\r |