]>
Commit | Line | Data |
---|---|---|
a37f6605 AB |
1 | /** @file\r |
2 | Architecture Independent Base Memory Library Implementation.\r | |
3 | \r | |
4 | The following BaseMemoryLib instances contain the same copy of this file:\r | |
5 | BaseMemoryLib\r | |
6 | PeiMemoryLib\r | |
7 | UefiMemoryLib\r | |
8 | \r | |
9 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r | |
9344f092 | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a37f6605 AB |
11 | \r |
12 | **/\r | |
13 | \r | |
14 | #include "../MemLibInternals.h"\r | |
15 | \r | |
16 | /**\r | |
17 | Scans a target buffer for a 16-bit value, and returns a pointer to the\r | |
18 | matching 16-bit value in the target buffer.\r | |
19 | \r | |
20 | @param Buffer The pointer to the target buffer to scan.\r | |
21 | @param Length The count of 16-bit value to scan. Must be non-zero.\r | |
22 | @param Value The value to search for in the target buffer.\r | |
23 | \r | |
24 | @return The pointer to the first occurrence, or NULL if not found.\r | |
25 | \r | |
26 | **/\r | |
27 | CONST VOID *\r | |
28 | EFIAPI\r | |
29 | InternalMemScanMem16 (\r | |
2f88bd3a MK |
30 | IN CONST VOID *Buffer,\r |
31 | IN UINTN Length,\r | |
32 | IN UINT16 Value\r | |
a37f6605 AB |
33 | )\r |
34 | {\r | |
2f88bd3a | 35 | CONST UINT16 *Pointer;\r |
a37f6605 | 36 | \r |
2f88bd3a | 37 | Pointer = (CONST UINT16 *)Buffer;\r |
a37f6605 AB |
38 | do {\r |
39 | if (*Pointer == Value) {\r | |
40 | return Pointer;\r | |
41 | }\r | |
2f88bd3a | 42 | \r |
a37f6605 AB |
43 | ++Pointer;\r |
44 | } while (--Length != 0);\r | |
2f88bd3a | 45 | \r |
a37f6605 AB |
46 | return NULL;\r |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | Scans a target buffer for a 32-bit value, and returns a pointer to the\r | |
51 | matching 32-bit value in the target buffer.\r | |
52 | \r | |
53 | @param Buffer The pointer to the target buffer to scan.\r | |
54 | @param Length The count of 32-bit value to scan. Must be non-zero.\r | |
55 | @param Value The value to search for in the target buffer.\r | |
56 | \r | |
57 | @return The pointer to the first occurrence, or NULL if not found.\r | |
58 | \r | |
59 | **/\r | |
60 | CONST VOID *\r | |
61 | EFIAPI\r | |
62 | InternalMemScanMem32 (\r | |
2f88bd3a MK |
63 | IN CONST VOID *Buffer,\r |
64 | IN UINTN Length,\r | |
65 | IN UINT32 Value\r | |
a37f6605 AB |
66 | )\r |
67 | {\r | |
2f88bd3a | 68 | CONST UINT32 *Pointer;\r |
a37f6605 | 69 | \r |
2f88bd3a | 70 | Pointer = (CONST UINT32 *)Buffer;\r |
a37f6605 AB |
71 | do {\r |
72 | if (*Pointer == Value) {\r | |
73 | return Pointer;\r | |
74 | }\r | |
2f88bd3a | 75 | \r |
a37f6605 AB |
76 | ++Pointer;\r |
77 | } while (--Length != 0);\r | |
2f88bd3a | 78 | \r |
a37f6605 AB |
79 | return NULL;\r |
80 | }\r | |
81 | \r | |
82 | /**\r | |
83 | Scans a target buffer for a 64-bit value, and returns a pointer to the\r | |
84 | matching 64-bit value in the target buffer.\r | |
85 | \r | |
86 | @param Buffer The pointer to the target buffer to scan.\r | |
87 | @param Length The count of 64-bit value to scan. Must be non-zero.\r | |
88 | @param Value The value to search for in the target buffer.\r | |
89 | \r | |
90 | @return The pointer to the first occurrence, or NULL if not found.\r | |
91 | \r | |
92 | **/\r | |
93 | CONST VOID *\r | |
94 | EFIAPI\r | |
95 | InternalMemScanMem64 (\r | |
2f88bd3a MK |
96 | IN CONST VOID *Buffer,\r |
97 | IN UINTN Length,\r | |
98 | IN UINT64 Value\r | |
a37f6605 AB |
99 | )\r |
100 | {\r | |
2f88bd3a | 101 | CONST UINT64 *Pointer;\r |
a37f6605 | 102 | \r |
2f88bd3a | 103 | Pointer = (CONST UINT64 *)Buffer;\r |
a37f6605 AB |
104 | do {\r |
105 | if (*Pointer == Value) {\r | |
106 | return Pointer;\r | |
107 | }\r | |
2f88bd3a | 108 | \r |
a37f6605 AB |
109 | ++Pointer;\r |
110 | } while (--Length != 0);\r | |
2f88bd3a | 111 | \r |
a37f6605 AB |
112 | return NULL;\r |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | Checks whether the contents of a buffer are all zeros.\r | |
117 | \r | |
118 | @param Buffer The pointer to the buffer to be checked.\r | |
119 | @param Length The size of the buffer (in bytes) to be checked.\r | |
120 | \r | |
121 | @retval TRUE Contents of the buffer are all zeros.\r | |
122 | @retval FALSE Contents of the buffer are not all zeros.\r | |
123 | \r | |
124 | **/\r | |
125 | BOOLEAN\r | |
126 | EFIAPI\r | |
127 | InternalMemIsZeroBuffer (\r | |
128 | IN CONST VOID *Buffer,\r | |
129 | IN UINTN Length\r | |
130 | )\r | |
131 | {\r | |
2f88bd3a MK |
132 | CONST UINT8 *BufferData;\r |
133 | UINTN Index;\r | |
a37f6605 AB |
134 | \r |
135 | BufferData = Buffer;\r | |
136 | for (Index = 0; Index < Length; Index++) {\r | |
137 | if (BufferData[Index] != 0) {\r | |
138 | return FALSE;\r | |
139 | }\r | |
140 | }\r | |
2f88bd3a | 141 | \r |
a37f6605 AB |
142 | return TRUE;\r |
143 | }\r |