]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiMemoryLib/MemLibGuid.c
06b2721c64f407a6ce20c477c6005b8e9ce83f63
[mirror_edk2.git] / MdePkg / Library / UefiMemoryLib / 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 UefiMemoryLib
23
24 **/
25
26 /**
27 This function copies a source GUID to a destination GUID.
28
29 This function copies the contents of the 128-bit GUID specified by SourceGuid
30 to DestinationGuid, and returns DestinationGuid.
31
32 If DestinationGuid is NULL, then ASSERT().
33 If SourceGuid is NULL, then ASSERT().
34
35 @param DestinationGuid Pointer to the destination GUID.
36 @param SourceGuid Pointer to the source GUID.
37
38 @return DestinationGuid
39
40 **/
41 GUID *
42 EFIAPI
43 CopyGuid (
44 OUT GUID *DestinationGuid,
45 IN CONST GUID *SourceGuid
46 )
47 {
48 WriteUnaligned64 (
49 (UINT64*)DestinationGuid,
50 ReadUnaligned64 ((CONST UINT64*)SourceGuid)
51 );
52 WriteUnaligned64 (
53 (UINT64*)DestinationGuid + 1,
54 ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)
55 );
56 return DestinationGuid;
57 }
58
59 /**
60 Compares two GUIDs
61
62 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE
63 is returned. If there are any bit differences in the two GUIDs, then FALSE is
64 returned.
65
66 If Guid1 is NULL, then ASSERT().
67 If Guid2 is NULL, then ASSERT().
68
69 @param Guid1 guid to compare
70 @param Guid2 guid to compare
71
72 @retval TRUE if Guid1 == Guid2
73 @retval FALSE if Guid1 != Guid2
74
75 **/
76 BOOLEAN
77 EFIAPI
78 CompareGuid (
79 IN CONST GUID *Guid1,
80 IN CONST GUID *Guid2
81 )
82 {
83 return (BOOLEAN)(
84 ReadUnaligned64 ((CONST UINT64*)Guid1)
85 == ReadUnaligned64 ((CONST UINT64*)Guid2) &&
86 ReadUnaligned64 ((CONST UINT64*)Guid1 + 1)
87 == ReadUnaligned64 ((CONST UINT64*)Guid2 + 1)
88 );
89 }
90
91 /**
92 Scans a target buffer for a GUID, and returns a pointer to the matching GUID
93 in the target buffer.
94
95 This function searches target the buffer specified by Buffer and Length from
96 the lowest address to the highest address at 128-bit increments for the
97 128-bit GUID value that matches Guid. If a match is found, then a pointer to
98 the matching GUID in the target buffer is returned. If no match is found,
99 then NULL is returned. If Length is 0, then NULL is returned.
100
101 If Buffer is NULL, then ASSERT().
102 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
103 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
104
105 @param Buffer Pointer to the target buffer to scan.
106 @param Length Number of bytes in Buffer to scan.
107 @param Guid Value to search for in the target buffer.
108
109 @return Pointer to the first occurrence.
110 @retval NULL if Length == 0 or Guid was not found.
111 **/
112 VOID *
113 EFIAPI
114 ScanGuid (
115 IN CONST VOID *Buffer,
116 IN UINTN Length,
117 IN CONST GUID *Guid
118 )
119 {
120 CONST GUID *GuidPtr;
121
122 GuidPtr = (GUID*)Buffer;
123 Buffer = GuidPtr + Length / sizeof (*GuidPtr);
124 while (GuidPtr < (CONST GUID*)Buffer) {
125 if (CompareGuid (GuidPtr, Guid)) {
126 return (VOID*)GuidPtr;
127 }
128 GuidPtr++;
129 }
130 return NULL;
131 }