]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/MemLibGuid.c
2 Implementation of GUID functions.
4 The following BaseMemoryLib instances contain the same copy of this file:
15 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
16 SPDX-License-Identifier: BSD-2-Clause-Patent
20 #include "MemLibInternals.h"
23 Copies a source GUID to a destination GUID.
25 This function copies the contents of the 128-bit GUID specified by SourceGuid to
26 DestinationGuid, and returns DestinationGuid.
28 If DestinationGuid is NULL, then ASSERT().
29 If SourceGuid is NULL, then ASSERT().
31 @param DestinationGuid A pointer to the destination GUID.
32 @param SourceGuid A pointer to the source GUID.
34 @return DestinationGuid.
40 OUT GUID
*DestinationGuid
,
41 IN CONST GUID
*SourceGuid
45 (UINT64
*)DestinationGuid
,
46 ReadUnaligned64 ((CONST UINT64
*)SourceGuid
)
49 (UINT64
*)DestinationGuid
+ 1,
50 ReadUnaligned64 ((CONST UINT64
*)SourceGuid
+ 1)
52 return DestinationGuid
;
58 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
59 If there are any bit differences in the two GUIDs, then FALSE is returned.
61 If Guid1 is NULL, then ASSERT().
62 If Guid2 is NULL, then ASSERT().
64 @param Guid1 A pointer to a 128 bit GUID.
65 @param Guid2 A pointer to a 128 bit GUID.
67 @retval TRUE Guid1 and Guid2 are identical.
68 @retval FALSE Guid1 and Guid2 are not identical.
78 UINT64 LowPartOfGuid1
;
79 UINT64 LowPartOfGuid2
;
80 UINT64 HighPartOfGuid1
;
81 UINT64 HighPartOfGuid2
;
83 LowPartOfGuid1
= ReadUnaligned64 ((CONST UINT64
*)Guid1
);
84 LowPartOfGuid2
= ReadUnaligned64 ((CONST UINT64
*)Guid2
);
85 HighPartOfGuid1
= ReadUnaligned64 ((CONST UINT64
*)Guid1
+ 1);
86 HighPartOfGuid2
= ReadUnaligned64 ((CONST UINT64
*)Guid2
+ 1);
88 return (BOOLEAN
)(LowPartOfGuid1
== LowPartOfGuid2
&& HighPartOfGuid1
== HighPartOfGuid2
);
92 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
95 This function searches the target buffer specified by Buffer and Length from
96 the lowest address to the highest address at 128-bit increments for the 128-bit
97 GUID value that matches Guid. If a match is found, then a pointer to the matching
98 GUID in the target buffer is returned. If no match is found, then NULL is returned.
99 If Length is 0, then NULL is returned.
101 If Length > 0 and Buffer is NULL, then ASSERT().
102 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
103 If Length is not aligned on a 128-bit boundary, then ASSERT().
104 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
106 @param Buffer The pointer to the target buffer to scan.
107 @param Length The number of bytes in Buffer to scan.
108 @param Guid The value to search for in the target buffer.
110 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
116 IN CONST VOID
*Buffer
,
123 ASSERT (((UINTN
)Buffer
& (sizeof (Guid
->Data1
) - 1)) == 0);
124 ASSERT (Length
<= (MAX_ADDRESS
- (UINTN
)Buffer
+ 1));
125 ASSERT ((Length
& (sizeof (*GuidPtr
) - 1)) == 0);
127 GuidPtr
= (GUID
*)Buffer
;
128 Buffer
= GuidPtr
+ Length
/ sizeof (*GuidPtr
);
129 while (GuidPtr
< (CONST GUID
*)Buffer
) {
130 if (CompareGuid (GuidPtr
, Guid
)) {
131 return (VOID
*)GuidPtr
;
141 Checks if the given GUID is a zero GUID.
143 This function checks whether the given GUID is a zero GUID. If the GUID is
144 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.
146 If Guid is NULL, then ASSERT().
148 @param Guid The pointer to a 128 bit GUID.
150 @retval TRUE Guid is a zero GUID.
151 @retval FALSE Guid is not a zero GUID.
160 UINT64 LowPartOfGuid
;
161 UINT64 HighPartOfGuid
;
163 LowPartOfGuid
= ReadUnaligned64 ((CONST UINT64
*)Guid
);
164 HighPartOfGuid
= ReadUnaligned64 ((CONST UINT64
*)Guid
+ 1);
166 return (BOOLEAN
)(LowPartOfGuid
== 0 && HighPartOfGuid
== 0);