1 /** @file 2 ScanMem8() and ScanMemN() implementation. 3 4 The following BaseMemoryLib instances contain the same copy of this file: 5 6 BaseMemoryLib 7 BaseMemoryLibMmx 8 BaseMemoryLibSse2 9 BaseMemoryLibRepStr 10 BaseMemoryLibOptDxe 11 BaseMemoryLibOptPei 12 PeiMemoryLib 13 UefiMemoryLib 14 15 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 16 SPDX-License-Identifier: BSD-2-Clause-Patent 17 18 **/ 19 20 #include "MemLibInternals.h" 21 22 /** 23 Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value 24 in the target buffer. 25 26 This function searches the target buffer specified by Buffer and Length from the lowest 27 address to the highest address for an 8-bit value that matches Value. If a match is found, 28 then a pointer to the matching byte in the target buffer is returned. If no match is found, 29 then NULL is returned. If Length is 0, then NULL is returned. 30 31 If Length > 0 and Buffer is NULL, then ASSERT(). 32 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 33 34 @param Buffer The pointer to the target buffer to scan. 35 @param Length The number of bytes in Buffer to scan. 36 @param Value The value to search for in the target buffer. 37 38 @return A pointer to the matching byte in the target buffer, or NULL otherwise. 39 40 **/ 41 VOID * 42 EFIAPI 43 ScanMem8 ( 44 IN CONST VOID *Buffer, ScanMem16(IN CONST VOID * Buffer,IN UINTN Length,IN UINT16 Value)45 IN UINTN Length, 46 IN UINT8 Value 47 ) 48 { 49 if (Length == 0) { 50 return NULL; 51 } 52 ASSERT (Buffer != NULL); 53 ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); 54 55 return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); 56 } 57 58 /** 59 Scans a target buffer for a UINTN sized value, and returns a pointer to the matching 60 UINTN sized value in the target buffer. 61 62 This function searches the target buffer specified by Buffer and Length from the lowest 63 address to the highest address for a UINTN sized value that matches Value. If a match is found, 64 then a pointer to the matching byte in the target buffer is returned. If no match is found, 65 then NULL is returned. If Length is 0, then NULL is returned. 66 67 If Length > 0 and Buffer is NULL, then ASSERT(). 68 If Buffer is not aligned on a UINTN boundary, then ASSERT(). 69 If Length is not aligned on a UINTN boundary, then ASSERT(). 70 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). 71 72 @param Buffer The pointer to the target buffer to scan. 73 @param Length The number of bytes in Buffer to scan. 74 @param Value The value to search for in the target buffer. 75 76 @return A pointer to the matching byte in the target buffer, or NULL otherwise. 77 78 **/ 79 VOID * 80 EFIAPI 81 ScanMemN ( 82 IN CONST VOID *Buffer, 83 IN UINTN Length, 84 IN UINTN Value 85 ) 86 { 87 if (sizeof (UINTN) == sizeof (UINT64)) { 88 return ScanMem64 (Buffer, Length, (UINT64)Value); 89 } else { 90 return ScanMem32 (Buffer, Length, (UINT32)Value); 91 } 92 } 93 94