xref: /aosp_15_r20/external/compiler-rt/lib/dfsan/dfsan_platform.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- dfsan_platform.h ----------------------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file is a part of DataFlowSanitizer.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot // Platform specific information for DFSan.
13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot #ifndef DFSAN_PLATFORM_H
16*7c3d14c8STreehugger Robot #define DFSAN_PLATFORM_H
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot namespace __dfsan {
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot #if defined(__x86_64__)
21*7c3d14c8STreehugger Robot struct Mapping {
22*7c3d14c8STreehugger Robot   static const uptr kShadowAddr = 0x10000;
23*7c3d14c8STreehugger Robot   static const uptr kUnionTableAddr = 0x200000000000;
24*7c3d14c8STreehugger Robot   static const uptr kAppAddr = 0x700000008000;
25*7c3d14c8STreehugger Robot   static const uptr kShadowMask = ~0x700000000000;
26*7c3d14c8STreehugger Robot };
27*7c3d14c8STreehugger Robot #elif defined(__mips64)
28*7c3d14c8STreehugger Robot struct Mapping {
29*7c3d14c8STreehugger Robot   static const uptr kShadowAddr = 0x10000;
30*7c3d14c8STreehugger Robot   static const uptr kUnionTableAddr = 0x2000000000;
31*7c3d14c8STreehugger Robot   static const uptr kAppAddr = 0xF000008000;
32*7c3d14c8STreehugger Robot   static const uptr kShadowMask = ~0xF000000000;
33*7c3d14c8STreehugger Robot };
34*7c3d14c8STreehugger Robot #elif defined(__aarch64__)
35*7c3d14c8STreehugger Robot struct Mapping39 {
36*7c3d14c8STreehugger Robot   static const uptr kShadowAddr = 0x10000;
37*7c3d14c8STreehugger Robot   static const uptr kUnionTableAddr = 0x1000000000;
38*7c3d14c8STreehugger Robot   static const uptr kAppAddr = 0x7000008000;
39*7c3d14c8STreehugger Robot   static const uptr kShadowMask = ~0x7800000000;
40*7c3d14c8STreehugger Robot };
41*7c3d14c8STreehugger Robot 
42*7c3d14c8STreehugger Robot struct Mapping42 {
43*7c3d14c8STreehugger Robot   static const uptr kShadowAddr = 0x10000;
44*7c3d14c8STreehugger Robot   static const uptr kUnionTableAddr = 0x8000000000;
45*7c3d14c8STreehugger Robot   static const uptr kAppAddr = 0x3ff00008000;
46*7c3d14c8STreehugger Robot   static const uptr kShadowMask = ~0x3c000000000;
47*7c3d14c8STreehugger Robot };
48*7c3d14c8STreehugger Robot 
49*7c3d14c8STreehugger Robot extern int vmaSize;
50*7c3d14c8STreehugger Robot # define DFSAN_RUNTIME_VMA 1
51*7c3d14c8STreehugger Robot #else
52*7c3d14c8STreehugger Robot # error "DFSan not supported for this platform!"
53*7c3d14c8STreehugger Robot #endif
54*7c3d14c8STreehugger Robot 
55*7c3d14c8STreehugger Robot enum MappingType {
56*7c3d14c8STreehugger Robot   MAPPING_SHADOW_ADDR,
57*7c3d14c8STreehugger Robot   MAPPING_UNION_TABLE_ADDR,
58*7c3d14c8STreehugger Robot   MAPPING_APP_ADDR,
59*7c3d14c8STreehugger Robot   MAPPING_SHADOW_MASK
60*7c3d14c8STreehugger Robot };
61*7c3d14c8STreehugger Robot 
62*7c3d14c8STreehugger Robot template<typename Mapping, int Type>
MappingImpl(void)63*7c3d14c8STreehugger Robot uptr MappingImpl(void) {
64*7c3d14c8STreehugger Robot   switch (Type) {
65*7c3d14c8STreehugger Robot     case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr;
66*7c3d14c8STreehugger Robot     case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr;
67*7c3d14c8STreehugger Robot     case MAPPING_APP_ADDR: return Mapping::kAppAddr;
68*7c3d14c8STreehugger Robot     case MAPPING_SHADOW_MASK: return Mapping::kShadowMask;
69*7c3d14c8STreehugger Robot   }
70*7c3d14c8STreehugger Robot }
71*7c3d14c8STreehugger Robot 
72*7c3d14c8STreehugger Robot template<int Type>
MappingArchImpl(void)73*7c3d14c8STreehugger Robot uptr MappingArchImpl(void) {
74*7c3d14c8STreehugger Robot #ifdef __aarch64__
75*7c3d14c8STreehugger Robot   if (vmaSize == 39)
76*7c3d14c8STreehugger Robot     return MappingImpl<Mapping39, Type>();
77*7c3d14c8STreehugger Robot   else
78*7c3d14c8STreehugger Robot     return MappingImpl<Mapping42, Type>();
79*7c3d14c8STreehugger Robot   DCHECK(0);
80*7c3d14c8STreehugger Robot #else
81*7c3d14c8STreehugger Robot   return MappingImpl<Mapping, Type>();
82*7c3d14c8STreehugger Robot #endif
83*7c3d14c8STreehugger Robot }
84*7c3d14c8STreehugger Robot 
85*7c3d14c8STreehugger Robot ALWAYS_INLINE
ShadowAddr()86*7c3d14c8STreehugger Robot uptr ShadowAddr() {
87*7c3d14c8STreehugger Robot   return MappingArchImpl<MAPPING_SHADOW_ADDR>();
88*7c3d14c8STreehugger Robot }
89*7c3d14c8STreehugger Robot 
90*7c3d14c8STreehugger Robot ALWAYS_INLINE
UnionTableAddr()91*7c3d14c8STreehugger Robot uptr UnionTableAddr() {
92*7c3d14c8STreehugger Robot   return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>();
93*7c3d14c8STreehugger Robot }
94*7c3d14c8STreehugger Robot 
95*7c3d14c8STreehugger Robot ALWAYS_INLINE
AppAddr()96*7c3d14c8STreehugger Robot uptr AppAddr() {
97*7c3d14c8STreehugger Robot   return MappingArchImpl<MAPPING_APP_ADDR>();
98*7c3d14c8STreehugger Robot }
99*7c3d14c8STreehugger Robot 
100*7c3d14c8STreehugger Robot ALWAYS_INLINE
ShadowMask()101*7c3d14c8STreehugger Robot uptr ShadowMask() {
102*7c3d14c8STreehugger Robot   return MappingArchImpl<MAPPING_SHADOW_MASK>();
103*7c3d14c8STreehugger Robot }
104*7c3d14c8STreehugger Robot 
105*7c3d14c8STreehugger Robot }  // namespace __dfsan
106*7c3d14c8STreehugger Robot 
107*7c3d14c8STreehugger Robot #endif
108