]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseMemoryLib/MemLibGuid.c
edk2/EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/*:
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BaseMemoryLib / MemLibGuid.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004 - 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 MemLibGuid.c\r
15 \r
16Abstract: \r
17\r
18 Implementation of GUID functions.\r
19\r
20--*/\r
21\r
22#include "BaseMemoryLibInternal.h"\r
23\r
24/**\r
25 Copies a source GUID to a destination GUID.\r
26\r
27 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
28 DestinationGuid, and returns DestinationGuid.\r
29 If DestinationGuid is NULL, then ASSERT().\r
30 If SourceGuid is NULL, then ASSERT().\r
31\r
32 @param DestinationGuid Pointer to the destination GUID.\r
33 @param SourceGuid Pointer to the source GUID.\r
34\r
35 @return DestinationGuid.\r
36\r
37**/\r
38GUID *\r
39EFIAPI\r
40CopyGuid (\r
41 OUT GUID *DestinationGuid,\r
42 IN CONST GUID *SourceGuid\r
43 )\r
44{\r
45 WriteUnaligned64 (\r
46 (UINT64*)DestinationGuid,\r
47 ReadUnaligned64 ((CONST UINT64*)SourceGuid)\r
48 );\r
49 WriteUnaligned64 (\r
50 (UINT64*)DestinationGuid + 1,\r
51 ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)\r
52 );\r
53 return DestinationGuid;\r
54}\r
55\r
56/**\r
57 Compares two GUIDs.\r
58\r
59 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
60 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
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
73GlueCompareGuid (\r
74 IN CONST GUID *Guid1,\r
75 IN CONST GUID *Guid2\r
76 )\r
77{\r
c7f33ca4 78 return (BOOLEAN)(\r
79 ReadUnaligned64 ((CONST UINT64*)Guid1)\r
80 == ReadUnaligned64 ((CONST UINT64*)Guid2) &&\r
81 ReadUnaligned64 ((CONST UINT64*)Guid1 + 1)\r
82 == ReadUnaligned64 ((CONST UINT64*)Guid2 + 1)\r
83 );\r
3eb9473e 84}\r
85\r
86/**\r
87 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
88 in the target buffer.\r
89\r
90 This function searches target the buffer specified by Buffer and Length from\r
91 the lowest address to the highest address at 128-bit increments for the 128-bit\r
92 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
93 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
94 If Length is 0, then NULL is returned.\r
95 If Length > 0 and Buffer is NULL, then ASSERT().\r
96 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
97 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
98 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
99\r
100 @param Buffer Pointer to the target buffer to scan.\r
101 @param Length Number of bytes in Buffer to scan.\r
102 @param Guid Value to search for in the target buffer.\r
103\r
104 @return A pointer to the matching Guid in the target buffer or NULL otherwise.\r
105\r
106**/\r
107VOID *\r
108EFIAPI\r
109ScanGuid (\r
110 IN CONST VOID *Buffer,\r
111 IN UINTN Length,\r
112 IN CONST GUID *Guid\r
113 )\r
114{\r
115 CONST GUID *GuidPtr;\r
116\r
117 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);\r
118 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));\r
119 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);\r
120\r
121 GuidPtr = (GUID*)Buffer;\r
122 Buffer = GuidPtr + Length / sizeof (*GuidPtr);\r
123 while (GuidPtr < (CONST GUID*)Buffer) {\r
124 if (CompareGuid (GuidPtr, Guid)) {\r
125 return (VOID*)GuidPtr;\r
126 }\r
127 GuidPtr++;\r
128 }\r
129 return NULL;\r
130}\r