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