]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/Library/BaseMemoryLib.h
Code have been checked with spec
[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 - 2008, Intel Corporation<BR>\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The 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 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
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 Memory to set.\r
55 @param Length Number of bytes to set.\r
56 @param Value 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 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
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 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
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 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
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 zeros, and returns the target buffer.\r
152\r
153 This function fills Length bytes of Buffer with zeros, and returns Buffer.\r
154 \r
155 If Length > 0 and Buffer is NULL, then ASSERT().\r
156 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
157\r
158 @param Buffer Pointer to the target buffer to fill with zeros.\r
159 @param Length Number of bytes in Buffer to fill with zeros.\r
160\r
161 @return Buffer.\r
162\r
163**/\r
164VOID *\r
165EFIAPI\r
166ZeroMem (\r
167 OUT VOID *Buffer,\r
168 IN UINTN Length\r
169 );\r
170\r
171/**\r
172 Compares the contents of two buffers.\r
173\r
174 This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
175 If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the\r
176 value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
177 mismatched byte in DestinationBuffer.\r
178 \r
179 If Length > 0 and DestinationBuffer is NULL, then ASSERT().\r
180 If Length > 0 and SourceBuffer is NULL, then ASSERT().\r
181 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r
182 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
183\r
184 @param DestinationBuffer Pointer to the destination buffer to compare.\r
185 @param SourceBuffer Pointer to the source buffer to compare.\r
186 @param Length Number of bytes to compare.\r
187\r
188 @return 0 All Length bytes of the two buffers are identical.\r
189 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first\r
190 mismatched byte in DestinationBuffer.\r
191 \r
192**/\r
193INTN\r
194EFIAPI\r
195CompareMem (\r
196 IN CONST VOID *DestinationBuffer,\r
197 IN CONST VOID *SourceBuffer,\r
198 IN UINTN Length\r
199 );\r
200\r
201/**\r
202 Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
203 in the target buffer.\r
204\r
205 This function searches target the buffer specified by Buffer and Length from the lowest\r
206 address to the highest address for an 8-bit value that matches Value. If a match is found,\r
207 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
208 then NULL is returned. If Length is 0, then NULL is returned.\r
209 \r
210 If Length > 0 and Buffer is NULL, then ASSERT().\r
211 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
212\r
213 @param Buffer Pointer to the target buffer to scan.\r
214 @param Length Number of bytes in Buffer to scan.\r
215 @param Value Value to search for in the target buffer.\r
216\r
217 @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
218\r
219**/\r
220VOID *\r
221EFIAPI\r
222ScanMem8 (\r
223 IN CONST VOID *Buffer,\r
224 IN UINTN Length,\r
225 IN UINT8 Value\r
226 );\r
227\r
228/**\r
229 Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-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 a 16-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 Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
239 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
240 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
241\r
242 @param Buffer Pointer to the target buffer to scan.\r
243 @param Length Number of bytes in Buffer to scan.\r
244 @param Value Value to search for in the target buffer.\r
245\r
246 @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
247\r
248**/\r
249VOID *\r
250EFIAPI\r
251ScanMem16 (\r
252 IN CONST VOID *Buffer,\r
253 IN UINTN Length,\r
254 IN UINT16 Value\r
255 );\r
256\r
257/**\r
258 Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
259 in the target buffer.\r
260\r
261 This function searches target the buffer specified by Buffer and Length from the lowest\r
262 address to the highest address for a 32-bit value that matches Value. If a match is found,\r
263 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
264 then NULL is returned. If Length is 0, then NULL is returned.\r
265 \r
266 If Length > 0 and Buffer is NULL, then ASSERT().\r
267 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
268 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
269 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
270\r
271 @param Buffer Pointer to the target buffer to scan.\r
272 @param Length Number of bytes in Buffer to scan.\r
273 @param Value Value to search for in the target buffer.\r
274\r
275 @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
276\r
277**/\r
278VOID *\r
279EFIAPI\r
280ScanMem32 (\r
281 IN CONST VOID *Buffer,\r
282 IN UINTN Length,\r
283 IN UINT32 Value\r
284 );\r
285\r
286/**\r
287 Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
288 in the target buffer.\r
289\r
290 This function searches target the buffer specified by Buffer and Length from the lowest\r
291 address to the highest address for a 64-bit value that matches Value. If a match is found,\r
292 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
293 then NULL is returned. If Length is 0, then NULL is returned.\r
294 \r
295 If Length > 0 and Buffer is NULL, then ASSERT().\r
296 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
297 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
298 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
299\r
300 @param Buffer Pointer to the target buffer to scan.\r
301 @param Length Number of bytes in Buffer to scan.\r
302 @param Value Value to search for in the target buffer.\r
303\r
304 @return A pointer to the matching byte in the target buffer or NULL otherwise.\r
305\r
306**/\r
307VOID *\r
308EFIAPI\r
309ScanMem64 (\r
310 IN CONST VOID *Buffer,\r
311 IN UINTN Length,\r
312 IN UINT64 Value\r
313 );\r
314\r
315/**\r
316 Copies a source GUID to a destination GUID.\r
317\r
318 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
319 DestinationGuid, and returns DestinationGuid.\r
320 \r
321 If DestinationGuid is NULL, then ASSERT().\r
322 If SourceGuid is NULL, then ASSERT().\r
323\r
324 @param DestinationGuid Pointer to the destination GUID.\r
325 @param SourceGuid Pointer to the source GUID.\r
326\r
327 @return DestinationGuid.\r
328\r
329**/\r
330GUID *\r
331EFIAPI\r
332CopyGuid (\r
333 OUT GUID *DestinationGuid,\r
334 IN CONST GUID *SourceGuid\r
335 );\r
336\r
337/**\r
338 Compares two GUIDs.\r
339\r
340 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
341 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
342 \r
343 If Guid1 is NULL, then ASSERT().\r
344 If Guid2 is NULL, then ASSERT().\r
345\r
346 @param Guid1 A pointer to a 128 bit GUID.\r
347 @param Guid2 A pointer to a 128 bit GUID.\r
348\r
349 @retval TRUE Guid1 and Guid2 are identical.\r
350 @retval FALSE Guid1 and Guid2 are not identical.\r
351\r
352**/\r
353BOOLEAN\r
354EFIAPI\r
355CompareGuid (\r
356 IN CONST GUID *Guid1,\r
357 IN CONST GUID *Guid2\r
358 );\r
359\r
360/**\r
361 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
362 in the target buffer.\r
363\r
364 This function searches target the buffer specified by Buffer and Length from\r
365 the lowest address to the highest address at 128-bit increments for the 128-bit\r
366 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
367 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
368 If Length is 0, then NULL is returned.\r
369 \r
370 If Length > 0 and Buffer is NULL, then ASSERT().\r
371 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
372 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
373 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
374\r
375 @param Buffer Pointer to the target buffer to scan.\r
376 @param Length Number of bytes in Buffer to scan.\r
377 @param Guid Value to search for in the target buffer.\r
378\r
379 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
380\r
381**/\r
382VOID *\r
383EFIAPI\r
384ScanGuid (\r
385 IN CONST VOID *Buffer,\r
386 IN UINTN Length,\r
387 IN CONST GUID *Guid\r
388 );\r
389\r
390#endif\r