• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #include <string.h>
16 #include "hwasan.h"
17 #include "hwasan_checks.h"
18 #include "hwasan_flags.h"
19 #include "hwasan_interface_internal.h"
20 #include "sanitizer_common/sanitizer_libc.h"
21 
22 using namespace __hwasan;
23 
__hwasan_memset(void * block,int c,uptr size)24 void *__hwasan_memset(void *block, int c, uptr size) {
25   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
26       reinterpret_cast<uptr>(block), size);
27   return memset(UntagPtr(block), c, size);
28 }
29 
__hwasan_memcpy(void * to,const void * from,uptr size)30 void *__hwasan_memcpy(void *to, const void *from, uptr size) {
31   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
32       reinterpret_cast<uptr>(to), size);
33   CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
34       reinterpret_cast<uptr>(from), size);
35   return memcpy(UntagPtr(to), UntagPtr(from), size);
36 }
37 
__hwasan_memmove(void * to,const void * from,uptr size)38 void *__hwasan_memmove(void *to, const void *from, uptr size) {
39   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
40       reinterpret_cast<uptr>(to), size);
41   CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
42       reinterpret_cast<uptr>(from), size);
43   return memmove(UntagPtr(to), UntagPtr(from), size);
44 }
45