]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/dfsan/dfsan_platform.h
Import tzdata 2018d
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / dfsan / dfsan_platform.h
1 //===-- dfsan_platform.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 // This file is a part of DataFlowSanitizer.
11 //
12 // Platform specific information for DFSan.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef DFSAN_PLATFORM_H
16 #define DFSAN_PLATFORM_H
17
18 namespace __dfsan {
19
20 #if defined(__x86_64__)
21 struct Mapping {
22   static const uptr kShadowAddr = 0x10000;
23   static const uptr kUnionTableAddr = 0x200000000000;
24   static const uptr kAppAddr = 0x700000008000;
25   static const uptr kShadowMask = ~0x700000000000;
26 };
27 #elif defined(__mips64)
28 struct Mapping {
29   static const uptr kShadowAddr = 0x10000;
30   static const uptr kUnionTableAddr = 0x2000000000;
31   static const uptr kAppAddr = 0xF000008000;
32   static const uptr kShadowMask = ~0xF000000000;
33 };
34 #elif defined(__aarch64__)
35 struct Mapping39 {
36   static const uptr kShadowAddr = 0x10000;
37   static const uptr kUnionTableAddr = 0x1000000000;
38   static const uptr kAppAddr = 0x7000008000;
39   static const uptr kShadowMask = ~0x7800000000;
40 };
41
42 struct Mapping42 {
43   static const uptr kShadowAddr = 0x10000;
44   static const uptr kUnionTableAddr = 0x8000000000;
45   static const uptr kAppAddr = 0x3ff00008000;
46   static const uptr kShadowMask = ~0x3c000000000;
47 };
48
49 struct Mapping48 {
50   static const uptr kShadowAddr = 0x10000;
51   static const uptr kUnionTableAddr = 0x8000000000;
52   static const uptr kAppAddr = 0xffff00008000;
53   static const uptr kShadowMask = ~0xfffff0000000;
54 };
55
56 extern int vmaSize;
57 # define DFSAN_RUNTIME_VMA 1
58 #else
59 # error "DFSan not supported for this platform!"
60 #endif
61
62 enum MappingType {
63   MAPPING_SHADOW_ADDR,
64   MAPPING_UNION_TABLE_ADDR,
65   MAPPING_APP_ADDR,
66   MAPPING_SHADOW_MASK
67 };
68
69 template<typename Mapping, int Type>
70 uptr MappingImpl(void) {
71   switch (Type) {
72     case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr;
73     case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr;
74     case MAPPING_APP_ADDR: return Mapping::kAppAddr;
75     case MAPPING_SHADOW_MASK: return Mapping::kShadowMask;
76   }
77 }
78
79 template<int Type>
80 uptr MappingArchImpl(void) {
81 #ifdef __aarch64__
82   switch (vmaSize) {
83     case 39: return MappingImpl<Mapping39, Type>();
84     case 42: return MappingImpl<Mapping42, Type>();
85     case 48: return MappingImpl<Mapping48, Type>();
86   }
87   DCHECK(0);
88   return 0;
89 #else
90   return MappingImpl<Mapping, Type>();
91 #endif
92 }
93
94 ALWAYS_INLINE
95 uptr ShadowAddr() {
96   return MappingArchImpl<MAPPING_SHADOW_ADDR>();
97 }
98
99 ALWAYS_INLINE
100 uptr UnionTableAddr() {
101   return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>();
102 }
103
104 ALWAYS_INLINE
105 uptr AppAddr() {
106   return MappingArchImpl<MAPPING_APP_ADDR>();
107 }
108
109 ALWAYS_INLINE
110 uptr ShadowMask() {
111   return MappingArchImpl<MAPPING_SHADOW_MASK>();
112 }
113
114 }  // namespace __dfsan
115
116 #endif