2 Wrapper functions for Base Memory Library.
4 Copyright (c) 2006, Intel Corporation<BR>
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: MemLibWrapper.c
15 The following BaseMemoryLib instances share the same version of this file:
27 Copy Length bytes from Source to Destination.
29 @param Destination Target of copy
30 @param Source Place to copy from
31 @param Length Number of bytes to copy
39 OUT VOID
*DestinationBuffer
,
40 IN CONST VOID
*SourceBuffer
,
45 Set Buffer to Value for Size bytes.
47 @param Buffer Memory to set.
48 @param Size Number of bytes to set
49 @param Value Value of the set operation.
63 Fills a target buffer with a 16-bit value, and returns the target buffer.
65 @param Buffer Pointer to the target buffer to fill.
66 @param Length Number of bytes in Buffer to fill.
67 @param Value Value with which to fill Length bytes of Buffer.
81 Fills a target buffer with a 32-bit value, and returns the target buffer.
83 @param Buffer Pointer to the target buffer to fill.
84 @param Length Number of bytes in Buffer to fill.
85 @param Value Value with which to fill Length bytes of Buffer.
99 Fills a target buffer with a 64-bit value, and returns the target buffer.
101 @param Buffer Pointer to the target buffer to fill.
102 @param Length Number of bytes in Buffer to fill.
103 @param Value Value with which to fill Length bytes of Buffer.
110 InternalMemSetMem64 (
117 Set Buffer to 0 for Size bytes.
119 @param Buffer Memory to set.
120 @param Size Number of bytes to set
133 Compares two memory buffers of a given length.
135 @param DestinationBuffer First memory buffer
136 @param SourceBuffer Second memory buffer
137 @param Length Length of DestinationBuffer and SourceBuffer memory
138 regions to compare. Must be non-zero.
140 @retval 0 if MemOne == MemTwo
145 InternalMemCompareMem (
146 IN CONST VOID
*DestinationBuffer
,
147 IN CONST VOID
*SourceBuffer
,
152 Scans a target buffer for an 8-bit value, and returns a pointer to the
153 matching 8-bit value in the target buffer.
155 @param Buffer Pointer to the target buffer to scan.
156 @param Length Number of bytes in Buffer to scan. Must be non-zero.
157 @param Value Value to search for in the target buffer.
159 @return Pointer to the first occurrence or NULL if not found.
164 InternalMemScanMem8 (
165 IN CONST VOID
*Buffer
,
171 Scans a target buffer for a 16-bit value, and returns a pointer to the
172 matching 16-bit value in the target buffer.
174 @param Buffer Pointer to the target buffer to scan.
175 @param Length Number of bytes in Buffer to scan. Must be non-zero.
176 @param Value Value to search for in the target buffer.
178 @return Pointer to the first occurrence or NULL if not found.
183 InternalMemScanMem16 (
184 IN CONST VOID
*Buffer
,
190 Scans a target buffer for a 32-bit value, and returns a pointer to the
191 matching 32-bit value in the target buffer.
193 @param Buffer Pointer to the target buffer to scan.
194 @param Length Number of bytes in Buffer to scan. Must be non-zero.
195 @param Value Value to search for in the target buffer.
197 @return Pointer to the first occurrence or NULL if not found.
202 InternalMemScanMem32 (
203 IN CONST VOID
*Buffer
,
209 Scans a target buffer for a 64-bit value, and returns a pointer to the
210 matching 64-bit value in the target buffer.
212 @param Buffer Pointer to the target buffer to scan.
213 @param Length Number of bytes in Buffer to scan. Must be non-zero.
214 @param Value Value to search for in the target buffer.
216 @return Pointer to the first occurrence or NULL if not found.
221 InternalMemScanMem64 (
222 IN CONST VOID
*Buffer
,
228 Copy Length bytes from Source to Destination.
230 This function copies Length bytes from SourceBuffer to DestinationBuffer, and
231 returns DestinationBuffer. The implementation must be reentrant, and it must
232 handle the case where SourceBuffer overlaps DestinationBuffer.
234 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then
236 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
238 @param Destination Target of copy
239 @param Source Place to copy from
240 @param Length Number of bytes to copy
248 OUT VOID
*Destination
,
249 IN CONST VOID
*Source
,
253 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Destination
+ 1);
254 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Source
+ 1);
255 return InternalMemCopyMem (Destination
, Source
, Length
);
259 Set Buffer to Value for Size bytes.
261 This function fills Length bytes of Buffer with Value, and returns Buffer.
263 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
265 @param Buffer Memory to set.
266 @param Size Number of bytes to set
267 @param Value Value of the set operation.
280 ASSERT (Size
<= MAX_ADDRESS
- (UINTN
)Buffer
+ 1);
281 return InternalMemSetMem (Buffer
, Size
, Value
);
285 Fills a target buffer with a 16-bit value, and returns the target buffer.
287 This function fills Length bytes of Buffer with the 16-bit value specified by
288 Value, and returns Buffer. Value is repeated every 16-bits in for Length
291 If Buffer is NULL and Length > 0, then ASSERT().
292 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
293 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
294 If Length is not aligned on a 16-bit boundary, then ASSERT().
296 @param Buffer Pointer to the target buffer to fill.
297 @param Length Number of bytes in Buffer to fill.
298 @param Value Value with which to fill Length bytes of Buffer.
311 ASSERT (Buffer
!= NULL
);
312 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Buffer
+ 1);
313 ASSERT ((((UINTN
)Buffer
) & 1) != 0);
314 ASSERT ((Length
& 1) != 0);
316 if ((Length
/= sizeof (Value
)) == 0) {
319 return InternalMemSetMem16 (Buffer
, Length
, Value
);
323 Fills a target buffer with a 32-bit value, and returns the target buffer.
325 This function fills Length bytes of Buffer with the 32-bit value specified by
326 Value, and returns Buffer. Value is repeated every 32-bits in for Length
329 If Buffer is NULL and Length > 0, then ASSERT().
330 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
331 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
332 If Length is not aligned on a 32-bit boundary, then ASSERT().
334 @param Buffer Pointer to the target buffer to fill.
335 @param Length Number of bytes in Buffer to fill.
336 @param Value Value with which to fill Length bytes of Buffer.
349 ASSERT (Buffer
!= NULL
);
350 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Buffer
+ 1);
351 ASSERT ((((UINTN
)Buffer
) & 1) != 0);
352 ASSERT ((Length
& 1) != 0);
354 if ((Length
/= sizeof (Value
)) == 0) {
357 return InternalMemSetMem32 (Buffer
, Length
, Value
);
361 Fills a target buffer with a 64-bit value, and returns the target buffer.
363 This function fills Length bytes of Buffer with the 64-bit value specified by
364 Value, and returns Buffer. Value is repeated every 64-bits in for Length
367 If Buffer is NULL and Length > 0, then ASSERT().
368 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
369 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
370 If Length is not aligned on a 64-bit boundary, then ASSERT().
372 @param Buffer Pointer to the target buffer to fill.
373 @param Length Number of bytes in Buffer to fill.
374 @param Value Value with which to fill Length bytes of Buffer.
387 ASSERT (Buffer
!= NULL
);
388 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Buffer
+ 1);
389 ASSERT ((((UINTN
)Buffer
) & 1) != 0);
390 ASSERT ((Length
& 1) != 0);
392 if ((Length
/= sizeof (Value
)) == 0) {
395 return InternalMemSetMem64 (Buffer
, Length
, Value
);
399 Set Buffer to 0 for Size bytes.
401 This function fills Length bytes of Buffer with zeros, and returns Buffer.
403 If Buffer is NULL and Length > 0, then ASSERT().
404 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
406 @param Buffer Memory to set.
407 @param Size Number of bytes to set
419 ASSERT (Buffer
!= NULL
);
420 return InternalMemSetMem (Buffer
, Size
, 0);
424 Compares two memory buffers of a given length.
426 This function compares Length bytes of SourceBuffer to Length bytes of
427 DestinationBuffer. If all Length bytes of the two buffers are identical, then
428 0 is returned. Otherwise, the value returned is the first mismatched byte in
429 SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.
431 If DestinationBuffer is NULL and Length > 0, then ASSERT().
432 If SourceBuffer is NULL and Length > 0, then ASSERT().
433 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then
435 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().
437 @param DestinationBuffer First memory buffer
438 @param SourceBuffer Second memory buffer
439 @param Length Length of DestinationBuffer and SourceBuffer memory
442 @retval 0 if DestinationBuffer == SourceBuffer
443 @retval Non-zero if DestinationBuffer != SourceBuffer
449 IN CONST VOID
*DestinationBuffer
,
450 IN CONST VOID
*SourceBuffer
,
454 ASSERT (DestinationBuffer
!= NULL
);
455 ASSERT (SourceBuffer
!= NULL
);
456 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)DestinationBuffer
+ 1);
457 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)SourceBuffer
+ 1);
461 return InternalMemCompareMem (DestinationBuffer
, SourceBuffer
, Length
);
465 Scans a target buffer for an 8-bit value, and returns a pointer to the
466 matching 8-bit value in the target buffer.
468 This function searches target the buffer specified by Buffer and Length from
469 the lowest address to the highest address for an 8-bit value that matches
470 Value. If a match is found, then a pointer to the matching byte in the target
471 buffer is returned. If no match is found, then NULL is returned. If Length is
472 0, then NULL is returned.
474 If Buffer is NULL, then ASSERT().
475 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
477 @param Buffer Pointer to the target buffer to scan.
478 @param Length Number of bytes in Buffer to scan.
479 @param Value Value to search for in the target buffer.
481 @return Pointer to the first occurrence or NULL if not found.
482 @retval NULL if Length == 0 or Value was not found.
488 IN CONST VOID
*Buffer
,
493 ASSERT (Buffer
!= NULL
);
494 ASSERT (Length
<= MAX_ADDRESS
+ (UINTN
)Buffer
+ 1);
496 if ((Length
/= sizeof (Value
)) == 0) {
499 return (VOID
*)InternalMemScanMem8 (Buffer
, Length
, Value
);
503 Scans a target buffer for a 16-bit value, and returns a pointer to the
504 matching 16-bit value in the target buffer.
506 This function searches target the buffer specified by Buffer and Length from
507 the lowest address to the highest address at 16-bit increments for a 16-bit
508 value that matches Value. If a match is found, then a pointer to the matching
509 value in the target buffer is returned. If no match is found, then NULL is
510 returned. If Length is 0, then NULL is returned.
512 If Buffer is NULL, then ASSERT().
513 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
514 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
516 @param Buffer Pointer to the target buffer to scan.
517 @param Length Number of bytes in Buffer to scan.
518 @param Value Value to search for in the target buffer.
520 @return Pointer to the first occurrence.
521 @retval NULL if Length == 0 or Value was not found.
527 IN CONST VOID
*Buffer
,
532 ASSERT (Buffer
!= NULL
);
533 ASSERT (((UINTN
)Buffer
& (sizeof (Value
) - 1)) == 0);
534 ASSERT (Length
<= MAX_ADDRESS
+ (UINTN
)Buffer
+ 1);
536 if ((Length
/= sizeof (Value
)) == 0) {
539 return (VOID
*)InternalMemScanMem16 (Buffer
, Length
, Value
);
543 Scans a target buffer for a 32-bit value, and returns a pointer to the
544 matching 32-bit value in the target buffer.
546 This function searches target the buffer specified by Buffer and Length from
547 the lowest address to the highest address at 32-bit increments for a 32-bit
548 value that matches Value. If a match is found, then a pointer to the matching
549 value in the target buffer is returned. If no match is found, then NULL is
550 returned. If Length is 0, then NULL is returned.
552 If Buffer is NULL, then ASSERT().
553 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
554 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
556 @param Buffer Pointer to the target buffer to scan.
557 @param Length Number of bytes in Buffer to scan.
558 @param Value Value to search for in the target buffer.
560 @return Pointer to the first occurrence or NULL if not found.
561 @retval NULL if Length == 0 or Value was not found.
567 IN CONST VOID
*Buffer
,
572 ASSERT (Buffer
!= NULL
);
573 ASSERT (((UINTN
)Buffer
& (sizeof (Value
) - 1)) == 0);
574 ASSERT (Length
<= MAX_ADDRESS
+ (UINTN
)Buffer
+ 1);
576 if ((Length
/= sizeof (Value
)) == 0) {
579 return (VOID
*)InternalMemScanMem32 (Buffer
, Length
, Value
);
583 Scans a target buffer for a 64-bit value, and returns a pointer to the
584 matching 64-bit value in the target buffer.
586 This function searches target the buffer specified by Buffer and Length from
587 the lowest address to the highest address at 64-bit increments for a 64-bit
588 value that matches Value. If a match is found, then a pointer to the matching
589 value in the target buffer is returned. If no match is found, then NULL is
590 returned. If Length is 0, then NULL is returned.
592 If Buffer is NULL, then ASSERT().
593 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
594 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
596 @param Buffer Pointer to the target buffer to scan.
597 @param Length Number of bytes in Buffer to scan.
598 @param Value Value to search for in the target buffer.
600 @return Pointer to the first occurrence or NULL if not found.
601 @retval NULL if Length == 0 or Value was not found.
607 IN CONST VOID
*Buffer
,
612 ASSERT (Buffer
!= NULL
);
613 ASSERT (((UINTN
)Buffer
& (sizeof (Value
) - 1)) == 0);
614 ASSERT (Length
<= MAX_ADDRESS
+ (UINTN
)Buffer
+ 1);
616 if ((Length
/= sizeof (Value
)) == 0) {
619 return (VOID
*)InternalMemScanMem64 (Buffer
, Length
, Value
);