]>
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 | |
10 | This program and the accompanying materials\r | |
11 | are licensed and made available under the terms and conditions of the BSD License\r | |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php.\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
17 | \r | |
18 | **/\r | |
19 | \r | |
20 | #include "../MemLibInternals.h"\r | |
21 | \r | |
22 | /**\r | |
23 | Scans a target buffer for a 16-bit value, and returns a pointer to the\r | |
24 | matching 16-bit value in the target buffer.\r | |
25 | \r | |
26 | @param Buffer The pointer to the target buffer to scan.\r | |
27 | @param Length The count of 16-bit value to scan. Must be non-zero.\r | |
28 | @param Value The value to search for in the target buffer.\r | |
29 | \r | |
30 | @return The pointer to the first occurrence, or NULL if not found.\r | |
31 | \r | |
32 | **/\r | |
33 | CONST VOID *\r | |
34 | EFIAPI\r | |
35 | InternalMemScanMem16 (\r | |
36 | IN CONST VOID *Buffer,\r | |
37 | IN UINTN Length,\r | |
38 | IN UINT16 Value\r | |
39 | )\r | |
40 | {\r | |
41 | CONST UINT16 *Pointer;\r | |
42 | \r | |
43 | Pointer = (CONST UINT16*)Buffer;\r | |
44 | do {\r | |
45 | if (*Pointer == Value) {\r | |
46 | return Pointer;\r | |
47 | }\r | |
48 | ++Pointer;\r | |
49 | } while (--Length != 0);\r | |
50 | return NULL;\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | Scans a target buffer for a 32-bit value, and returns a pointer to the\r | |
55 | matching 32-bit value in the target buffer.\r | |
56 | \r | |
57 | @param Buffer The pointer to the target buffer to scan.\r | |
58 | @param Length The count of 32-bit value to scan. Must be non-zero.\r | |
59 | @param Value The value to search for in the target buffer.\r | |
60 | \r | |
61 | @return The pointer to the first occurrence, or NULL if not found.\r | |
62 | \r | |
63 | **/\r | |
64 | CONST VOID *\r | |
65 | EFIAPI\r | |
66 | InternalMemScanMem32 (\r | |
67 | IN CONST VOID *Buffer,\r | |
68 | IN UINTN Length,\r | |
69 | IN UINT32 Value\r | |
70 | )\r | |
71 | {\r | |
72 | CONST UINT32 *Pointer;\r | |
73 | \r | |
74 | Pointer = (CONST UINT32*)Buffer;\r | |
75 | do {\r | |
76 | if (*Pointer == Value) {\r | |
77 | return Pointer;\r | |
78 | }\r | |
79 | ++Pointer;\r | |
80 | } while (--Length != 0);\r | |
81 | return NULL;\r | |
82 | }\r | |
83 | \r | |
84 | /**\r | |
85 | Scans a target buffer for a 64-bit value, and returns a pointer to the\r | |
86 | matching 64-bit value in the target buffer.\r | |
87 | \r | |
88 | @param Buffer The pointer to the target buffer to scan.\r | |
89 | @param Length The count of 64-bit value to scan. Must be non-zero.\r | |
90 | @param Value The value to search for in the target buffer.\r | |
91 | \r | |
92 | @return The pointer to the first occurrence, or NULL if not found.\r | |
93 | \r | |
94 | **/\r | |
95 | CONST VOID *\r | |
96 | EFIAPI\r | |
97 | InternalMemScanMem64 (\r | |
98 | IN CONST VOID *Buffer,\r | |
99 | IN UINTN Length,\r | |
100 | IN UINT64 Value\r | |
101 | )\r | |
102 | {\r | |
103 | CONST UINT64 *Pointer;\r | |
104 | \r | |
105 | Pointer = (CONST UINT64*)Buffer;\r | |
106 | do {\r | |
107 | if (*Pointer == Value) {\r | |
108 | return Pointer;\r | |
109 | }\r | |
110 | ++Pointer;\r | |
111 | } while (--Length != 0);\r | |
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 | |
132 | CONST UINT8 *BufferData;\r | |
133 | UINTN Index;\r | |
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 | |
141 | return TRUE;\r | |
142 | }\r |