]>
Commit | Line | Data |
---|---|---|
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 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
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 | |
30 | IN CONST VOID *Buffer,\r | |
31 | IN UINTN Length,\r | |
32 | IN UINT16 Value\r | |
33 | )\r | |
34 | {\r | |
35 | CONST UINT16 *Pointer;\r | |
36 | \r | |
37 | Pointer = (CONST UINT16*)Buffer;\r | |
38 | do {\r | |
39 | if (*Pointer == Value) {\r | |
40 | return Pointer;\r | |
41 | }\r | |
42 | ++Pointer;\r | |
43 | } while (--Length != 0);\r | |
44 | return NULL;\r | |
45 | }\r | |
46 | \r | |
47 | /**\r | |
48 | Scans a target buffer for a 32-bit value, and returns a pointer to the\r | |
49 | matching 32-bit value in the target buffer.\r | |
50 | \r | |
51 | @param Buffer The pointer to the target buffer to scan.\r | |
52 | @param Length The count of 32-bit value to scan. Must be non-zero.\r | |
53 | @param Value The value to search for in the target buffer.\r | |
54 | \r | |
55 | @return The pointer to the first occurrence, or NULL if not found.\r | |
56 | \r | |
57 | **/\r | |
58 | CONST VOID *\r | |
59 | EFIAPI\r | |
60 | InternalMemScanMem32 (\r | |
61 | IN CONST VOID *Buffer,\r | |
62 | IN UINTN Length,\r | |
63 | IN UINT32 Value\r | |
64 | )\r | |
65 | {\r | |
66 | CONST UINT32 *Pointer;\r | |
67 | \r | |
68 | Pointer = (CONST UINT32*)Buffer;\r | |
69 | do {\r | |
70 | if (*Pointer == Value) {\r | |
71 | return Pointer;\r | |
72 | }\r | |
73 | ++Pointer;\r | |
74 | } while (--Length != 0);\r | |
75 | return NULL;\r | |
76 | }\r | |
77 | \r | |
78 | /**\r | |
79 | Scans a target buffer for a 64-bit value, and returns a pointer to the\r | |
80 | matching 64-bit value in the target buffer.\r | |
81 | \r | |
82 | @param Buffer The pointer to the target buffer to scan.\r | |
83 | @param Length The count of 64-bit value to scan. Must be non-zero.\r | |
84 | @param Value The value to search for in the target buffer.\r | |
85 | \r | |
86 | @return The pointer to the first occurrence, or NULL if not found.\r | |
87 | \r | |
88 | **/\r | |
89 | CONST VOID *\r | |
90 | EFIAPI\r | |
91 | InternalMemScanMem64 (\r | |
92 | IN CONST VOID *Buffer,\r | |
93 | IN UINTN Length,\r | |
94 | IN UINT64 Value\r | |
95 | )\r | |
96 | {\r | |
97 | CONST UINT64 *Pointer;\r | |
98 | \r | |
99 | Pointer = (CONST UINT64*)Buffer;\r | |
100 | do {\r | |
101 | if (*Pointer == Value) {\r | |
102 | return Pointer;\r | |
103 | }\r | |
104 | ++Pointer;\r | |
105 | } while (--Length != 0);\r | |
106 | return NULL;\r | |
107 | }\r | |
108 | \r | |
109 | /**\r | |
110 | Checks whether the contents of a buffer are all zeros.\r | |
111 | \r | |
112 | @param Buffer The pointer to the buffer to be checked.\r | |
113 | @param Length The size of the buffer (in bytes) to be checked.\r | |
114 | \r | |
115 | @retval TRUE Contents of the buffer are all zeros.\r | |
116 | @retval FALSE Contents of the buffer are not all zeros.\r | |
117 | \r | |
118 | **/\r | |
119 | BOOLEAN\r | |
120 | EFIAPI\r | |
121 | InternalMemIsZeroBuffer (\r | |
122 | IN CONST VOID *Buffer,\r | |
123 | IN UINTN Length\r | |
124 | )\r | |
125 | {\r | |
126 | CONST UINT8 *BufferData;\r | |
127 | UINTN Index;\r | |
128 | \r | |
129 | BufferData = Buffer;\r | |
130 | for (Index = 0; Index < Length; Index++) {\r | |
131 | if (BufferData[Index] != 0) {\r | |
132 | return FALSE;\r | |
133 | }\r | |
134 | }\r | |
135 | return TRUE;\r | |
136 | }\r |