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