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