]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/hwasan/hwasan_memintrinsics.cc
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / lib / hwasan / hwasan_memintrinsics.cc
1 //===-- hwasan_memintrinsics.cc ---------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file is a part of HWAddressSanitizer and contains HWASAN versions of
12 /// memset, memcpy and memmove
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #include <string.h>
17 #include "hwasan.h"
18 #include "hwasan_checks.h"
19 #include "hwasan_flags.h"
20 #include "hwasan_interface_internal.h"
21 #include "sanitizer_common/sanitizer_libc.h"
22
23 using namespace __hwasan;
24
25 void *__hwasan_memset(void *block, int c, uptr size) {
26   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
27       reinterpret_cast<uptr>(block), size);
28   return memset(UntagPtr(block), c, size);
29 }
30
31 void *__hwasan_memcpy(void *to, const void *from, uptr size) {
32   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
33       reinterpret_cast<uptr>(to), size);
34   CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
35       reinterpret_cast<uptr>(from), size);
36   return memcpy(UntagPtr(to), UntagPtr(from), size);
37 }
38
39 void *__hwasan_memmove(void *to, const void *from, uptr size) {
40   CheckAddressSized<ErrorAction::Recover, AccessType::Store>(
41       reinterpret_cast<uptr>(to), size);
42   CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
43       reinterpret_cast<uptr>(from), size);
44   return memmove(UntagPtr(to), UntagPtr(from), size);
45 }