[DominatorTree] Add support for mixed pre/post CFG views.
[llvm-project.git] / compiler-rt / lib / dfsan / dfsan_platform.h
blob4ff68b9d40b6044c0e8ab89527e1df2efc8eaeae
1 //===-- dfsan_platform.h ----------------------------------------*- 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 // This file is a part of DataFlowSanitizer.
11 // Platform specific information for DFSan.
12 //===----------------------------------------------------------------------===//
14 #ifndef DFSAN_PLATFORM_H
15 #define DFSAN_PLATFORM_H
17 namespace __dfsan {
19 #if defined(__x86_64__)
20 struct Mapping {
21 static const uptr kShadowAddr = 0x10000;
22 static const uptr kUnionTableAddr = 0x200000000000;
23 static const uptr kAppAddr = 0x700000008000;
24 static const uptr kShadowMask = ~0x700000000000;
26 #elif defined(__mips64)
27 struct Mapping {
28 static const uptr kShadowAddr = 0x10000;
29 static const uptr kUnionTableAddr = 0x2000000000;
30 static const uptr kAppAddr = 0xF000008000;
31 static const uptr kShadowMask = ~0xF000000000;
33 #elif defined(__aarch64__)
34 struct Mapping39 {
35 static const uptr kShadowAddr = 0x10000;
36 static const uptr kUnionTableAddr = 0x1000000000;
37 static const uptr kAppAddr = 0x7000008000;
38 static const uptr kShadowMask = ~0x7800000000;
41 struct Mapping42 {
42 static const uptr kShadowAddr = 0x10000;
43 static const uptr kUnionTableAddr = 0x8000000000;
44 static const uptr kAppAddr = 0x3ff00008000;
45 static const uptr kShadowMask = ~0x3c000000000;
48 struct Mapping48 {
49 static const uptr kShadowAddr = 0x10000;
50 static const uptr kUnionTableAddr = 0x8000000000;
51 static const uptr kAppAddr = 0xffff00008000;
52 static const uptr kShadowMask = ~0xfffff0000000;
55 extern int vmaSize;
56 # define DFSAN_RUNTIME_VMA 1
57 #else
58 # error "DFSan not supported for this platform!"
59 #endif
61 enum MappingType {
62 MAPPING_SHADOW_ADDR,
63 MAPPING_UNION_TABLE_ADDR,
64 MAPPING_APP_ADDR,
65 MAPPING_SHADOW_MASK
68 template<typename Mapping, int Type>
69 uptr MappingImpl(void) {
70 switch (Type) {
71 case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr;
72 case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr;
73 case MAPPING_APP_ADDR: return Mapping::kAppAddr;
74 case MAPPING_SHADOW_MASK: return Mapping::kShadowMask;
78 template<int Type>
79 uptr MappingArchImpl(void) {
80 #ifdef __aarch64__
81 switch (vmaSize) {
82 case 39: return MappingImpl<Mapping39, Type>();
83 case 42: return MappingImpl<Mapping42, Type>();
84 case 48: return MappingImpl<Mapping48, Type>();
86 DCHECK(0);
87 return 0;
88 #else
89 return MappingImpl<Mapping, Type>();
90 #endif
93 ALWAYS_INLINE
94 uptr ShadowAddr() {
95 return MappingArchImpl<MAPPING_SHADOW_ADDR>();
98 ALWAYS_INLINE
99 uptr UnionTableAddr() {
100 return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>();
103 ALWAYS_INLINE
104 uptr AppAddr() {
105 return MappingArchImpl<MAPPING_APP_ADDR>();
108 ALWAYS_INLINE
109 uptr ShadowMask() {
110 return MappingArchImpl<MAPPING_SHADOW_MASK>();
113 } // namespace __dfsan
115 #endif