]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/hwasan/hwasan_poisoning.cc
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / hwasan / hwasan_poisoning.cc
1 //===-- hwasan_poisoning.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 // This file is a part of HWAddressSanitizer.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "hwasan_poisoning.h"
15
16 #include "hwasan_mapping.h"
17 #include "interception/interception.h"
18 #include "sanitizer_common/sanitizer_common.h"
19
20 namespace __hwasan {
21
22 uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
23   CHECK(IsAligned(p, kShadowAlignment));
24   CHECK(IsAligned(size, kShadowAlignment));
25   uptr shadow_start = MemToShadow(p);
26   uptr shadow_size = MemToShadowSize(size);
27   internal_memset((void *)shadow_start, tag, shadow_size);
28   return AddTagToPointer(p, tag);
29 }
30
31 uptr TagMemory(uptr p, uptr size, tag_t tag) {
32   uptr start = RoundDownTo(p, kShadowAlignment);
33   uptr end = RoundUpTo(p + size, kShadowAlignment);
34   return TagMemoryAligned(start, end - start, tag);
35 }
36
37 }  // namespace __hwasan