1/** @file
2  ScanMem8() and ScanMemN() implementation.
3
4  The following BaseMemoryLib instances contain the same copy of this file:
5
6    BaseMemoryLib
7    BaseMemoryLibMmx
8    BaseMemoryLibSse2
9    BaseMemoryLibRepStr
10    BaseMemoryLibOptDxe
11    BaseMemoryLibOptPei
12    PeiMemoryLib
13    UefiMemoryLib
14
15  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
16  This program and the accompanying materials
17  are licensed and made available under the terms and conditions of the BSD License
18  which accompanies this distribution.  The full text of the license may be found at
19  http://opensource.org/licenses/bsd-license.php.
20
21  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23
24**/
25
26#include "MemLibInternals.h"
27
28/**
29  Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value
30  in the target buffer.
31
32  This function searches the target buffer specified by Buffer and Length from the lowest
33  address to the highest address for an 8-bit value that matches Value.  If a match is found,
34  then a pointer to the matching byte in the target buffer is returned.  If no match is found,
35  then NULL is returned.  If Length is 0, then NULL is returned.
36
37  If Length > 0 and Buffer is NULL, then ASSERT().
38  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
39
40  @param  Buffer      The pointer to the target buffer to scan.
41  @param  Length      The number of bytes in Buffer to scan.
42  @param  Value       The value to search for in the target buffer.
43
44  @return A pointer to the matching byte in the target buffer or NULL otherwise.
45
46**/
47VOID *
48EFIAPI
49ScanMem8 (
50  IN CONST VOID  *Buffer,
51  IN UINTN       Length,
52  IN UINT8       Value
53  )
54{
55  if (Length == 0) {
56    return NULL;
57  }
58  ASSERT (Buffer != NULL);
59  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
60
61  return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);
62}
63
64/**
65  Scans a target buffer for a UINTN sized value, and returns a pointer to the matching
66  UINTN sized value in the target buffer.
67
68  This function searches the target buffer specified by Buffer and Length from the lowest
69  address to the highest address for a UINTN sized value that matches Value.  If a match is found,
70  then a pointer to the matching byte in the target buffer is returned.  If no match is found,
71  then NULL is returned.  If Length is 0, then NULL is returned.
72
73  If Length > 0 and Buffer is NULL, then ASSERT().
74  If Buffer is not aligned on a UINTN boundary, then ASSERT().
75  If Length is not aligned on a UINTN boundary, then ASSERT().
76  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
77
78  @param  Buffer      The pointer to the target buffer to scan.
79  @param  Length      The number of bytes in Buffer to scan.
80  @param  Value       The value to search for in the target buffer.
81
82  @return A pointer to the matching byte in the target buffer or NULL otherwise.
83
84**/
85VOID *
86EFIAPI
87ScanMemN (
88  IN CONST VOID  *Buffer,
89  IN UINTN       Length,
90  IN UINTN       Value
91  )
92{
93  if (sizeof (UINTN) == sizeof (UINT64)) {
94    return ScanMem64 (Buffer, Length, (UINT64)Value);
95  } else {
96    return ScanMem32 (Buffer, Length, (UINT32)Value);
97  }
98}
99
100