Path: blob/main/sys/contrib/edk2/Include/Library/BaseMemoryLib.h
48383 views
/** @file1Provides copy memory, fill memory, zero memory, and GUID functions.23The Base Memory Library provides optimized implementations for common memory-based operations.4These functions should be used in place of coding your own loops to do equivalent common functions.5This allows optimized library implementations to help increase performance.67Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>8SPDX-License-Identifier: BSD-2-Clause-Patent910**/1112#ifndef __BASE_MEMORY_LIB__13#define __BASE_MEMORY_LIB__1415/**16Copies a source buffer to a destination buffer, and returns the destination buffer.1718This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns19DestinationBuffer. The implementation must be reentrant, and it must handle the case20where SourceBuffer overlaps DestinationBuffer.2122If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().23If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().2425@param DestinationBuffer The pointer to the destination buffer of the memory copy.26@param SourceBuffer The pointer to the source buffer of the memory copy.27@param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.2829@return DestinationBuffer.3031**/32VOID *33EFIAPI34CopyMem (35OUT VOID *DestinationBuffer,36IN CONST VOID *SourceBuffer,37IN UINTN Length38);3940/**41Fills a target buffer with a byte value, and returns the target buffer.4243This function fills Length bytes of Buffer with Value, and returns Buffer.4445If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().4647@param Buffer The memory to set.48@param Length The number of bytes to set.49@param Value The value with which to fill Length bytes of Buffer.5051@return Buffer.5253**/54VOID *55EFIAPI56SetMem (57OUT VOID *Buffer,58IN UINTN Length,59IN UINT8 Value60);6162/**63Fills a target buffer with a 16-bit value, and returns the target buffer.6465This function fills Length bytes of Buffer with the 16-bit value specified by66Value, and returns Buffer. Value is repeated every 16-bits in for Length67bytes of Buffer.6869If Length > 0 and Buffer is NULL, then ASSERT().70If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().71If Buffer is not aligned on a 16-bit boundary, then ASSERT().72If Length is not aligned on a 16-bit boundary, then ASSERT().7374@param Buffer The pointer to the target buffer to fill.75@param Length The number of bytes in Buffer to fill.76@param Value The value with which to fill Length bytes of Buffer.7778@return Buffer.7980**/81VOID *82EFIAPI83SetMem16 (84OUT VOID *Buffer,85IN UINTN Length,86IN UINT16 Value87);8889/**90Fills a target buffer with a 32-bit value, and returns the target buffer.9192This function fills Length bytes of Buffer with the 32-bit value specified by93Value, and returns Buffer. Value is repeated every 32-bits in for Length94bytes of Buffer.9596If Length > 0 and Buffer is NULL, then ASSERT().97If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().98If Buffer is not aligned on a 32-bit boundary, then ASSERT().99If Length is not aligned on a 32-bit boundary, then ASSERT().100101@param Buffer The pointer to the target buffer to fill.102@param Length The number of bytes in Buffer to fill.103@param Value The value with which to fill Length bytes of Buffer.104105@return Buffer.106107**/108VOID *109EFIAPI110SetMem32 (111OUT VOID *Buffer,112IN UINTN Length,113IN UINT32 Value114);115116/**117Fills a target buffer with a 64-bit value, and returns the target buffer.118119This function fills Length bytes of Buffer with the 64-bit value specified by120Value, and returns Buffer. Value is repeated every 64-bits in for Length121bytes of Buffer.122123If Length > 0 and Buffer is NULL, then ASSERT().124If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().125If Buffer is not aligned on a 64-bit boundary, then ASSERT().126If Length is not aligned on a 64-bit boundary, then ASSERT().127128@param Buffer The pointer to the target buffer to fill.129@param Length The number of bytes in Buffer to fill.130@param Value The value with which to fill Length bytes of Buffer.131132@return Buffer.133134**/135VOID *136EFIAPI137SetMem64 (138OUT VOID *Buffer,139IN UINTN Length,140IN UINT64 Value141);142143/**144Fills a target buffer with a value that is size UINTN, and returns the target buffer.145146This function fills Length bytes of Buffer with the UINTN sized value specified by147Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length148bytes of Buffer.149150If Length > 0 and Buffer is NULL, then ASSERT().151If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().152If Buffer is not aligned on a UINTN boundary, then ASSERT().153If Length is not aligned on a UINTN boundary, then ASSERT().154155@param Buffer The pointer to the target buffer to fill.156@param Length The number of bytes in Buffer to fill.157@param Value The value with which to fill Length bytes of Buffer.158159@return Buffer.160161**/162VOID *163EFIAPI164SetMemN (165OUT VOID *Buffer,166IN UINTN Length,167IN UINTN Value168);169170/**171Fills a target buffer with zeros, and returns the target buffer.172173This function fills Length bytes of Buffer with zeros, and returns Buffer.174175If Length > 0 and Buffer is NULL, then ASSERT().176If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().177178@param Buffer The pointer to the target buffer to fill with zeros.179@param Length The number of bytes in Buffer to fill with zeros.180181@return Buffer.182183**/184VOID *185EFIAPI186ZeroMem (187OUT VOID *Buffer,188IN UINTN Length189);190191/**192Compares the contents of two buffers.193194This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.195If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the196value returned is the first mismatched byte in SourceBuffer subtracted from the first197mismatched byte in DestinationBuffer.198199If Length > 0 and DestinationBuffer is NULL, then ASSERT().200If Length > 0 and SourceBuffer is NULL, then ASSERT().201If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().202If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().203204@param DestinationBuffer The pointer to the destination buffer to compare.205@param SourceBuffer The pointer to the source buffer to compare.206@param Length The number of bytes to compare.207208@return 0 All Length bytes of the two buffers are identical.209@retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first210mismatched byte in DestinationBuffer.211212**/213INTN214EFIAPI215CompareMem (216IN CONST VOID *DestinationBuffer,217IN CONST VOID *SourceBuffer,218IN UINTN Length219);220221/**222Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value223in the target buffer.224225This function searches target the buffer specified by Buffer and Length from the lowest226address to the highest address for an 8-bit value that matches Value. If a match is found,227then a pointer to the matching byte in the target buffer is returned. If no match is found,228then NULL is returned. If Length is 0, then NULL is returned.229230If Length > 0 and Buffer is NULL, then ASSERT().231If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().232233@param Buffer The pointer to the target buffer to scan.234@param Length The number of bytes in Buffer to scan.235@param Value The value to search for in the target buffer.236237@return A pointer to the matching byte in the target buffer, otherwise NULL.238239**/240VOID *241EFIAPI242ScanMem8 (243IN CONST VOID *Buffer,244IN UINTN Length,245IN UINT8 Value246);247248/**249Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value250in the target buffer.251252This function searches target the buffer specified by Buffer and Length from the lowest253address to the highest address for a 16-bit value that matches Value. If a match is found,254then a pointer to the matching byte in the target buffer is returned. If no match is found,255then NULL is returned. If Length is 0, then NULL is returned.256257If Length > 0 and Buffer is NULL, then ASSERT().258If Buffer is not aligned on a 16-bit boundary, then ASSERT().259If Length is not aligned on a 16-bit boundary, then ASSERT().260If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().261262@param Buffer The pointer to the target buffer to scan.263@param Length The number of bytes in Buffer to scan.264@param Value The value to search for in the target buffer.265266@return A pointer to the matching byte in the target buffer, otherwise NULL.267268**/269VOID *270EFIAPI271ScanMem16 (272IN CONST VOID *Buffer,273IN UINTN Length,274IN UINT16 Value275);276277/**278Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value279in the target buffer.280281This function searches target the buffer specified by Buffer and Length from the lowest282address to the highest address for a 32-bit value that matches Value. If a match is found,283then a pointer to the matching byte in the target buffer is returned. If no match is found,284then NULL is returned. If Length is 0, then NULL is returned.285286If Length > 0 and Buffer is NULL, then ASSERT().287If Buffer is not aligned on a 32-bit boundary, then ASSERT().288If Length is not aligned on a 32-bit boundary, then ASSERT().289If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().290291@param Buffer The pointer to the target buffer to scan.292@param Length The number of bytes in Buffer to scan.293@param Value The value to search for in the target buffer.294295@return A pointer to the matching byte in the target buffer, otherwise NULL.296297**/298VOID *299EFIAPI300ScanMem32 (301IN CONST VOID *Buffer,302IN UINTN Length,303IN UINT32 Value304);305306/**307Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value308in the target buffer.309310This function searches target the buffer specified by Buffer and Length from the lowest311address to the highest address for a 64-bit value that matches Value. If a match is found,312then a pointer to the matching byte in the target buffer is returned. If no match is found,313then NULL is returned. If Length is 0, then NULL is returned.314315If Length > 0 and Buffer is NULL, then ASSERT().316If Buffer is not aligned on a 64-bit boundary, then ASSERT().317If Length is not aligned on a 64-bit boundary, then ASSERT().318If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().319320@param Buffer The pointer to the target buffer to scan.321@param Length The number of bytes in Buffer to scan.322@param Value The value to search for in the target buffer.323324@return A pointer to the matching byte in the target buffer, otherwise NULL.325326**/327VOID *328EFIAPI329ScanMem64 (330IN CONST VOID *Buffer,331IN UINTN Length,332IN UINT64 Value333);334335/**336Scans a target buffer for a UINTN sized value, and returns a pointer to the matching337UINTN sized value in the target buffer.338339This function searches target the buffer specified by Buffer and Length from the lowest340address to the highest address for a UINTN sized value that matches Value. If a match is found,341then a pointer to the matching byte in the target buffer is returned. If no match is found,342then NULL is returned. If Length is 0, then NULL is returned.343344If Length > 0 and Buffer is NULL, then ASSERT().345If Buffer is not aligned on a UINTN boundary, then ASSERT().346If Length is not aligned on a UINTN boundary, then ASSERT().347If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().348349@param Buffer The pointer to the target buffer to scan.350@param Length The number of bytes in Buffer to scan.351@param Value The value to search for in the target buffer.352353@return A pointer to the matching byte in the target buffer, otherwise NULL.354355**/356VOID *357EFIAPI358ScanMemN (359IN CONST VOID *Buffer,360IN UINTN Length,361IN UINTN Value362);363364/**365Copies a source GUID to a destination GUID.366367This function copies the contents of the 128-bit GUID specified by SourceGuid to368DestinationGuid, and returns DestinationGuid.369370If DestinationGuid is NULL, then ASSERT().371If SourceGuid is NULL, then ASSERT().372373@param DestinationGuid The pointer to the destination GUID.374@param SourceGuid The pointer to the source GUID.375376@return DestinationGuid.377378**/379GUID *380EFIAPI381CopyGuid (382OUT GUID *DestinationGuid,383IN CONST GUID *SourceGuid384);385386/**387Compares two GUIDs.388389This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.390If there are any bit differences in the two GUIDs, then FALSE is returned.391392If Guid1 is NULL, then ASSERT().393If Guid2 is NULL, then ASSERT().394395@param Guid1 A pointer to a 128 bit GUID.396@param Guid2 A pointer to a 128 bit GUID.397398@retval TRUE Guid1 and Guid2 are identical.399@retval FALSE Guid1 and Guid2 are not identical.400401**/402BOOLEAN403EFIAPI404CompareGuid (405IN CONST GUID *Guid1,406IN CONST GUID *Guid2407);408409/**410Scans a target buffer for a GUID, and returns a pointer to the matching GUID411in the target buffer.412413This function searches target the buffer specified by Buffer and Length from414the lowest address to the highest address at 128-bit increments for the 128-bit415GUID value that matches Guid. If a match is found, then a pointer to the matching416GUID in the target buffer is returned. If no match is found, then NULL is returned.417If Length is 0, then NULL is returned.418419If Length > 0 and Buffer is NULL, then ASSERT().420If Buffer is not aligned on a 32-bit boundary, then ASSERT().421If Length is not aligned on a 128-bit boundary, then ASSERT().422If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().423424@param Buffer The pointer to the target buffer to scan.425@param Length The number of bytes in Buffer to scan.426@param Guid The value to search for in the target buffer.427428@return A pointer to the matching Guid in the target buffer, otherwise NULL.429430**/431VOID *432EFIAPI433ScanGuid (434IN CONST VOID *Buffer,435IN UINTN Length,436IN CONST GUID *Guid437);438439/**440Checks if the given GUID is a zero GUID.441442This function checks whether the given GUID is a zero GUID. If the GUID is443identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.444445If Guid is NULL, then ASSERT().446447@param Guid The pointer to a 128 bit GUID.448449@retval TRUE Guid is a zero GUID.450@retval FALSE Guid is not a zero GUID.451452**/453BOOLEAN454EFIAPI455IsZeroGuid (456IN CONST GUID *Guid457);458459/**460Checks if the contents of a buffer are all zeros.461462This function checks whether the contents of a buffer are all zeros. If the463contents are all zeros, return TRUE. Otherwise, return FALSE.464465If Length > 0 and Buffer is NULL, then ASSERT().466If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().467468@param Buffer The pointer to the buffer to be checked.469@param Length The size of the buffer (in bytes) to be checked.470471@retval TRUE Contents of the buffer are all zeros.472@retval FALSE Contents of the buffer are not all zeros.473474**/475BOOLEAN476EFIAPI477IsZeroBuffer (478IN CONST VOID *Buffer,479IN UINTN Length480);481482#endif483484485