]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/BaseMemoryLib.h
MdePkg: fix comment typo in DebugLib.h
[mirror_edk2.git] / MdePkg / Include / Library / BaseMemoryLib.h
CommitLineData
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
9df063a0 8Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
af2dc6a7 9This program and the accompanying materials are licensed and made available under \r
10the terms and conditions of the BSD License that accompanies this distribution. \r
11The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php.\r
fb3df220 13\r
50a64e5b 14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT 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
af2dc6a7 32 @param DestinationBuffer The pointer to the destination buffer of the memory copy.\r
33 @param SourceBuffer The pointer to the source buffer of the memory copy.\r
34 @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.\r
fb3df220 35\r
36 @return DestinationBuffer.\r
37\r
38**/\r
39VOID *\r
40EFIAPI\r
41CopyMem (\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
af2dc6a7 54 @param Buffer The memory to set.\r
55 @param Length The number of bytes to set.\r
56 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 57\r
58 @return Buffer.\r
59\r
60**/\r
61VOID *\r
62EFIAPI\r
63SetMem (\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
af2dc6a7 81 @param Buffer The pointer to the target buffer to fill.\r
82 @param Length The number of bytes in Buffer to fill.\r
83 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 84\r
85 @return Buffer.\r
86\r
87**/\r
88VOID *\r
89EFIAPI\r
90SetMem16 (\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
af2dc6a7 108 @param Buffer The pointer to the target buffer to fill.\r
109 @param Length The number of bytes in Buffer to fill.\r
110 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 111\r
112 @return Buffer.\r
113\r
114**/\r
115VOID *\r
116EFIAPI\r
117SetMem32 (\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
af2dc6a7 135 @param Buffer The pointer to the target buffer to fill.\r
136 @param Length The number of bytes in Buffer to fill.\r
137 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 138\r
139 @return Buffer.\r
140\r
141**/\r
142VOID *\r
143EFIAPI\r
144SetMem64 (\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
af2dc6a7 162 @param Buffer The pointer to the target buffer to fill.\r
163 @param Length The number of bytes in Buffer to fill.\r
164 @param Value The value with which to fill Length bytes of Buffer.\r
f7753a96 165\r
166 @return Buffer.\r
167\r
168**/\r
169VOID *\r
170EFIAPI\r
171SetMemN (\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
af2dc6a7 185 @param Buffer The pointer to the target buffer to fill with zeros.\r
186 @param Length The number of bytes in Buffer to fill with zeros.\r
fb3df220 187\r
188 @return Buffer.\r
189\r
190**/\r
191VOID *\r
192EFIAPI\r
193ZeroMem (\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
af2dc6a7 211 @param DestinationBuffer The pointer to the destination buffer to compare.\r
212 @param SourceBuffer The pointer to the source buffer to compare.\r
213 @param Length The number of bytes to compare.\r
fb3df220 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
220INTN\r
221EFIAPI\r
222CompareMem (\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
af2dc6a7 240 @param Buffer The pointer to the target buffer to scan.\r
241 @param Length The number of bytes in Buffer to scan.\r
242 @param Value The value to search for in the target buffer.\r
fb3df220 243\r
af2dc6a7 244 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 245\r
246**/\r
247VOID *\r
248EFIAPI\r
249ScanMem8 (\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
af2dc6a7 269 @param Buffer The pointer to the target buffer to scan.\r
270 @param Length The number of bytes in Buffer to scan.\r
271 @param Value The value to search for in the target buffer.\r
fb3df220 272\r
af2dc6a7 273 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 274\r
275**/\r
276VOID *\r
277EFIAPI\r
278ScanMem16 (\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
af2dc6a7 298 @param Buffer The pointer to the target buffer to scan.\r
299 @param Length The number of bytes in Buffer to scan.\r
300 @param Value The value to search for in the target buffer.\r
fb3df220 301\r
af2dc6a7 302 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 303\r
304**/\r
305VOID *\r
306EFIAPI\r
307ScanMem32 (\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
af2dc6a7 327 @param Buffer The pointer to the target buffer to scan.\r
328 @param Length The number of bytes in Buffer to scan.\r
329 @param Value The value to search for in the target buffer.\r
fb3df220 330\r
af2dc6a7 331 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 332\r
333**/\r
334VOID *\r
335EFIAPI\r
336ScanMem64 (\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
af2dc6a7 356 @param Buffer The pointer to the target buffer to scan.\r
357 @param Length The number of bytes in Buffer to scan.\r
358 @param Value The value to search for in the target buffer.\r
f7753a96 359\r
af2dc6a7 360 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
f7753a96 361\r
362**/\r
363VOID *\r
364EFIAPI\r
365ScanMemN (\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
af2dc6a7 380 @param DestinationGuid The pointer to the destination GUID.\r
381 @param SourceGuid The pointer to the source GUID.\r
fb3df220 382\r
383 @return DestinationGuid.\r
384\r
385**/\r
386GUID *\r
387EFIAPI\r
388CopyGuid (\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
409BOOLEAN\r
410EFIAPI\r
411CompareGuid (\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
af2dc6a7 431 @param Buffer The pointer to the target buffer to scan.\r
432 @param Length The number of bytes in Buffer to scan.\r
433 @param Guid The value to search for in the target buffer.\r
fb3df220 434\r
af2dc6a7 435 @return A pointer to the matching Guid in the target buffer, otherwise NULL.\r
fb3df220 436\r
437**/\r
438VOID *\r
439EFIAPI\r
440ScanGuid (\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