]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/Library/BaseMemoryLib.h
Add new DEBUG_VERBOSE print error level.
[mirror_edk2.git] / MdePkg / Include / Library / BaseMemoryLib.h
... / ...
CommitLineData
1/** @file\r
2 Provides copy memory, fill memory, zero memory, and GUID functions.\r
3 \r
4 The Base Memory Library provides optimized implementations for common memory-based operations. \r
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
7\r
8Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
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
13\r
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
16\r
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
28 \r
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
31\r
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
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
51 \r
52 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
53\r
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
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
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
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
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
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
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
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
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 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
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
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
181 \r
182 If Length > 0 and Buffer is NULL, then ASSERT().\r
183 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
184\r
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
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
205 \r
206 If Length > 0 and DestinationBuffer is NULL, then ASSERT().\r
207 If Length > 0 and SourceBuffer is NULL, then ASSERT().\r
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
210\r
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
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
218 \r
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
236 \r
237 If Length > 0 and Buffer is NULL, then ASSERT().\r
238 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
239\r
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
243\r
244 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
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
263 \r
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
267 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
268\r
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
272\r
273 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
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
292 \r
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
296 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
297\r
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
301\r
302 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
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
321 \r
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
325 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
326\r
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
330\r
331 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
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
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 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
359\r
360 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
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
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
376 \r
377 If DestinationGuid is NULL, then ASSERT().\r
378 If SourceGuid is NULL, then ASSERT().\r
379\r
380 @param DestinationGuid The pointer to the destination GUID.\r
381 @param SourceGuid The pointer to the source GUID.\r
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
398 \r
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
425 \r
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
429 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
430\r
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
434\r
435 @return A pointer to the matching Guid in the target buffer, otherwise NULL.\r
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