]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/MemLibGuid.c
Removed CommonHeader.h generated file from the MdePkg.
[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 Module Name: MemLibGuid.c
14
15 The following BaseMemoryLib instances share the same version of this file:
16
17 BaseMemoryLib
18 BaseMemoryLibMmx
19 BaseMemoryLibSse2
20 BaseMemoryLibRepStr
21 PeiMemoryLib
22 DxeMemoryLib
23
24 **/
25
26 //
27 // Include common header file for this module.
28 //
29 #include <MemLibInternals.h>
30
31
32 /**
33 Copies a source GUID to a destination GUID.
34
35 This function copies the contents of the 128-bit GUID specified by SourceGuid to
36 DestinationGuid, and returns DestinationGuid.
37 If DestinationGuid is NULL, then ASSERT().
38 If SourceGuid is NULL, then ASSERT().
39
40 @param DestinationGuid Pointer to the destination GUID.
41 @param SourceGuid Pointer to the source GUID.
42
43 @return DestinationGuid.
44
45 **/
46 GUID *
47 EFIAPI
48 CopyGuid (
49 OUT GUID *DestinationGuid,
50 IN CONST GUID *SourceGuid
51 )
52 {
53 WriteUnaligned64 (
54 (UINT64*)DestinationGuid,
55 ReadUnaligned64 ((CONST UINT64*)SourceGuid)
56 );
57 WriteUnaligned64 (
58 (UINT64*)DestinationGuid + 1,
59 ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)
60 );
61 return DestinationGuid;
62 }
63
64 /**
65 Compares two GUIDs.
66
67 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
68 If there are any bit differences in the two GUIDs, then FALSE is returned.
69 If Guid1 is NULL, then ASSERT().
70 If Guid2 is NULL, then ASSERT().
71
72 @param Guid1 A pointer to a 128 bit GUID.
73 @param Guid2 A pointer to a 128 bit GUID.
74
75 @retval TRUE Guid1 and Guid2 are identical.
76 @retval FALSE Guid1 and Guid2 are not identical.
77
78 **/
79 BOOLEAN
80 EFIAPI
81 CompareGuid (
82 IN CONST GUID *Guid1,
83 IN CONST GUID *Guid2
84 )
85 {
86 UINT64 LowPartOfGuid1;
87 UINT64 LowPartOfGuid2;
88 UINT64 HighPartOfGuid1;
89 UINT64 HighPartOfGuid2;
90
91 LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1);
92 LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2);
93 HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);
94 HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);
95
96 return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);
97 }
98
99 /**
100 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
101 in the target buffer.
102
103 This function searches target the buffer specified by Buffer and Length from
104 the lowest address to the highest address at 128-bit increments for the 128-bit
105 GUID value that matches Guid. If a match is found, then a pointer to the matching
106 GUID in the target buffer is returned. If no match is found, then NULL is returned.
107 If Length is 0, then NULL is returned.
108 If Length > 0 and Buffer is NULL, then ASSERT().
109 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
110 If Length is not aligned on a 128-bit boundary, then ASSERT().
111 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
112
113 @param Buffer Pointer to the target buffer to scan.
114 @param Length Number of bytes in Buffer to scan.
115 @param Guid Value to search for in the target buffer.
116
117 @return A pointer to the matching Guid in the target buffer or NULL otherwise.
118
119 **/
120 VOID *
121 EFIAPI
122 ScanGuid (
123 IN CONST VOID *Buffer,
124 IN UINTN Length,
125 IN CONST GUID *Guid
126 )
127 {
128 CONST GUID *GuidPtr;
129
130 ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
131 ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
132 ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
133
134 GuidPtr = (GUID*)Buffer;
135 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
136 while (GuidPtr < (CONST GUID*)Buffer) {
137 if (CompareGuid (GuidPtr, Guid)) {
138 return (VOID*)GuidPtr;
139 }
140 GuidPtr++;
141 }
142 return NULL;
143 }