2 Memory-only library functions with no library constructor/destructor
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: BaseMemoryLib.h
17 #ifndef __BASE_MEMORY_LIB__
18 #define __BASE_MEMORY_LIB__
21 Copy Length bytes from Source to Destination.
23 This function copies Length bytes from SourceBuffer to DestinationBuffer, and
24 returns DestinationBuffer. The implementation must be reentrant, and it must
25 handle the case where SourceBuffer overlaps DestinationBuffer.
27 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then
29 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
31 @param Destination Target of copy
32 @param Source Place to copy from
33 @param Length Number of bytes to copy
41 OUT VOID
*DestinationBuffer
,
42 IN CONST VOID
*SourceBuffer
,
47 Set Buffer to Value for Size bytes.
49 This function fills Length bytes of Buffer with Value, and returns Buffer.
51 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
53 @param Buffer Memory to set.
54 @param Size Number of bytes to set
55 @param Value Value of the set operation.
69 Fills a target buffer with a 16-bit value, and returns the target buffer.
71 This function fills Length bytes of Buffer with the 16-bit value specified by
72 Value, and returns Buffer. Value is repeated every 16-bits in for Length
75 If Buffer is NULL and Length > 0, then ASSERT().
76 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
77 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
78 If Length is not aligned on a 16-bit boundary, then ASSERT().
80 @param Buffer Pointer to the target buffer to fill.
81 @param Length Number of bytes in Buffer to fill.
82 @param Value Value with which to fill Length bytes of Buffer.
96 Fills a target buffer with a 32-bit value, and returns the target buffer.
98 This function fills Length bytes of Buffer with the 32-bit value specified by
99 Value, and returns Buffer. Value is repeated every 32-bits in for Length
102 If Buffer is NULL and Length > 0, then ASSERT().
103 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
104 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
105 If Length is not aligned on a 32-bit boundary, then ASSERT().
107 @param Buffer Pointer to the target buffer to fill.
108 @param Length Number of bytes in Buffer to fill.
109 @param Value Value with which to fill Length bytes of Buffer.
123 Fills a target buffer with a 64-bit value, and returns the target buffer.
125 This function fills Length bytes of Buffer with the 64-bit value specified by
126 Value, and returns Buffer. Value is repeated every 64-bits in for Length
129 If Buffer is NULL and Length > 0, then ASSERT().
130 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
131 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
132 If Length is not aligned on a 64-bit boundary, then ASSERT().
134 @param Buffer Pointer to the target buffer to fill.
135 @param Length Number of bytes in Buffer to fill.
136 @param Value Value with which to fill Length bytes of Buffer.
150 Set Buffer to 0 for Size bytes.
152 This function fills Length bytes of Buffer with zeros, and returns Buffer.
154 If Buffer is NULL and Length > 0, then ASSERT().
155 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
157 @param Buffer Memory to set.
158 @param Size Number of bytes to set
171 Compares two memory buffers of a given length.
173 This function compares Length bytes of SourceBuffer to Length bytes of
174 DestinationBuffer. If all Length bytes of the two buffers are identical, then
175 0 is returned. Otherwise, the value returned is the first mismatched byte in
176 SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.
178 If DestinationBuffer is NULL and Length > 0, then ASSERT().
179 If SourceBuffer is NULL and Length > 0, then ASSERT().
180 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then
182 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
184 @param DestinationBuffer First memory buffer
185 @param SourceBuffer Second memory buffer
186 @param Length Length of DestinationBuffer and SourceBuffer memory
189 @retval 0 if DestinationBuffer == SourceBuffer
190 @retval Non-zero if DestinationBuffer != SourceBuffer
196 IN CONST VOID
*DestinationBuffer
,
197 IN CONST VOID
*SourceBuffer
,
202 Scans a target buffer for an 8-bit value, and returns a pointer to the
203 matching 8-bit value in the target buffer.
205 This function searches target the buffer specified by Buffer and Length from
206 the lowest address to the highest address for an 8-bit value that matches
207 Value. If a match is found, then a pointer to the matching byte in the target
208 buffer is returned. If no match is found, then NULL is returned. If Length is
209 0, then NULL is returned.
211 If Buffer is NULL, then ASSERT().
212 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
214 @param Buffer Pointer to the target buffer to scan.
215 @param Length Number of bytes in Buffer to scan.
216 @param Value Value to search for in the target buffer.
218 @return Pointer to the first occurrence or NULL if not found.
219 @retval NULL if Length == 0 or Value was not found.
225 IN CONST VOID
*Buffer
,
231 Scans a target buffer for a 16-bit value, and returns a pointer to the
232 matching 16-bit value in the target buffer.
234 This function searches target the buffer specified by Buffer and Length from
235 the lowest address to the highest address at 16-bit increments for a 16-bit
236 value that matches Value. If a match is found, then a pointer to the matching
237 value in the target buffer is returned. If no match is found, then NULL is
238 returned. If Length is 0, then NULL is returned.
240 If Buffer is NULL, then ASSERT().
241 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
242 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
244 @param Buffer Pointer to the target buffer to scan.
245 @param Length Number of bytes in Buffer to scan.
246 @param Value Value to search for in the target buffer.
248 @return Pointer to the first occurrence.
249 @retval NULL if Length == 0 or Value was not found.
255 IN CONST VOID
*Buffer
,
261 Scans a target buffer for a 32-bit value, and returns a pointer to the
262 matching 32-bit value in the target buffer.
264 This function searches target the buffer specified by Buffer and Length from
265 the lowest address to the highest address at 32-bit increments for a 32-bit
266 value that matches Value. If a match is found, then a pointer to the matching
267 value in the target buffer is returned. If no match is found, then NULL is
268 returned. If Length is 0, then NULL is returned.
270 If Buffer is NULL, then ASSERT().
271 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
272 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
274 @param Buffer Pointer to the target buffer to scan.
275 @param Length Number of bytes in Buffer to scan.
276 @param Value Value to search for in the target buffer.
278 @return Pointer to the first occurrence or NULL if not found.
279 @retval NULL if Length == 0 or Value was not found.
285 IN CONST VOID
*Buffer
,
291 Scans a target buffer for a 64-bit value, and returns a pointer to the
292 matching 64-bit value in the target buffer.
294 This function searches target the buffer specified by Buffer and Length from
295 the lowest address to the highest address at 64-bit increments for a 64-bit
296 value that matches Value. If a match is found, then a pointer to the matching
297 value in the target buffer is returned. If no match is found, then NULL is
298 returned. If Length is 0, then NULL is returned.
300 If Buffer is NULL, then ASSERT().
301 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
302 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
304 @param Buffer Pointer to the target buffer to scan.
305 @param Length Number of bytes in Buffer to scan.
306 @param Value Value to search for in the target buffer.
308 @return Pointer to the first occurrence or NULL if not found.
309 @retval NULL if Length == 0 or Value was not found.
315 IN CONST VOID
*Buffer
,
321 This function copies a source GUID to a destination GUID.
323 This function copies the contents of the 128-bit GUID specified by SourceGuid
324 to DestinationGuid, and returns DestinationGuid.
326 If DestinationGuid is NULL, then ASSERT().
327 If SourceGuid is NULL, then ASSERT().
329 @param DestinationGuid Pointer to the destination GUID.
330 @param SourceGuid Pointer to the source GUID.
332 @return DestinationGuid
338 OUT GUID
*DestinationGuid
,
339 IN CONST GUID
*SourceGuid
345 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE
346 is returned. If there are any bit differences in the two GUIDs, then FALSE is
349 If Guid1 is NULL, then ASSERT().
350 If Guid2 is NULL, then ASSERT().
352 @param Guid1 guid to compare
353 @param Guid2 guid to compare
355 @retval TRUE if Guid1 == Guid2
356 @retval FALSE if Guid1 != Guid2
362 IN CONST GUID
*Guid1
,
367 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
368 in the target buffer.
370 This function searches target the buffer specified by Buffer and Length from
371 the lowest address to the highest address at 128-bit increments for the
372 128-bit GUID value that matches Guid. If a match is found, then a pointer to
373 the matching GUID in the target buffer is returned. If no match is found,
374 then NULL is returned. If Length is 0, then NULL is returned.
376 If Buffer is NULL, then ASSERT().
377 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
378 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
380 @param Buffer Pointer to the target buffer to scan.
381 @param Length Number of bytes in Buffer to scan.
382 @param Guid Value to search for in the target buffer.
384 @return Pointer to the first occurrence.
385 @retval NULL if Length == 0 or Guid was not found.
390 IN CONST VOID
*Buffer
,