ScanMem8Wrapper.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /** @file
  2. ScanMem8() and ScanMemN() implementation.
  3. The following BaseMemoryLib instances contain the same copy of this file:
  4. BaseMemoryLib
  5. BaseMemoryLibMmx
  6. BaseMemoryLibSse2
  7. BaseMemoryLibRepStr
  8. BaseMemoryLibOptDxe
  9. BaseMemoryLibOptPei
  10. PeiMemoryLib
  11. UefiMemoryLib
  12. Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
  13. This program and the accompanying materials
  14. are licensed and made available under the terms and conditions of the BSD License
  15. which accompanies this distribution. The full text of the license may be found at
  16. http://opensource.org/licenses/bsd-license.php
  17. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  18. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  19. **/
  20. #include "MemLibInternals.h"
  21. /**
  22. Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value
  23. in the target buffer.
  24. This function searches the target buffer specified by Buffer and Length from the lowest
  25. address to the highest address for an 8-bit value that matches Value. If a match is found,
  26. then a pointer to the matching byte in the target buffer is returned. If no match is found,
  27. then NULL is returned. If Length is 0, then NULL is returned.
  28. If Length > 0 and Buffer is NULL, then ASSERT().
  29. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  30. @param Buffer Pointer to the target buffer to scan.
  31. @param Length Number of bytes in Buffer to scan.
  32. @param Value Value to search for in the target buffer.
  33. @return A pointer to the matching byte in the target buffer or NULL otherwise.
  34. **/
  35. VOID *
  36. EFIAPI
  37. ScanMem8 (
  38. IN CONST VOID *Buffer,
  39. IN UINTN Length,
  40. IN UINT8 Value
  41. )
  42. {
  43. if (Length == 0) {
  44. return NULL;
  45. }
  46. ASSERT (Buffer != NULL);
  47. ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
  48. return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);
  49. }
  50. /**
  51. Scans a target buffer for a UINTN sized value, and returns a pointer to the matching
  52. UINTN sized value in the target buffer.
  53. This function searches the target buffer specified by Buffer and Length from the lowest
  54. address to the highest address for a UINTN sized value that matches Value. If a match is found,
  55. then a pointer to the matching byte in the target buffer is returned. If no match is found,
  56. then NULL is returned. If Length is 0, then NULL is returned.
  57. If Length > 0 and Buffer is NULL, then ASSERT().
  58. If Buffer is not aligned on a UINTN boundary, then ASSERT().
  59. If Length is not aligned on a UINTN boundary, then ASSERT().
  60. If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
  61. @param Buffer Pointer to the target buffer to scan.
  62. @param Length Number of bytes in Buffer to scan.
  63. @param Value Value to search for in the target buffer.
  64. @return A pointer to the matching byte in the target buffer or NULL otherwise.
  65. **/
  66. VOID *
  67. EFIAPI
  68. ScanMemN (
  69. IN CONST VOID *Buffer,
  70. IN UINTN Length,
  71. IN UINTN Value
  72. )
  73. {
  74. if (sizeof (UINTN) == sizeof (UINT64)) {
  75. return ScanMem64 (Buffer, Length, (UINT64)Value);
  76. } else {
  77. return ScanMem32 (Buffer, Length, (UINT32)Value);
  78. }
  79. }