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