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