hwasan_memintrinsics.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //===-- hwasan_memintrinsics.cpp --------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// \file
  10. /// This file is a part of HWAddressSanitizer and contains HWASAN versions of
  11. /// memset, memcpy and memmove
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include <string.h>
  15. #include "hwasan.h"
  16. #include "hwasan_checks.h"
  17. #include "hwasan_flags.h"
  18. #include "hwasan_interface_internal.h"
  19. #include "sanitizer_common/sanitizer_libc.h"
  20. using namespace __hwasan;
  21. void *__hwasan_memset(void *block, int c, uptr size) {
  22. CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
  23. reinterpret_cast<uptr>(block), size);
  24. return memset(block, c, size);
  25. }
  26. void *__hwasan_memcpy(void *to, const void *from, uptr size) {
  27. CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
  28. reinterpret_cast<uptr>(to), size);
  29. CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
  30. reinterpret_cast<uptr>(from), size);
  31. return memcpy(to, from, size);
  32. }
  33. void *__hwasan_memmove(void *to, const void *from, uptr size) {
  34. CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
  35. reinterpret_cast<uptr>(to), size);
  36. CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
  37. reinterpret_cast<uptr>(from), size);
  38. return memmove(UntagPtr(to), UntagPtr(from), size);
  39. }