]>
Commit | Line | Data |
---|---|---|
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 |
eb1c78db | 8 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
50a64e5b | 9 | All rights reserved. This program and the accompanying materials\r |
10 | are licensed and made available under the terms and conditions of the BSD License\r | |
11 | which accompanies this distribution. The full text of the license may be found at\r | |
12 | http://opensource.org/licenses/bsd-license.php\r | |
fb3df220 | 13 | \r |
50a64e5b | 14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
15 | WITHOUT 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 |
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 | |
39 | VOID *\r | |
40 | EFIAPI\r | |
41 | CopyMem (\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 |
54 | @param Buffer Memory to set.\r | |
55 | @param Length Number of bytes to set.\r | |
d80b2f71 | 56 | @param Value Value with which to fill Length bytes of Buffer.\r |
fb3df220 | 57 | \r |
58 | @return Buffer.\r | |
59 | \r | |
60 | **/\r | |
61 | VOID *\r | |
62 | EFIAPI\r | |
63 | SetMem (\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 | |
88 | VOID *\r | |
89 | EFIAPI\r | |
90 | SetMem16 (\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 | |
115 | VOID *\r | |
116 | EFIAPI\r | |
117 | SetMem32 (\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 | |
142 | VOID *\r | |
143 | EFIAPI\r | |
144 | SetMem64 (\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 | |
eb1c78db | 154 | \r |
fb3df220 | 155 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
cc4e0485 | 156 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
164 | VOID *\r | |
165 | EFIAPI\r | |
166 | ZeroMem (\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 | |
eb1c78db | 178 | \r |
2bfb6009 LG |
179 | If Length > 0 and DestinationBuffer is NULL, then ASSERT().\r |
180 | If Length > 0 and SourceBuffer is NULL, then ASSERT().\r | |
8693ca5d | 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 | |
fb3df220 | 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 | |
eb1c78db | 191 | \r |
fb3df220 | 192 | **/\r |
193 | INTN\r | |
194 | EFIAPI\r | |
195 | CompareMem (\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 | |
eb1c78db | 209 | \r |
fb3df220 | 210 | If Length > 0 and Buffer is NULL, then ASSERT().\r |
cc4e0485 | 211 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
220 | VOID *\r | |
221 | EFIAPI\r | |
222 | ScanMem8 (\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 | |
eb1c78db | 236 | \r |
fb3df220 | 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 | |
cc4e0485 | 240 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
249 | VOID *\r | |
250 | EFIAPI\r | |
251 | ScanMem16 (\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 | |
eb1c78db | 265 | \r |
fb3df220 | 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 | |
cc4e0485 | 269 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
278 | VOID *\r | |
279 | EFIAPI\r | |
280 | ScanMem32 (\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 | |
eb1c78db | 294 | \r |
fb3df220 | 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 | |
cc4e0485 | 298 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
307 | VOID *\r | |
308 | EFIAPI\r | |
309 | ScanMem64 (\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 | |
eb1c78db | 320 | \r |
fb3df220 | 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 | |
330 | GUID *\r | |
331 | EFIAPI\r | |
332 | CopyGuid (\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 | |
eb1c78db | 342 | \r |
fb3df220 | 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 | |
353 | BOOLEAN\r | |
354 | EFIAPI\r | |
355 | CompareGuid (\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 | |
eb1c78db | 369 | \r |
fb3df220 | 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 | |
cc4e0485 | 373 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
fb3df220 | 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 | |
382 | VOID *\r | |
383 | EFIAPI\r | |
384 | ScanGuid (\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 |