Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 | extern int vmaSize; |
| 50 | # define DFSAN_RUNTIME_VMA 1 |
| 51 | #else |
| 52 | # error "DFSan not supported for this platform!" |
| 53 | #endif |
| 54 | |
| 55 | enum MappingType { |
| 56 | MAPPING_SHADOW_ADDR, |
| 57 | MAPPING_UNION_TABLE_ADDR, |
| 58 | MAPPING_APP_ADDR, |
| 59 | MAPPING_SHADOW_MASK |
| 60 | }; |
| 61 | |
| 62 | template<typename Mapping, int Type> |
| 63 | uptr MappingImpl(void) { |
| 64 | switch (Type) { |
| 65 | case MAPPING_SHADOW_ADDR: return Mapping::kShadowAddr; |
| 66 | case MAPPING_UNION_TABLE_ADDR: return Mapping::kUnionTableAddr; |
| 67 | case MAPPING_APP_ADDR: return Mapping::kAppAddr; |
| 68 | case MAPPING_SHADOW_MASK: return Mapping::kShadowMask; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | template<int Type> |
| 73 | uptr MappingArchImpl(void) { |
| 74 | #ifdef __aarch64__ |
| 75 | if (vmaSize == 39) |
| 76 | return MappingImpl<Mapping39, Type>(); |
| 77 | else |
| 78 | return MappingImpl<Mapping42, Type>(); |
| 79 | DCHECK(0); |
| 80 | #else |
| 81 | return MappingImpl<Mapping, Type>(); |
| 82 | #endif |
| 83 | } |
| 84 | |
| 85 | ALWAYS_INLINE |
| 86 | uptr ShadowAddr() { |
| 87 | return MappingArchImpl<MAPPING_SHADOW_ADDR>(); |
| 88 | } |
| 89 | |
| 90 | ALWAYS_INLINE |
| 91 | uptr UnionTableAddr() { |
| 92 | return MappingArchImpl<MAPPING_UNION_TABLE_ADDR>(); |
| 93 | } |
| 94 | |
| 95 | ALWAYS_INLINE |
| 96 | uptr AppAddr() { |
| 97 | return MappingArchImpl<MAPPING_APP_ADDR>(); |
| 98 | } |
| 99 | |
| 100 | ALWAYS_INLINE |
| 101 | uptr ShadowMask() { |
| 102 | return MappingArchImpl<MAPPING_SHADOW_MASK>(); |
| 103 | } |
| 104 | |
| 105 | } // namespace __dfsan |
| 106 | |
| 107 | #endif |