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