]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
d80b2f71 | 2 | Provides copy memory, fill memory, zero memory, and GUID functions.\r |
3 | \r | |
eb1c78db | 4 | The Base Memory Library provides optimized implementations for common memory-based operations. \r |
d80b2f71 | 5 | These functions should be used in place of coding your own loops to do equivalent common functions. \r |
6 | This allows optimized library implementations to help increase performance. \r | |
fb3df220 | 7 | \r |
eb1c78db | 8 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
50a64e5b | 9 | All rights reserved. This program and the accompanying materials\r |
10 | are licensed and made available under the terms and conditions of the BSD License\r | |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
fb3df220 | 13 | \r |
50a64e5b | 14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
fb3df220 | 16 | \r |
fb3df220 | 17 | **/\r |
18 | \r | |
19 | #ifndef __BASE_MEMORY_LIB__\r | |
20 | #define __BASE_MEMORY_LIB__\r | |
21 | \r | |
22 | /**\r | |
23 | Copies a source buffer to a destination buffer, and returns the destination buffer.\r | |
24 | \r | |
25 | This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns\r | |
26 | DestinationBuffer. The implementation must be reentrant, and it must handle the case\r | |
27 | where SourceBuffer overlaps DestinationBuffer.\r | |
eb1c78db | 28 | \r |
8693ca5d | 29 | If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r |
30 | If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r | |
fb3df220 | 31 | \r |
32 | @param DestinationBuffer Pointer to the destination buffer of the memory copy.\r | |
33 | @param SourceBuffer Pointer to the source buffer of the memory copy.\r | |
34 | @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer.\r | |
35 | \r | |
36 | @return DestinationBuffer.\r | |
37 | \r | |
38 | **/\r | |
39 | VOID *\r | |
40 | EFIAPI\r | |
41 | CopyMem (\r | |
42 | OUT VOID *DestinationBuffer,\r | |
43 | IN CONST VOID *SourceBuffer,\r | |
44 | IN UINTN Length\r | |
45 | );\r | |
46 | \r | |
47 | /**\r | |
48 | Fills a target buffer with a byte value, and returns the target buffer.\r | |
49 | \r | |
50 | This function fills Length bytes of Buffer with Value, and returns Buffer.\r | |
eb1c78db | 51 | \r |
cc4e0485 | 52 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 53 | \r |
54 | @param Buffer Memory to set.\r | |
55 | @param Length Number of bytes to set.\r | |
d80b2f71 | 56 | @param Value Value with which to fill Length bytes of Buffer.\r |
fb3df220 | 57 | \r |
58 | @return Buffer.\r | |
59 | \r | |
60 | **/\r | |
61 | VOID *\r | |
62 | EFIAPI\r | |
63 | SetMem (\r | |
64 | OUT VOID *Buffer,\r | |
65 | IN UINTN Length,\r | |
66 | IN UINT8 Value\r | |
67 | );\r | |
68 | \r | |
69 | /**\r | |
70 | Fills a target buffer with a 16-bit value, and returns the target buffer.\r | |
71 | \r | |
72 | This function fills Length bytes of Buffer with the 16-bit value specified by\r | |
73 | Value, and returns Buffer. Value is repeated every 16-bits in for Length\r | |
74 | bytes of Buffer.\r | |
75 | \r | |
76 | If Length > 0 and Buffer is NULL, then ASSERT().\r | |
77 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
78 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r | |
79 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r | |
80 | \r | |
81 | @param Buffer Pointer to the target buffer to fill.\r | |
82 | @param Length Number of bytes in Buffer to fill.\r | |
83 | @param Value Value with which to fill Length bytes of Buffer.\r | |
84 | \r | |
85 | @return Buffer.\r | |
86 | \r | |
87 | **/\r | |
88 | VOID *\r | |
89 | EFIAPI\r | |
90 | SetMem16 (\r | |
91 | OUT VOID *Buffer,\r | |
92 | IN UINTN Length,\r | |
93 | IN UINT16 Value\r | |
94 | );\r | |
95 | \r | |
96 | /**\r | |
97 | Fills a target buffer with a 32-bit value, and returns the target buffer.\r | |
98 | \r | |
99 | This function fills Length bytes of Buffer with the 32-bit value specified by\r | |
100 | Value, and returns Buffer. Value is repeated every 32-bits in for Length\r | |
101 | bytes of Buffer.\r | |
102 | \r | |
103 | If Length > 0 and Buffer is NULL, then ASSERT().\r | |
104 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
105 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
106 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
107 | \r | |
108 | @param Buffer Pointer to the target buffer to fill.\r | |
109 | @param Length Number of bytes in Buffer to fill.\r | |
110 | @param Value Value with which to fill Length bytes of Buffer.\r | |
111 | \r | |
112 | @return Buffer.\r | |
113 | \r | |
114 | **/\r | |
115 | VOID *\r | |
116 | EFIAPI\r | |
117 | SetMem32 (\r | |
118 | OUT VOID *Buffer,\r | |
119 | IN UINTN Length,\r | |
120 | IN UINT32 Value\r | |
121 | );\r | |
122 | \r | |
123 | /**\r | |
124 | Fills a target buffer with a 64-bit value, and returns the target buffer.\r | |
125 | \r | |
126 | This function fills Length bytes of Buffer with the 64-bit value specified by\r | |
127 | Value, and returns Buffer. Value is repeated every 64-bits in for Length\r | |
128 | bytes of Buffer.\r | |
129 | \r | |
130 | If Length > 0 and Buffer is NULL, then ASSERT().\r | |
131 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
132 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r | |
133 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
134 | \r | |
135 | @param Buffer Pointer to the target buffer to fill.\r | |
136 | @param Length Number of bytes in Buffer to fill.\r | |
137 | @param Value Value with which to fill Length bytes of Buffer.\r | |
138 | \r | |
139 | @return Buffer.\r | |
140 | \r | |
141 | **/\r | |
142 | VOID *\r | |
143 | EFIAPI\r | |
144 | SetMem64 (\r | |
145 | OUT VOID *Buffer,\r | |
146 | IN UINTN Length,\r | |
147 | IN UINT64 Value\r | |
148 | );\r | |
149 | \r | |
f7753a96 | 150 | /**\r |
151 | Fills a target buffer with a value that is size UINTN, and returns the target buffer.\r | |
152 | \r | |
153 | This function fills Length bytes of Buffer with the UINTN sized value specified by\r | |
154 | Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length\r | |
155 | bytes of Buffer.\r | |
156 | \r | |
157 | If Length > 0 and Buffer is NULL, then ASSERT().\r | |
158 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
159 | If Buffer is not aligned on a UINTN boundary, then ASSERT().\r | |
160 | If Length is not aligned on a UINTN boundary, then ASSERT().\r | |
161 | \r | |
162 | @param Buffer Pointer to the target buffer to fill.\r | |
163 | @param Length Number of bytes in Buffer to fill.\r | |
164 | @param Value Value with which to fill Length bytes of Buffer.\r | |
165 | \r | |
166 | @return Buffer.\r | |
167 | \r | |
168 | **/\r | |
169 | VOID *\r | |
170 | EFIAPI\r | |
171 | SetMemN (\r | |
172 | OUT VOID *Buffer,\r | |
173 | IN UINTN Length,\r | |
174 | IN UINTN Value\r | |
175 | );\r | |
176 | \r | |
fb3df220 | 177 | /**\r |
178 | Fills a target buffer with zeros, and returns the target buffer.\r | |
179 | \r | |
180 | This function fills Length bytes of Buffer with zeros, and returns Buffer.\r | |
eb1c78db | 181 | \r |
fb3df220 | 182 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
cc4e0485 | 183 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 184 | \r |
185 | @param Buffer Pointer to the target buffer to fill with zeros.\r | |
186 | @param Length Number of bytes in Buffer to fill with zeros.\r | |
187 | \r | |
188 | @return Buffer.\r | |
189 | \r | |
190 | **/\r | |
191 | VOID *\r | |
192 | EFIAPI\r | |
193 | ZeroMem (\r | |
194 | OUT VOID *Buffer,\r | |
195 | IN UINTN Length\r | |
196 | );\r | |
197 | \r | |
198 | /**\r | |
199 | Compares the contents of two buffers.\r | |
200 | \r | |
201 | This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r | |
202 | If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the\r | |
203 | value returned is the first mismatched byte in SourceBuffer subtracted from the first\r | |
204 | mismatched byte in DestinationBuffer.\r | |
eb1c78db | 205 | \r |
2bfb6009 LG |
206 | If Length > 0 and DestinationBuffer is NULL, then ASSERT().\r |
207 | If Length > 0 and SourceBuffer is NULL, then ASSERT().\r | |
8693ca5d | 208 | If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r |
209 | If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r | |
fb3df220 | 210 | \r |
211 | @param DestinationBuffer Pointer to the destination buffer to compare.\r | |
212 | @param SourceBuffer Pointer to the source buffer to compare.\r | |
213 | @param Length Number of bytes to compare.\r | |
214 | \r | |
215 | @return 0 All Length bytes of the two buffers are identical.\r | |
216 | @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first\r | |
217 | mismatched byte in DestinationBuffer.\r | |
eb1c78db | 218 | \r |
fb3df220 | 219 | **/\r |
220 | INTN\r | |
221 | EFIAPI\r | |
222 | CompareMem (\r | |
223 | IN CONST VOID *DestinationBuffer,\r | |
224 | IN CONST VOID *SourceBuffer,\r | |
225 | IN UINTN Length\r | |
226 | );\r | |
227 | \r | |
228 | /**\r | |
229 | Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r | |
230 | in the target buffer.\r | |
231 | \r | |
232 | This function searches target the buffer specified by Buffer and Length from the lowest\r | |
233 | address to the highest address for an 8-bit value that matches Value. If a match is found,\r | |
234 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r | |
235 | then NULL is returned. If Length is 0, then NULL is returned.\r | |
eb1c78db | 236 | \r |
fb3df220 | 237 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
cc4e0485 | 238 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 239 | \r |
240 | @param Buffer Pointer to the target buffer to scan.\r | |
241 | @param Length Number of bytes in Buffer to scan.\r | |
242 | @param Value Value to search for in the target buffer.\r | |
243 | \r | |
244 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r | |
245 | \r | |
246 | **/\r | |
247 | VOID *\r | |
248 | EFIAPI\r | |
249 | ScanMem8 (\r | |
250 | IN CONST VOID *Buffer,\r | |
251 | IN UINTN Length,\r | |
252 | IN UINT8 Value\r | |
253 | );\r | |
254 | \r | |
255 | /**\r | |
256 | Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r | |
257 | in the target buffer.\r | |
258 | \r | |
259 | This function searches target the buffer specified by Buffer and Length from the lowest\r | |
260 | address to the highest address for a 16-bit value that matches Value. If a match is found,\r | |
261 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r | |
262 | then NULL is returned. If Length is 0, then NULL is returned.\r | |
eb1c78db | 263 | \r |
fb3df220 | 264 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
265 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r | |
266 | If Length is not aligned on a 16-bit boundary, then ASSERT().\r | |
cc4e0485 | 267 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 268 | \r |
269 | @param Buffer Pointer to the target buffer to scan.\r | |
270 | @param Length Number of bytes in Buffer to scan.\r | |
271 | @param Value Value to search for in the target buffer.\r | |
272 | \r | |
273 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r | |
274 | \r | |
275 | **/\r | |
276 | VOID *\r | |
277 | EFIAPI\r | |
278 | ScanMem16 (\r | |
279 | IN CONST VOID *Buffer,\r | |
280 | IN UINTN Length,\r | |
281 | IN UINT16 Value\r | |
282 | );\r | |
283 | \r | |
284 | /**\r | |
285 | Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r | |
286 | in the target buffer.\r | |
287 | \r | |
288 | This function searches target the buffer specified by Buffer and Length from the lowest\r | |
289 | address to the highest address for a 32-bit value that matches Value. If a match is found,\r | |
290 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r | |
291 | then NULL is returned. If Length is 0, then NULL is returned.\r | |
eb1c78db | 292 | \r |
fb3df220 | 293 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
294 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
295 | If Length is not aligned on a 32-bit boundary, then ASSERT().\r | |
cc4e0485 | 296 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 297 | \r |
298 | @param Buffer Pointer to the target buffer to scan.\r | |
299 | @param Length Number of bytes in Buffer to scan.\r | |
300 | @param Value Value to search for in the target buffer.\r | |
301 | \r | |
302 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r | |
303 | \r | |
304 | **/\r | |
305 | VOID *\r | |
306 | EFIAPI\r | |
307 | ScanMem32 (\r | |
308 | IN CONST VOID *Buffer,\r | |
309 | IN UINTN Length,\r | |
310 | IN UINT32 Value\r | |
311 | );\r | |
312 | \r | |
313 | /**\r | |
314 | Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r | |
315 | in the target buffer.\r | |
316 | \r | |
317 | This function searches target the buffer specified by Buffer and Length from the lowest\r | |
318 | address to the highest address for a 64-bit value that matches Value. If a match is found,\r | |
319 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r | |
320 | then NULL is returned. If Length is 0, then NULL is returned.\r | |
eb1c78db | 321 | \r |
fb3df220 | 322 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
323 | If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r | |
324 | If Length is not aligned on a 64-bit boundary, then ASSERT().\r | |
cc4e0485 | 325 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 326 | \r |
327 | @param Buffer Pointer to the target buffer to scan.\r | |
328 | @param Length Number of bytes in Buffer to scan.\r | |
329 | @param Value Value to search for in the target buffer.\r | |
330 | \r | |
331 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r | |
332 | \r | |
333 | **/\r | |
334 | VOID *\r | |
335 | EFIAPI\r | |
336 | ScanMem64 (\r | |
337 | IN CONST VOID *Buffer,\r | |
338 | IN UINTN Length,\r | |
339 | IN UINT64 Value\r | |
340 | );\r | |
341 | \r | |
f7753a96 | 342 | /**\r |
343 | Scans a target buffer for a UINTN sized value, and returns a pointer to the matching \r | |
344 | UINTN sized value in the target buffer.\r | |
345 | \r | |
346 | This function searches target the buffer specified by Buffer and Length from the lowest\r | |
347 | address to the highest address for a UINTN sized value that matches Value. If a match is found,\r | |
348 | then a pointer to the matching byte in the target buffer is returned. If no match is found,\r | |
349 | then NULL is returned. If Length is 0, then NULL is returned.\r | |
350 | \r | |
351 | If Length > 0 and Buffer is NULL, then ASSERT().\r | |
352 | If Buffer is not aligned on a UINTN boundary, then ASSERT().\r | |
353 | If Length is not aligned on a UINTN boundary, then ASSERT().\r | |
354 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
355 | \r | |
356 | @param Buffer Pointer to the target buffer to scan.\r | |
357 | @param Length Number of bytes in Buffer to scan.\r | |
358 | @param Value Value to search for in the target buffer.\r | |
359 | \r | |
360 | @return A pointer to the matching byte in the target buffer or NULL otherwise.\r | |
361 | \r | |
362 | **/\r | |
363 | VOID *\r | |
364 | EFIAPI\r | |
365 | ScanMemN (\r | |
366 | IN CONST VOID *Buffer,\r | |
367 | IN UINTN Length,\r | |
368 | IN UINTN Value\r | |
369 | );\r | |
370 | \r | |
fb3df220 | 371 | /**\r |
372 | Copies a source GUID to a destination GUID.\r | |
373 | \r | |
374 | This function copies the contents of the 128-bit GUID specified by SourceGuid to\r | |
375 | DestinationGuid, and returns DestinationGuid.\r | |
eb1c78db | 376 | \r |
fb3df220 | 377 | If DestinationGuid is NULL, then ASSERT().\r |
378 | If SourceGuid is NULL, then ASSERT().\r | |
379 | \r | |
380 | @param DestinationGuid Pointer to the destination GUID.\r | |
381 | @param SourceGuid Pointer to the source GUID.\r | |
382 | \r | |
383 | @return DestinationGuid.\r | |
384 | \r | |
385 | **/\r | |
386 | GUID *\r | |
387 | EFIAPI\r | |
388 | CopyGuid (\r | |
389 | OUT GUID *DestinationGuid,\r | |
390 | IN CONST GUID *SourceGuid\r | |
391 | );\r | |
392 | \r | |
393 | /**\r | |
394 | Compares two GUIDs.\r | |
395 | \r | |
396 | This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r | |
397 | If there are any bit differences in the two GUIDs, then FALSE is returned.\r | |
eb1c78db | 398 | \r |
fb3df220 | 399 | If Guid1 is NULL, then ASSERT().\r |
400 | If Guid2 is NULL, then ASSERT().\r | |
401 | \r | |
402 | @param Guid1 A pointer to a 128 bit GUID.\r | |
403 | @param Guid2 A pointer to a 128 bit GUID.\r | |
404 | \r | |
405 | @retval TRUE Guid1 and Guid2 are identical.\r | |
406 | @retval FALSE Guid1 and Guid2 are not identical.\r | |
407 | \r | |
408 | **/\r | |
409 | BOOLEAN\r | |
410 | EFIAPI\r | |
411 | CompareGuid (\r | |
412 | IN CONST GUID *Guid1,\r | |
413 | IN CONST GUID *Guid2\r | |
414 | );\r | |
415 | \r | |
416 | /**\r | |
417 | Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r | |
418 | in the target buffer.\r | |
419 | \r | |
420 | This function searches target the buffer specified by Buffer and Length from\r | |
421 | the lowest address to the highest address at 128-bit increments for the 128-bit\r | |
422 | GUID value that matches Guid. If a match is found, then a pointer to the matching\r | |
423 | GUID in the target buffer is returned. If no match is found, then NULL is returned.\r | |
424 | If Length is 0, then NULL is returned.\r | |
eb1c78db | 425 | \r |
fb3df220 | 426 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
427 | If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r | |
428 | If Length is not aligned on a 128-bit boundary, then ASSERT().\r | |
cc4e0485 | 429 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 430 | \r |
431 | @param Buffer Pointer to the target buffer to scan.\r | |
432 | @param Length Number of bytes in Buffer to scan.\r | |
433 | @param Guid Value to search for in the target buffer.\r | |
434 | \r | |
435 | @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r | |
436 | \r | |
437 | **/\r | |
438 | VOID *\r | |
439 | EFIAPI\r | |
440 | ScanGuid (\r | |
441 | IN CONST VOID *Buffer,\r | |
442 | IN UINTN Length,\r | |
443 | IN CONST GUID *Guid\r | |
444 | );\r | |
445 | \r | |
446 | #endif\r |