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 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
16 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
17 |
|
---|
18 | **/
|
---|
19 |
|
---|
20 | #include "MemLibInternals.h"
|
---|
21 |
|
---|
22 | /**
|
---|
23 | Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value
|
---|
24 | in the target buffer.
|
---|
25 |
|
---|
26 | This function searches the target buffer specified by Buffer and Length from the lowest
|
---|
27 | address to the highest address for an 8-bit value that matches Value. If a match is found,
|
---|
28 | then a pointer to the matching byte in the target buffer is returned. If no match is found,
|
---|
29 | then NULL is returned. If Length is 0, then NULL is returned.
|
---|
30 |
|
---|
31 | If Length > 0 and Buffer is NULL, then ASSERT().
|
---|
32 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
33 |
|
---|
34 | @param Buffer The pointer to the target buffer to scan.
|
---|
35 | @param Length The number of bytes in Buffer to scan.
|
---|
36 | @param Value The value to search for in the target buffer.
|
---|
37 |
|
---|
38 | @return A pointer to the matching byte in the target buffer, or NULL otherwise.
|
---|
39 |
|
---|
40 | **/
|
---|
41 | VOID *
|
---|
42 | EFIAPI
|
---|
43 | ScanMem8 (
|
---|
44 | IN CONST VOID *Buffer,
|
---|
45 | IN UINTN Length,
|
---|
46 | IN UINT8 Value
|
---|
47 | )
|
---|
48 | {
|
---|
49 | if (Length == 0) {
|
---|
50 | return NULL;
|
---|
51 | }
|
---|
52 |
|
---|
53 | ASSERT (Buffer != NULL);
|
---|
54 | ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
|
---|
55 |
|
---|
56 | return (VOID *)InternalMemScanMem8 (Buffer, Length, Value);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | Scans a target buffer for a UINTN sized value, and returns a pointer to the matching
|
---|
61 | UINTN sized value in the target buffer.
|
---|
62 |
|
---|
63 | This function searches the target buffer specified by Buffer and Length from the lowest
|
---|
64 | address to the highest address for a UINTN sized value that matches Value. If a match is found,
|
---|
65 | then a pointer to the matching byte in the target buffer is returned. If no match is found,
|
---|
66 | then NULL is returned. If Length is 0, then NULL is returned.
|
---|
67 |
|
---|
68 | If Length > 0 and Buffer is NULL, then ASSERT().
|
---|
69 | If Buffer is not aligned on a UINTN boundary, then ASSERT().
|
---|
70 | If Length is not aligned on a UINTN boundary, then ASSERT().
|
---|
71 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
|
---|
72 |
|
---|
73 | @param Buffer The pointer to the target buffer to scan.
|
---|
74 | @param Length The number of bytes in Buffer to scan.
|
---|
75 | @param Value The value to search for in the target buffer.
|
---|
76 |
|
---|
77 | @return A pointer to the matching byte in the target buffer, or NULL otherwise.
|
---|
78 |
|
---|
79 | **/
|
---|
80 | VOID *
|
---|
81 | EFIAPI
|
---|
82 | ScanMemN (
|
---|
83 | IN CONST VOID *Buffer,
|
---|
84 | IN UINTN Length,
|
---|
85 | IN UINTN Value
|
---|
86 | )
|
---|
87 | {
|
---|
88 | if (sizeof (UINTN) == sizeof (UINT64)) {
|
---|
89 | return ScanMem64 (Buffer, Length, (UINT64)Value);
|
---|
90 | } else {
|
---|
91 | return ScanMem32 (Buffer, Length, (UINT32)Value);
|
---|
92 | }
|
---|
93 | }
|
---|