]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLib/MemLibGuid.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLib / MemLibGuid.c
CommitLineData
e1f414b6 1/** @file\r
2 Implementation of GUID functions.\r
3\r
2bfb6009 4 The following BaseMemoryLib instances contain the same copy of this file:\r
9095d37b 5\r
e1f414b6 6 BaseMemoryLib\r
7 BaseMemoryLibMmx\r
8 BaseMemoryLibSse2\r
9 BaseMemoryLibRepStr\r
2bfb6009
LG
10 BaseMemoryLibOptDxe\r
11 BaseMemoryLibOptPei\r
e1f414b6 12 PeiMemoryLib\r
1fef058f 13 UefiMemoryLib\r
e1f414b6 14\r
9095d37b 15 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 16 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d531bfee 17\r
e1f414b6 18**/\r
19\r
d531bfee 20#include "MemLibInternals.h"\r
f734a10a 21\r
e1f414b6 22/**\r
23 Copies a source GUID to a destination GUID.\r
24\r
25 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
26 DestinationGuid, and returns DestinationGuid.\r
9095d37b 27\r
e1f414b6 28 If DestinationGuid is NULL, then ASSERT().\r
29 If SourceGuid is NULL, then ASSERT().\r
30\r
15c952e7 31 @param DestinationGuid A pointer to the destination GUID.\r
32 @param SourceGuid A pointer to the source GUID.\r
e1f414b6 33\r
34 @return DestinationGuid.\r
35\r
36**/\r
37GUID *\r
38EFIAPI\r
39CopyGuid (\r
40 OUT GUID *DestinationGuid,\r
41 IN CONST GUID *SourceGuid\r
42 )\r
43{\r
44 WriteUnaligned64 (\r
2f88bd3a
MK
45 (UINT64 *)DestinationGuid,\r
46 ReadUnaligned64 ((CONST UINT64 *)SourceGuid)\r
e1f414b6 47 );\r
48 WriteUnaligned64 (\r
2f88bd3a
MK
49 (UINT64 *)DestinationGuid + 1,\r
50 ReadUnaligned64 ((CONST UINT64 *)SourceGuid + 1)\r
e1f414b6 51 );\r
52 return DestinationGuid;\r
53}\r
54\r
55/**\r
56 Compares two GUIDs.\r
57\r
58 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
59 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
9095d37b 60\r
e1f414b6 61 If Guid1 is NULL, then ASSERT().\r
62 If Guid2 is NULL, then ASSERT().\r
63\r
64 @param Guid1 A pointer to a 128 bit GUID.\r
65 @param Guid2 A pointer to a 128 bit GUID.\r
66\r
67 @retval TRUE Guid1 and Guid2 are identical.\r
68 @retval FALSE Guid1 and Guid2 are not identical.\r
69\r
70**/\r
71BOOLEAN\r
72EFIAPI\r
73CompareGuid (\r
74 IN CONST GUID *Guid1,\r
75 IN CONST GUID *Guid2\r
76 )\r
77{\r
78 UINT64 LowPartOfGuid1;\r
79 UINT64 LowPartOfGuid2;\r
80 UINT64 HighPartOfGuid1;\r
81 UINT64 HighPartOfGuid2;\r
82\r
2f88bd3a
MK
83 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64 *)Guid1);\r
84 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64 *)Guid2);\r
85 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64 *)Guid1 + 1);\r
86 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64 *)Guid2 + 1);\r
e1f414b6 87\r
2f88bd3a 88 return (BOOLEAN)(LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);\r
e1f414b6 89}\r
90\r
91/**\r
92 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
93 in the target buffer.\r
94\r
56385d49 95 This function searches the target buffer specified by Buffer and Length from\r
e1f414b6 96 the lowest address to the highest address at 128-bit increments for the 128-bit\r
97 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
98 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
99 If Length is 0, then NULL is returned.\r
9095d37b 100\r
e1f414b6 101 If Length > 0 and Buffer is NULL, then ASSERT().\r
102 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
103 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
eb1c78db 104 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
e1f414b6 105\r
15c952e7 106 @param Buffer The pointer to the target buffer to scan.\r
107 @param Length The number of bytes in Buffer to scan.\r
108 @param Guid The value to search for in the target buffer.\r
e1f414b6 109\r
110 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
111\r
112**/\r
113VOID *\r
114EFIAPI\r
115ScanGuid (\r
116 IN CONST VOID *Buffer,\r
117 IN UINTN Length,\r
118 IN CONST GUID *Guid\r
119 )\r
120{\r
2f88bd3a 121 CONST GUID *GuidPtr;\r
e1f414b6 122\r
123 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
124 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
125 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
126\r
2f88bd3a 127 GuidPtr = (GUID *)Buffer;\r
e1f414b6 128 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
2f88bd3a 129 while (GuidPtr < (CONST GUID *)Buffer) {\r
e1f414b6 130 if (CompareGuid (GuidPtr, Guid)) {\r
2f88bd3a 131 return (VOID *)GuidPtr;\r
e1f414b6 132 }\r
2f88bd3a 133\r
e1f414b6 134 GuidPtr++;\r
135 }\r
2f88bd3a 136\r
e1f414b6 137 return NULL;\r
138}\r
313831d9
HW
139\r
140/**\r
141 Checks if the given GUID is a zero GUID.\r
142\r
143 This function checks whether the given GUID is a zero GUID. If the GUID is\r
144 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.\r
145\r
146 If Guid is NULL, then ASSERT().\r
147\r
148 @param Guid The pointer to a 128 bit GUID.\r
149\r
150 @retval TRUE Guid is a zero GUID.\r
151 @retval FALSE Guid is not a zero GUID.\r
152\r
153**/\r
154BOOLEAN\r
155EFIAPI\r
156IsZeroGuid (\r
157 IN CONST GUID *Guid\r
158 )\r
159{\r
160 UINT64 LowPartOfGuid;\r
161 UINT64 HighPartOfGuid;\r
162\r
2f88bd3a
MK
163 LowPartOfGuid = ReadUnaligned64 ((CONST UINT64 *)Guid);\r
164 HighPartOfGuid = ReadUnaligned64 ((CONST UINT64 *)Guid + 1);\r
313831d9 165\r
2f88bd3a 166 return (BOOLEAN)(LowPartOfGuid == 0 && HighPartOfGuid == 0);\r
313831d9 167}\r