]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/hwasan/hwasan_mapping.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / hwasan / hwasan_mapping.h
1 //===-- hwasan_mapping.h ----------------------------------------*- 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 defines memory mapping.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef HWASAN_MAPPING_H
16 #define HWASAN_MAPPING_H
17
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19 #include "hwasan_interface_internal.h"
20
21 // Typical mapping on Linux/x86_64:
22 // with dynamic shadow mapped at [0x770d59f40000, 0x7f0d59f40000]:
23 // || [0x7f0d59f40000, 0x7fffffffffff] || HighMem    ||
24 // || [0x7efe2f934000, 0x7f0d59f3ffff] || HighShadow ||
25 // || [0x7e7e2f934000, 0x7efe2f933fff] || ShadowGap  ||
26 // || [0x770d59f40000, 0x7e7e2f933fff] || LowShadow  ||
27 // || [0x000000000000, 0x770d59f3ffff] || LowMem     ||
28
29 // Typical mapping on Android/AArch64
30 // with dynamic shadow mapped: [0x007477480000, 0x007c77480000]:
31 // || [0x007c77480000, 0x007fffffffff] || HighMem    ||
32 // || [0x007c3ebc8000, 0x007c7747ffff] || HighShadow ||
33 // || [0x007bbebc8000, 0x007c3ebc7fff] || ShadowGap  ||
34 // || [0x007477480000, 0x007bbebc7fff] || LowShadow  ||
35 // || [0x000000000000, 0x00747747ffff] || LowMem     ||
36
37 // Reasonable values are 4 (for 1/16th shadow) and 6 (for 1/64th).
38 constexpr uptr kShadowScale = 4;
39 constexpr uptr kShadowAlignment = 1ULL << kShadowScale;
40
41 namespace __hwasan {
42
43 inline uptr MemToShadow(uptr untagged_addr) {
44   return (untagged_addr >> kShadowScale) +
45          __hwasan_shadow_memory_dynamic_address;
46 }
47 inline uptr ShadowToMem(uptr shadow_addr) {
48   return (shadow_addr - __hwasan_shadow_memory_dynamic_address) << kShadowScale;
49 }
50 inline uptr MemToShadowSize(uptr size) {
51   return size >> kShadowScale;
52 }
53
54 bool MemIsApp(uptr p);
55
56 }  // namespace __hwasan
57
58 #endif  // HWASAN_MAPPING_H