]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibOptDxe/Arm/MemLibGuid.c
MdePkg/BasePeCoffLib: Add more check for relocation data
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptDxe / Arm / MemLibGuid.c
CommitLineData
217b3ac0
AB
1/** @file\r
2 Implementation of GUID functions for ARM and AARCH64\r
3\r
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "MemLibInternals.h"\r
17\r
8e947c07
LG
18/**\r
19 Internal function to compare two GUIDs.\r
20\r
21 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
22 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
23\r
24 @param Guid1 A pointer to a 128 bit GUID.\r
25 @param Guid2 A pointer to a 128 bit GUID.\r
26\r
27 @retval TRUE Guid1 and Guid2 are identical.\r
28 @retval FALSE Guid1 and Guid2 are not identical.\r
29\r
30**/\r
217b3ac0
AB
31BOOLEAN\r
32EFIAPI\r
33InternalMemCompareGuid (\r
34 IN CONST GUID *Guid1,\r
35 IN CONST GUID *Guid2\r
36 );\r
37\r
38/**\r
39 Copies a source GUID to a destination GUID.\r
40\r
41 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
42 DestinationGuid, and returns DestinationGuid.\r
43\r
44 If DestinationGuid is NULL, then ASSERT().\r
45 If SourceGuid is NULL, then ASSERT().\r
46\r
47 @param DestinationGuid The pointer to the destination GUID.\r
48 @param SourceGuid The pointer to the source GUID.\r
49\r
50 @return DestinationGuid.\r
51\r
52**/\r
53GUID *\r
54EFIAPI\r
55CopyGuid (\r
56 OUT GUID *DestinationGuid,\r
57 IN CONST GUID *SourceGuid\r
58 )\r
59{\r
60 ASSERT (DestinationGuid != NULL);\r
61 ASSERT (SourceGuid != NULL);\r
62\r
63 return InternalMemCopyMem (DestinationGuid, SourceGuid, sizeof (GUID));\r
64}\r
65\r
66/**\r
67 Compares two GUIDs.\r
68\r
69 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
70 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
71\r
72 If Guid1 is NULL, then ASSERT().\r
73 If Guid2 is NULL, then ASSERT().\r
74\r
75 @param Guid1 A pointer to a 128 bit GUID.\r
76 @param Guid2 A pointer to a 128 bit GUID.\r
77\r
78 @retval TRUE Guid1 and Guid2 are identical.\r
79 @retval FALSE Guid1 and Guid2 are not identical.\r
80\r
81**/\r
82BOOLEAN\r
83EFIAPI\r
84CompareGuid (\r
85 IN CONST GUID *Guid1,\r
86 IN CONST GUID *Guid2\r
87 )\r
88{\r
89 ASSERT (Guid1 != NULL);\r
90 ASSERT (Guid2 != NULL);\r
91\r
92 return InternalMemCompareGuid (Guid1, Guid2);\r
93}\r
94\r
95/**\r
96 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
97 in the target buffer.\r
98\r
99 This function searches the target buffer specified by Buffer and Length from\r
100 the lowest address to the highest address at 128-bit increments for the 128-bit\r
101 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
102 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
103 If Length is 0, then NULL is returned.\r
104\r
105 If Length > 0 and Buffer is NULL, then ASSERT().\r
106 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
107 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
108 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
109\r
110 @param Buffer The pointer to the target buffer to scan.\r
111 @param Length The number of bytes in Buffer to scan.\r
112 @param Guid The value to search for in the target buffer.\r
113\r
114 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
115\r
116**/\r
117VOID *\r
118EFIAPI\r
119ScanGuid (\r
120 IN CONST VOID *Buffer,\r
121 IN UINTN Length,\r
122 IN CONST GUID *Guid\r
123 )\r
124{\r
125 CONST GUID *GuidPtr;\r
126\r
127 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
128 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
129 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
130\r
131 GuidPtr = (GUID*)Buffer;\r
132 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
133 while (GuidPtr < (CONST GUID*)Buffer) {\r
134 if (InternalMemCompareGuid (GuidPtr, Guid)) {\r
135 return (VOID*)GuidPtr;\r
136 }\r
137 GuidPtr++;\r
138 }\r
139 return NULL;\r
140}\r
141\r
142/**\r
143 Checks if the given GUID is a zero GUID.\r
144\r
145 This function checks whether the given GUID is a zero GUID. If the GUID is\r
146 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.\r
147\r
148 If Guid is NULL, then ASSERT().\r
149\r
150 @param Guid The pointer to a 128 bit GUID.\r
151\r
152 @retval TRUE Guid is a zero GUID.\r
153 @retval FALSE Guid is not a zero GUID.\r
154\r
155**/\r
156BOOLEAN\r
157EFIAPI\r
158IsZeroGuid (\r
159 IN CONST GUID *Guid\r
160 )\r
161{\r
162 ASSERT (Guid != NULL);\r
163\r
164 return InternalMemCompareGuid (Guid, NULL);\r
165}\r