MemLibGuid.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
4632N/A/** @file
4632N/A Implementation of GUID functions.
4632N/A
4632N/A The following BaseMemoryLib instances contain the same copy of this file:
4632N/A
4632N/A BaseMemoryLib
4632N/A BaseMemoryLibMmx
4632N/A BaseMemoryLibSse2
4632N/A BaseMemoryLibRepStr
4632N/A BaseMemoryLibOptDxe
4632N/A BaseMemoryLibOptPei
4632N/A PeiMemoryLib
4632N/A UefiMemoryLib
4632N/A
4632N/A Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
4632N/A This program and the accompanying materials
4632N/A are licensed and made available under the terms and conditions of the BSD License
4632N/A which accompanies this distribution. The full text of the license may be found at
4632N/A http://opensource.org/licenses/bsd-license.php.
4632N/A
4632N/A THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4632N/A WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4632N/A
4632N/A**/
4632N/A
4632N/A#include "MemLibInternals.h"
4632N/A
4632N/A/**
4632N/A Copies a source GUID to a destination GUID.
4632N/A
4632N/A This function copies the contents of the 128-bit GUID specified by SourceGuid to
4632N/A DestinationGuid, and returns DestinationGuid.
4632N/A
4632N/A If DestinationGuid is NULL, then ASSERT().
4632N/A If SourceGuid is NULL, then ASSERT().
4632N/A
4632N/A @param DestinationGuid The pointer to the destination GUID.
4632N/A @param SourceGuid The pointer to the source GUID.
4632N/A
4632N/A @return DestinationGuid.
4632N/A
4632N/A**/
4632N/AGUID *
4632N/AEFIAPI
4632N/ACopyGuid (
4632N/A OUT GUID *DestinationGuid,
4632N/A IN CONST GUID *SourceGuid
4632N/A )
4632N/A{
4632N/A WriteUnaligned64 (
4632N/A (UINT64*)DestinationGuid,
4632N/A ReadUnaligned64 ((CONST UINT64*)SourceGuid)
4632N/A );
4632N/A WriteUnaligned64 (
4632N/A (UINT64*)DestinationGuid + 1,
4632N/A ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1)
4632N/A );
4632N/A return DestinationGuid;
4632N/A}
4632N/A
4632N/A/**
4632N/A Compares two GUIDs.
4632N/A
4632N/A This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.
4632N/A If there are any bit differences in the two GUIDs, then FALSE is returned.
4632N/A
4632N/A If Guid1 is NULL, then ASSERT().
4632N/A If Guid2 is NULL, then ASSERT().
4632N/A
4632N/A @param Guid1 A pointer to a 128 bit GUID.
4632N/A @param Guid2 A pointer to a 128 bit GUID.
4632N/A
4632N/A @retval TRUE Guid1 and Guid2 are identical.
4632N/A @retval FALSE Guid1 and Guid2 are not identical.
4632N/A
4632N/A**/
4632N/ABOOLEAN
4632N/AEFIAPI
4632N/ACompareGuid (
4632N/A IN CONST GUID *Guid1,
5333N/A IN CONST GUID *Guid2
4632N/A )
5333N/A{
4632N/A UINT64 LowPartOfGuid1;
4632N/A UINT64 LowPartOfGuid2;
4632N/A UINT64 HighPartOfGuid1;
4632N/A UINT64 HighPartOfGuid2;
4632N/A
4632N/A LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1);
4632N/A LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2);
4632N/A HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1);
4632N/A HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1);
4632N/A
4632N/A return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2);
4632N/A}
4632N/A
4632N/A/**
4632N/A Scans a target buffer for a GUID, and returns a pointer to the matching GUID
4632N/A in the target buffer.
4632N/A
4632N/A This function searches the target buffer specified by Buffer and Length from
4632N/A the lowest address to the highest address at 128-bit increments for the 128-bit
5555N/A GUID value that matches Guid. If a match is found, then a pointer to the matching
5555N/A GUID in the target buffer is returned. If no match is found, then NULL is returned.
5555N/A If Length is 0, then NULL is returned.
5555N/A
5555N/A If Length > 0 and Buffer is NULL, then ASSERT().
5555N/A If Buffer is not aligned on a 32-bit boundary, then ASSERT().
5555N/A If Length is not aligned on a 128-bit boundary, then ASSERT().
4632N/A If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
5555N/A
4632N/A @param Buffer The pointer to the target buffer to scan.
4632N/A @param Length The number of bytes in Buffer to scan.
4632N/A @param Guid The value to search for in the target buffer.
4632N/A
4632N/A @return A pointer to the matching Guid in the target buffer or NULL otherwise.
4632N/A
4632N/A**/
4632N/AVOID *
4632N/AEFIAPI
4632N/AScanGuid (
4632N/A IN CONST VOID *Buffer,
4632N/A IN UINTN Length,
4632N/A IN CONST GUID *Guid
4632N/A )
4632N/A{
4632N/A CONST GUID *GuidPtr;
5555N/A
5555N/A ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0);
4632N/A ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1));
4632N/A ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0);
4632N/A
4632N/A GuidPtr = (GUID*)Buffer;
5555N/A Buffer = GuidPtr + Length / sizeof (*GuidPtr);
4632N/A while (GuidPtr < (CONST GUID*)Buffer) {
4632N/A if (CompareGuid (GuidPtr, Guid)) {
4632N/A return (VOID*)GuidPtr;
}
GuidPtr++;
}
return NULL;
}