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