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