Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 1 | //===-- asan_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 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // Defines ASan memory mapping. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #ifndef ASAN_MAPPING_H |
| 15 | #define ASAN_MAPPING_H |
| 16 | |
| 17 | #include "asan_internal.h" |
| 18 | |
| 19 | // The full explanation of the memory mapping could be found here: |
| 20 | // http://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 21 | // |
| 22 | // Typical shadow mapping on Linux/x86_64 with SHADOW_OFFSET == 0x00007fff8000: |
| 23 | // || `[0x10007fff8000, 0x7fffffffffff]` || HighMem || |
| 24 | // || `[0x02008fff7000, 0x10007fff7fff]` || HighShadow || |
| 25 | // || `[0x00008fff7000, 0x02008fff6fff]` || ShadowGap || |
| 26 | // || `[0x00007fff8000, 0x00008fff6fff]` || LowShadow || |
| 27 | // || `[0x000000000000, 0x00007fff7fff]` || LowMem || |
| 28 | // |
| 29 | // When SHADOW_OFFSET is zero (-pie): |
| 30 | // || `[0x100000000000, 0x7fffffffffff]` || HighMem || |
| 31 | // || `[0x020000000000, 0x0fffffffffff]` || HighShadow || |
| 32 | // || `[0x000000040000, 0x01ffffffffff]` || ShadowGap || |
| 33 | // |
| 34 | // Special case when something is already mapped between |
Kostya Serebryany | 13577fe | 2013-02-28 12:28:37 +0000 | [diff] [blame] | 35 | // 0x003000000000 and 0x005000000000 (e.g. when prelink is installed): |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 36 | // || `[0x10007fff8000, 0x7fffffffffff]` || HighMem || |
| 37 | // || `[0x02008fff7000, 0x10007fff7fff]` || HighShadow || |
Kostya Serebryany | 13577fe | 2013-02-28 12:28:37 +0000 | [diff] [blame] | 38 | // || `[0x005000000000, 0x02008fff6fff]` || ShadowGap3 || |
| 39 | // || `[0x003000000000, 0x004fffffffff]` || MidMem || |
| 40 | // || `[0x000a7fff8000, 0x002fffffffff]` || ShadowGap2 || |
| 41 | // || `[0x00067fff8000, 0x000a7fff7fff]` || MidShadow || |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 42 | // || `[0x00008fff7000, 0x00067fff7fff]` || ShadowGap || |
| 43 | // || `[0x00007fff8000, 0x00008fff6fff]` || LowShadow || |
| 44 | // || `[0x000000000000, 0x00007fff7fff]` || LowMem || |
| 45 | // |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 46 | // Default Linux/i386 mapping on x86_64 machine: |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 47 | // || `[0x40000000, 0xffffffff]` || HighMem || |
| 48 | // || `[0x28000000, 0x3fffffff]` || HighShadow || |
| 49 | // || `[0x24000000, 0x27ffffff]` || ShadowGap || |
| 50 | // || `[0x20000000, 0x23ffffff]` || LowShadow || |
| 51 | // || `[0x00000000, 0x1fffffff]` || LowMem || |
Kostya Serebryany | 40527a5 | 2013-06-03 14:49:25 +0000 | [diff] [blame] | 52 | // |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 53 | // Default Linux/i386 mapping on i386 machine |
| 54 | // (addresses starting with 0xc0000000 are reserved |
| 55 | // for kernel and thus not sanitized): |
| 56 | // || `[0x38000000, 0xbfffffff]` || HighMem || |
| 57 | // || `[0x27000000, 0x37ffffff]` || HighShadow || |
| 58 | // || `[0x24000000, 0x26ffffff]` || ShadowGap || |
| 59 | // || `[0x20000000, 0x23ffffff]` || LowShadow || |
| 60 | // || `[0x00000000, 0x1fffffff]` || LowMem || |
| 61 | // |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 62 | // Default Linux/MIPS32 mapping: |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 63 | // || `[0x2aaa0000, 0xffffffff]` || HighMem || |
| 64 | // || `[0x0fff4000, 0x2aa9ffff]` || HighShadow || |
| 65 | // || `[0x0bff4000, 0x0fff3fff]` || ShadowGap || |
| 66 | // || `[0x0aaa0000, 0x0bff3fff]` || LowShadow || |
| 67 | // || `[0x00000000, 0x0aa9ffff]` || LowMem || |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 68 | // |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 69 | // Default Linux/MIPS64 mapping: |
| 70 | // || `[0x4000000000, 0xffffffffff]` || HighMem || |
| 71 | // || `[0x2800000000, 0x3fffffffff]` || HighShadow || |
| 72 | // || `[0x2400000000, 0x27ffffffff]` || ShadowGap || |
| 73 | // || `[0x2000000000, 0x23ffffffff]` || LowShadow || |
| 74 | // || `[0x0000000000, 0x1fffffffff]` || LowMem || |
| 75 | // |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 76 | // Shadow mapping on FreeBSD/x86-64 with SHADOW_OFFSET == 0x400000000000: |
| 77 | // || `[0x500000000000, 0x7fffffffffff]` || HighMem || |
| 78 | // || `[0x4a0000000000, 0x4fffffffffff]` || HighShadow || |
| 79 | // || `[0x480000000000, 0x49ffffffffff]` || ShadowGap || |
| 80 | // || `[0x400000000000, 0x47ffffffffff]` || LowShadow || |
| 81 | // || `[0x000000000000, 0x3fffffffffff]` || LowMem || |
| 82 | // |
| 83 | // Shadow mapping on FreeBSD/i386 with SHADOW_OFFSET == 0x40000000: |
| 84 | // || `[0x60000000, 0xffffffff]` || HighMem || |
| 85 | // || `[0x4c000000, 0x5fffffff]` || HighShadow || |
| 86 | // || `[0x48000000, 0x4bffffff]` || ShadowGap || |
| 87 | // || `[0x40000000, 0x47ffffff]` || LowShadow || |
| 88 | // || `[0x00000000, 0x3fffffff]` || LowMem || |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 89 | // |
| 90 | // Default Windows/i386 mapping: |
| 91 | // (the exact location of HighShadow/HighMem may vary depending |
| 92 | // on WoW64, /LARGEADDRESSAWARE, etc). |
| 93 | // || `[0x50000000, 0xffffffff]` || HighMem || |
| 94 | // || `[0x3a000000, 0x4fffffff]` || HighShadow || |
| 95 | // || `[0x36000000, 0x39ffffff]` || ShadowGap || |
| 96 | // || `[0x30000000, 0x35ffffff]` || LowShadow || |
| 97 | // || `[0x00000000, 0x2fffffff]` || LowMem || |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 98 | |
Alexey Samsonov | 22e21b0 | 2013-09-16 15:45:06 +0000 | [diff] [blame] | 99 | static const u64 kDefaultShadowScale = 3; |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 100 | static const u64 kDefaultShadowOffset32 = 1ULL << 29; // 0x20000000 |
| 101 | static const u64 kIosShadowOffset32 = 1ULL << 30; // 0x40000000 |
Alexey Samsonov | 22e21b0 | 2013-09-16 15:45:06 +0000 | [diff] [blame] | 102 | static const u64 kDefaultShadowOffset64 = 1ULL << 44; |
| 103 | static const u64 kDefaultShort64bitShadowOffset = 0x7FFF8000; // < 2G. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 104 | static const u64 kAArch64_ShadowOffset64 = 1ULL << 36; |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 105 | static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 106 | static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37; |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 107 | static const u64 kPPC64_ShadowOffset64 = 1ULL << 41; |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 108 | static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000 |
| 109 | static const u64 kFreeBSD_ShadowOffset64 = 1ULL << 46; // 0x400000000000 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 110 | static const u64 kWindowsShadowOffset32 = 3ULL << 28; // 0x30000000 |
Alexey Samsonov | 22e21b0 | 2013-09-16 15:45:06 +0000 | [diff] [blame] | 111 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 112 | #define SHADOW_SCALE kDefaultShadowScale |
| 113 | #if SANITIZER_ANDROID |
| 114 | # define SHADOW_OFFSET (0) |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 115 | #else |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 116 | # if SANITIZER_WORDSIZE == 32 |
| 117 | # if defined(__mips__) |
| 118 | # define SHADOW_OFFSET kMIPS32_ShadowOffset32 |
| 119 | # elif SANITIZER_FREEBSD |
| 120 | # define SHADOW_OFFSET kFreeBSD_ShadowOffset32 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 121 | # elif SANITIZER_IOS |
| 122 | # define SHADOW_OFFSET kIosShadowOffset32 |
| 123 | # elif SANITIZER_WINDOWS |
| 124 | # define SHADOW_OFFSET kWindowsShadowOffset32 |
Evgeniy Stepanov | f1ee2cd | 2012-05-23 11:52:37 +0000 | [diff] [blame] | 125 | # else |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 126 | # define SHADOW_OFFSET kDefaultShadowOffset32 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 127 | # endif |
| 128 | # else |
| 129 | # if defined(__aarch64__) |
| 130 | # define SHADOW_OFFSET kAArch64_ShadowOffset64 |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 131 | # elif defined(__powerpc64__) |
| 132 | # define SHADOW_OFFSET kPPC64_ShadowOffset64 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 133 | # elif SANITIZER_FREEBSD |
| 134 | # define SHADOW_OFFSET kFreeBSD_ShadowOffset64 |
| 135 | # elif SANITIZER_MAC |
| 136 | # define SHADOW_OFFSET kDefaultShadowOffset64 |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 137 | # elif defined(__mips64) |
| 138 | # define SHADOW_OFFSET kMIPS64_ShadowOffset64 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 139 | # else |
| 140 | # define SHADOW_OFFSET kDefaultShort64bitShadowOffset |
Evgeniy Stepanov | f1ee2cd | 2012-05-23 11:52:37 +0000 | [diff] [blame] | 141 | # endif |
| 142 | # endif |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 143 | #endif |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 144 | |
| 145 | #define SHADOW_GRANULARITY (1ULL << SHADOW_SCALE) |
Kostya Serebryany | e5ab968 | 2013-01-23 13:27:43 +0000 | [diff] [blame] | 146 | #define MEM_TO_SHADOW(mem) (((mem) >> SHADOW_SCALE) + (SHADOW_OFFSET)) |
Evgeniy Stepanov | 3972ea0 | 2012-05-12 12:33:10 +0000 | [diff] [blame] | 147 | #define SHADOW_TO_MEM(shadow) (((shadow) - SHADOW_OFFSET) << SHADOW_SCALE) |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 148 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 149 | #define kLowMemBeg 0 |
| 150 | #define kLowMemEnd (SHADOW_OFFSET ? SHADOW_OFFSET - 1 : 0) |
| 151 | |
| 152 | #define kLowShadowBeg SHADOW_OFFSET |
| 153 | #define kLowShadowEnd MEM_TO_SHADOW(kLowMemEnd) |
| 154 | |
| 155 | #define kHighMemBeg (MEM_TO_SHADOW(kHighMemEnd) + 1) |
| 156 | |
| 157 | #define kHighShadowBeg MEM_TO_SHADOW(kHighMemBeg) |
| 158 | #define kHighShadowEnd MEM_TO_SHADOW(kHighMemEnd) |
| 159 | |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 160 | # define kMidShadowBeg MEM_TO_SHADOW(kMidMemBeg) |
| 161 | # define kMidShadowEnd MEM_TO_SHADOW(kMidMemEnd) |
| 162 | |
Kostya Serebryany | e89f184 | 2012-11-24 05:03:11 +0000 | [diff] [blame] | 163 | // With the zero shadow base we can not actually map pages starting from 0. |
| 164 | // This constant is somewhat arbitrary. |
| 165 | #define kZeroBaseShadowStart (1 << 18) |
| 166 | |
| 167 | #define kShadowGapBeg (kLowShadowEnd ? kLowShadowEnd + 1 \ |
| 168 | : kZeroBaseShadowStart) |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 169 | #define kShadowGapEnd ((kMidMemBeg ? kMidShadowBeg : kHighShadowBeg) - 1) |
| 170 | |
| 171 | #define kShadowGap2Beg (kMidMemBeg ? kMidShadowEnd + 1 : 0) |
| 172 | #define kShadowGap2End (kMidMemBeg ? kMidMemBeg - 1 : 0) |
| 173 | |
| 174 | #define kShadowGap3Beg (kMidMemBeg ? kMidMemEnd + 1 : 0) |
| 175 | #define kShadowGap3End (kMidMemBeg ? kHighShadowBeg - 1 : 0) |
| 176 | |
| 177 | #define DO_ASAN_MAPPING_PROFILE 0 // Set to 1 to profile the functions below. |
| 178 | |
| 179 | #if DO_ASAN_MAPPING_PROFILE |
| 180 | # define PROFILE_ASAN_MAPPING() AsanMappingProfile[__LINE__]++; |
| 181 | #else |
| 182 | # define PROFILE_ASAN_MAPPING() |
| 183 | #endif |
| 184 | |
| 185 | // If 1, all shadow boundaries are constants. |
| 186 | // Don't set to 1 other than for testing. |
| 187 | #define ASAN_FIXED_MAPPING 0 |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 188 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 189 | namespace __asan { |
| 190 | |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 191 | extern uptr AsanMappingProfile[]; |
| 192 | |
| 193 | #if ASAN_FIXED_MAPPING |
| 194 | // Fixed mapping for 64-bit Linux. Mostly used for performance comparison |
| 195 | // with non-fixed mapping. As of r175253 (Feb 2013) the performance |
| 196 | // difference between fixed and non-fixed mapping is below the noise level. |
| 197 | static uptr kHighMemEnd = 0x7fffffffffffULL; |
| 198 | static uptr kMidMemBeg = 0x3000000000ULL; |
Kostya Serebryany | 13577fe | 2013-02-28 12:28:37 +0000 | [diff] [blame] | 199 | static uptr kMidMemEnd = 0x4fffffffffULL; |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 200 | #else |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 201 | extern uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; // Initialized in __asan_init. |
| 202 | #endif |
Kostya Serebryany | e5ab968 | 2013-01-23 13:27:43 +0000 | [diff] [blame] | 203 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 204 | static inline bool AddrIsInLowMem(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 205 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 206 | return a < kLowMemEnd; |
| 207 | } |
| 208 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 209 | static inline bool AddrIsInLowShadow(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 210 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 211 | return a >= kLowShadowBeg && a <= kLowShadowEnd; |
| 212 | } |
| 213 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 214 | static inline bool AddrIsInHighMem(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 215 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 216 | return a >= kHighMemBeg && a <= kHighMemEnd; |
| 217 | } |
| 218 | |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 219 | static inline bool AddrIsInMidMem(uptr a) { |
| 220 | PROFILE_ASAN_MAPPING(); |
| 221 | return kMidMemBeg && a >= kMidMemBeg && a <= kMidMemEnd; |
| 222 | } |
| 223 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 224 | static inline bool AddrIsInMem(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 225 | PROFILE_ASAN_MAPPING(); |
| 226 | return AddrIsInLowMem(a) || AddrIsInMidMem(a) || AddrIsInHighMem(a); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 229 | static inline uptr MemToShadow(uptr p) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 230 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 231 | CHECK(AddrIsInMem(p)); |
| 232 | return MEM_TO_SHADOW(p); |
| 233 | } |
| 234 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 235 | static inline bool AddrIsInHighShadow(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 236 | PROFILE_ASAN_MAPPING(); |
| 237 | return a >= kHighShadowBeg && a <= kHighMemEnd; |
| 238 | } |
| 239 | |
| 240 | static inline bool AddrIsInMidShadow(uptr a) { |
| 241 | PROFILE_ASAN_MAPPING(); |
| 242 | return kMidMemBeg && a >= kMidShadowBeg && a <= kMidMemEnd; |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 245 | static inline bool AddrIsInShadow(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 246 | PROFILE_ASAN_MAPPING(); |
| 247 | return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a); |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Alexander Potapenko | 79d12e8 | 2012-07-23 08:22:27 +0000 | [diff] [blame] | 250 | static inline bool AddrIsInShadowGap(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 251 | PROFILE_ASAN_MAPPING(); |
| 252 | if (kMidMemBeg) { |
| 253 | if (a <= kShadowGapEnd) |
| 254 | return SHADOW_OFFSET == 0 || a >= kShadowGapBeg; |
| 255 | return (a >= kShadowGap2Beg && a <= kShadowGap2End) || |
| 256 | (a >= kShadowGap3Beg && a <= kShadowGap3End); |
| 257 | } |
Alexey Samsonov | ee485d4 | 2013-01-21 10:51:18 +0000 | [diff] [blame] | 258 | // In zero-based shadow mode we treat addresses near zero as addresses |
| 259 | // in shadow gap as well. |
Alexey Samsonov | 87b52b9 | 2013-01-21 11:36:38 +0000 | [diff] [blame] | 260 | if (SHADOW_OFFSET == 0) |
Alexey Samsonov | ee485d4 | 2013-01-21 10:51:18 +0000 | [diff] [blame] | 261 | return a <= kShadowGapEnd; |
Alexander Potapenko | 79d12e8 | 2012-07-23 08:22:27 +0000 | [diff] [blame] | 262 | return a >= kShadowGapBeg && a <= kShadowGapEnd; |
| 263 | } |
| 264 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 265 | static inline bool AddrIsAlignedByGranularity(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 266 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 218a9b7 | 2011-11-30 18:50:23 +0000 | [diff] [blame] | 267 | return (a & (SHADOW_GRANULARITY - 1)) == 0; |
| 268 | } |
| 269 | |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 270 | static inline bool AddressIsPoisoned(uptr a) { |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 271 | PROFILE_ASAN_MAPPING(); |
Kostya Serebryany | 3f4c387 | 2012-05-31 14:35:53 +0000 | [diff] [blame] | 272 | const uptr kAccessSize = 1; |
Kostya Serebryany | a84805f | 2013-02-21 07:07:39 +0000 | [diff] [blame] | 273 | u8 *shadow_address = (u8*)MEM_TO_SHADOW(a); |
Kostya Serebryany | ee39255 | 2012-05-31 15:02:07 +0000 | [diff] [blame] | 274 | s8 shadow_value = *shadow_address; |
Kostya Serebryany | 8599762 | 2012-03-15 01:18:06 +0000 | [diff] [blame] | 275 | if (shadow_value) { |
Kostya Serebryany | ee39255 | 2012-05-31 15:02:07 +0000 | [diff] [blame] | 276 | u8 last_accessed_byte = (a & (SHADOW_GRANULARITY - 1)) |
Kostya Serebryany | 8599762 | 2012-03-15 01:18:06 +0000 | [diff] [blame] | 277 | + kAccessSize - 1; |
| 278 | return (last_accessed_byte >= shadow_value); |
| 279 | } |
| 280 | return false; |
| 281 | } |
| 282 | |
Kostya Serebryany | e31eca9 | 2013-02-15 12:00:24 +0000 | [diff] [blame] | 283 | // Must be after all calls to PROFILE_ASAN_MAPPING(). |
| 284 | static const uptr kAsanMappingProfileSize = __LINE__; |
| 285 | |
Kostya Serebryany | 1e172b4 | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 286 | } // namespace __asan |
| 287 | |
| 288 | #endif // ASAN_MAPPING_H |