Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 1 | //===-- asan_report.cc ----------------------------------------------------===// |
| 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 | // This file contains error reporting code. |
| 13 | //===----------------------------------------------------------------------===// |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 14 | #include "asan_flags.h" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 15 | #include "asan_internal.h" |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 16 | #include "asan_mapping.h" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 17 | #include "asan_report.h" |
| 18 | #include "asan_stack.h" |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 19 | #include "asan_thread.h" |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 20 | #include "sanitizer_common/sanitizer_common.h" |
Sergey Matveev | ed20ebe | 2013-05-06 11:27:58 +0000 | [diff] [blame] | 21 | #include "sanitizer_common/sanitizer_flags.h" |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 22 | #include "sanitizer_common/sanitizer_report_decorator.h" |
Alexey Samsonov | 9c92748 | 2012-12-26 14:44:46 +0000 | [diff] [blame] | 23 | #include "sanitizer_common/sanitizer_symbolizer.h" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 24 | |
| 25 | namespace __asan { |
| 26 | |
Alexey Samsonov | f657a19 | 2012-08-13 11:23:40 +0000 | [diff] [blame] | 27 | // -------------------- User-specified callbacks ----------------- {{{1 |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 28 | static void (*error_report_callback)(const char*); |
| 29 | static char *error_message_buffer = 0; |
| 30 | static uptr error_message_buffer_pos = 0; |
| 31 | static uptr error_message_buffer_size = 0; |
| 32 | |
| 33 | void AppendToErrorMessageBuffer(const char *buffer) { |
| 34 | if (error_message_buffer) { |
| 35 | uptr length = internal_strlen(buffer); |
| 36 | CHECK_GE(error_message_buffer_size, error_message_buffer_pos); |
| 37 | uptr remaining = error_message_buffer_size - error_message_buffer_pos; |
| 38 | internal_strncpy(error_message_buffer + error_message_buffer_pos, |
| 39 | buffer, remaining); |
| 40 | error_message_buffer[error_message_buffer_size - 1] = '\0'; |
| 41 | // FIXME: reallocate the buffer instead of truncating the message. |
| 42 | error_message_buffer_pos += remaining > length ? length : remaining; |
| 43 | } |
| 44 | } |
| 45 | |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 46 | // ---------------------- Decorator ------------------------------ {{{1 |
| 47 | class Decorator: private __sanitizer::AnsiColorDecorator { |
| 48 | public: |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 49 | Decorator() : __sanitizer::AnsiColorDecorator(PrintsToTtyCached()) { } |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 50 | const char *Warning() { return Red(); } |
| 51 | const char *EndWarning() { return Default(); } |
| 52 | const char *Access() { return Blue(); } |
| 53 | const char *EndAccess() { return Default(); } |
| 54 | const char *Location() { return Green(); } |
| 55 | const char *EndLocation() { return Default(); } |
| 56 | const char *Allocation() { return Magenta(); } |
| 57 | const char *EndAllocation() { return Default(); } |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 58 | |
| 59 | const char *ShadowByte(u8 byte) { |
| 60 | switch (byte) { |
| 61 | case kAsanHeapLeftRedzoneMagic: |
| 62 | case kAsanHeapRightRedzoneMagic: |
| 63 | return Red(); |
| 64 | case kAsanHeapFreeMagic: |
| 65 | return Magenta(); |
| 66 | case kAsanStackLeftRedzoneMagic: |
| 67 | case kAsanStackMidRedzoneMagic: |
| 68 | case kAsanStackRightRedzoneMagic: |
| 69 | case kAsanStackPartialRedzoneMagic: |
| 70 | return Red(); |
| 71 | case kAsanStackAfterReturnMagic: |
| 72 | return Magenta(); |
| 73 | case kAsanInitializationOrderMagic: |
| 74 | return Cyan(); |
| 75 | case kAsanUserPoisonedMemoryMagic: |
| 76 | return Blue(); |
| 77 | case kAsanStackUseAfterScopeMagic: |
| 78 | return Magenta(); |
| 79 | case kAsanGlobalRedzoneMagic: |
| 80 | return Red(); |
| 81 | case kAsanInternalHeapMagic: |
| 82 | return Yellow(); |
| 83 | default: |
| 84 | return Default(); |
| 85 | } |
| 86 | } |
| 87 | const char *EndShadowByte() { return Default(); } |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 90 | // ---------------------- Helper functions ----------------------- {{{1 |
| 91 | |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 92 | static void PrintShadowByte(const char *before, u8 byte, |
| 93 | const char *after = "\n") { |
| 94 | Decorator d; |
| 95 | Printf("%s%s%x%x%s%s", before, |
| 96 | d.ShadowByte(byte), byte >> 4, byte & 15, d.EndShadowByte(), after); |
| 97 | } |
| 98 | |
| 99 | static void PrintShadowBytes(const char *before, u8 *bytes, |
| 100 | u8 *guilty, uptr n) { |
| 101 | Decorator d; |
| 102 | if (before) |
| 103 | Printf("%s%p:", before, bytes); |
| 104 | for (uptr i = 0; i < n; i++) { |
| 105 | u8 *p = bytes + i; |
| 106 | const char *before = p == guilty ? "[" : |
Kostya Serebryany | 696902a | 2013-09-03 09:44:56 +0000 | [diff] [blame] | 107 | (p - 1 == guilty && i != 0) ? "" : " "; |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 108 | const char *after = p == guilty ? "]" : ""; |
| 109 | PrintShadowByte(before, *p, after); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 110 | } |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 111 | Printf("\n"); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Kostya Serebryany | 95f630a | 2013-01-28 07:34:22 +0000 | [diff] [blame] | 114 | static void PrintLegend() { |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 115 | Printf("Shadow byte legend (one shadow byte represents %d " |
| 116 | "application bytes):\n", (int)SHADOW_GRANULARITY); |
| 117 | PrintShadowByte(" Addressable: ", 0); |
| 118 | Printf(" Partially addressable: "); |
Timur Iskhodzhanov | 5e97ba3 | 2013-05-29 14:11:44 +0000 | [diff] [blame] | 119 | for (u8 i = 1; i < SHADOW_GRANULARITY; i++) |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 120 | PrintShadowByte("", i, " "); |
| 121 | Printf("\n"); |
| 122 | PrintShadowByte(" Heap left redzone: ", kAsanHeapLeftRedzoneMagic); |
Alexey Samsonov | f3f2f5c | 2013-04-10 07:00:25 +0000 | [diff] [blame] | 123 | PrintShadowByte(" Heap right redzone: ", kAsanHeapRightRedzoneMagic); |
| 124 | PrintShadowByte(" Freed heap region: ", kAsanHeapFreeMagic); |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 125 | PrintShadowByte(" Stack left redzone: ", kAsanStackLeftRedzoneMagic); |
| 126 | PrintShadowByte(" Stack mid redzone: ", kAsanStackMidRedzoneMagic); |
| 127 | PrintShadowByte(" Stack right redzone: ", kAsanStackRightRedzoneMagic); |
| 128 | PrintShadowByte(" Stack partial redzone: ", kAsanStackPartialRedzoneMagic); |
Kostya Serebryany | 9514a53 | 2012-12-19 09:53:32 +0000 | [diff] [blame] | 129 | PrintShadowByte(" Stack after return: ", kAsanStackAfterReturnMagic); |
| 130 | PrintShadowByte(" Stack use after scope: ", kAsanStackUseAfterScopeMagic); |
| 131 | PrintShadowByte(" Global redzone: ", kAsanGlobalRedzoneMagic); |
| 132 | PrintShadowByte(" Global init order: ", kAsanInitializationOrderMagic); |
| 133 | PrintShadowByte(" Poisoned by user: ", kAsanUserPoisonedMemoryMagic); |
| 134 | PrintShadowByte(" ASan internal: ", kAsanInternalHeapMagic); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Kostya Serebryany | 95f630a | 2013-01-28 07:34:22 +0000 | [diff] [blame] | 137 | static void PrintShadowMemoryForAddress(uptr addr) { |
| 138 | if (!AddrIsInMem(addr)) |
| 139 | return; |
| 140 | uptr shadow_addr = MemToShadow(addr); |
| 141 | const uptr n_bytes_per_row = 16; |
| 142 | uptr aligned_shadow = shadow_addr & ~(n_bytes_per_row - 1); |
| 143 | Printf("Shadow bytes around the buggy address:\n"); |
| 144 | for (int i = -5; i <= 5; i++) { |
| 145 | const char *prefix = (i == 0) ? "=>" : " "; |
| 146 | PrintShadowBytes(prefix, |
| 147 | (u8*)(aligned_shadow + i * n_bytes_per_row), |
| 148 | (u8*)shadow_addr, n_bytes_per_row); |
| 149 | } |
| 150 | if (flags()->print_legend) |
| 151 | PrintLegend(); |
| 152 | } |
| 153 | |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 154 | static void PrintZoneForPointer(uptr ptr, uptr zone_ptr, |
| 155 | const char *zone_name) { |
| 156 | if (zone_ptr) { |
| 157 | if (zone_name) { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 158 | Printf("malloc_zone_from_ptr(%p) = %p, which is %s\n", |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 159 | ptr, zone_ptr, zone_name); |
| 160 | } else { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 161 | Printf("malloc_zone_from_ptr(%p) = %p, which doesn't have a name\n", |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 162 | ptr, zone_ptr); |
| 163 | } |
| 164 | } else { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 165 | Printf("malloc_zone_from_ptr(%p) = 0\n", ptr); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 169 | static void DescribeThread(AsanThread *t) { |
| 170 | if (t) |
| 171 | DescribeThread(t->context()); |
| 172 | } |
| 173 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 174 | // ---------------------- Address Descriptions ------------------- {{{1 |
| 175 | |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 176 | static bool IsASCII(unsigned char c) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 177 | return /*0x00 <= c &&*/ c <= 0x7F; |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Alexey Samsonov | c942427 | 2013-03-27 10:41:22 +0000 | [diff] [blame] | 180 | static const char *MaybeDemangleGlobalName(const char *name) { |
| 181 | // We can spoil names of globals with C linkage, so use an heuristic |
| 182 | // approach to check if the name should be demangled. |
Alexey Samsonov | 22e21b0 | 2013-09-16 15:45:06 +0000 | [diff] [blame] | 183 | return (name[0] == '_' && name[1] == 'Z' && &getSymbolizer) |
| 184 | ? getSymbolizer()->Demangle(name) |
| 185 | : name; |
Alexey Samsonov | c942427 | 2013-03-27 10:41:22 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Alexey Samsonov | 939316c | 2013-04-01 08:57:38 +0000 | [diff] [blame] | 188 | // Check if the global is a zero-terminated ASCII string. If so, print it. |
| 189 | static void PrintGlobalNameIfASCII(const __asan_global &g) { |
| 190 | for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { |
| 191 | unsigned char c = *(unsigned char*)p; |
| 192 | if (c == '\0' || !IsASCII(c)) return; |
| 193 | } |
| 194 | if (*(char*)(g.beg + g.size - 1) != '\0') return; |
| 195 | Printf(" '%s' is ascii string '%s'\n", |
| 196 | MaybeDemangleGlobalName(g.name), (char*)g.beg); |
| 197 | } |
| 198 | |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 199 | bool DescribeAddressRelativeToGlobal(uptr addr, uptr size, |
| 200 | const __asan_global &g) { |
Kostya Serebryany | a3b0e5e | 2013-01-23 11:14:21 +0000 | [diff] [blame] | 201 | static const uptr kMinimalDistanceFromAnotherGlobal = 64; |
| 202 | if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false; |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 203 | if (addr >= g.beg + g.size_with_redzone) return false; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 204 | Decorator d; |
| 205 | Printf("%s", d.Location()); |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 206 | if (addr < g.beg) { |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 207 | Printf("%p is located %zd bytes to the left", (void*)addr, g.beg - addr); |
| 208 | } else if (addr + size > g.beg + g.size) { |
| 209 | if (addr < g.beg + g.size) |
| 210 | addr = g.beg + g.size; |
| 211 | Printf("%p is located %zd bytes to the right", (void*)addr, |
| 212 | addr - (g.beg + g.size)); |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 213 | } else { |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 214 | // Can it happen? |
| 215 | Printf("%p is located %zd bytes inside", (void*)addr, addr - g.beg); |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 216 | } |
Kostya Serebryany | 60c9f44 | 2013-03-18 08:04:55 +0000 | [diff] [blame] | 217 | Printf(" of global variable '%s' from '%s' (0x%zx) of size %zu\n", |
Alexey Samsonov | c942427 | 2013-03-27 10:41:22 +0000 | [diff] [blame] | 218 | MaybeDemangleGlobalName(g.name), g.module_name, g.beg, g.size); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 219 | Printf("%s", d.EndLocation()); |
Alexey Samsonov | e4bfca2 | 2012-08-09 09:27:24 +0000 | [diff] [blame] | 220 | PrintGlobalNameIfASCII(g); |
| 221 | return true; |
| 222 | } |
| 223 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 224 | bool DescribeAddressIfShadow(uptr addr) { |
| 225 | if (AddrIsInMem(addr)) |
| 226 | return false; |
| 227 | static const char kAddrInShadowReport[] = |
| 228 | "Address %p is located in the %s.\n"; |
| 229 | if (AddrIsInShadowGap(addr)) { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 230 | Printf(kAddrInShadowReport, addr, "shadow gap area"); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 231 | return true; |
| 232 | } |
| 233 | if (AddrIsInHighShadow(addr)) { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 234 | Printf(kAddrInShadowReport, addr, "high shadow area"); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 235 | return true; |
| 236 | } |
| 237 | if (AddrIsInLowShadow(addr)) { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 238 | Printf(kAddrInShadowReport, addr, "low shadow area"); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | CHECK(0 && "Address is not in memory and not in shadow?"); |
| 242 | return false; |
| 243 | } |
| 244 | |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 245 | // Return " (thread_name) " or an empty string if the name is empty. |
| 246 | const char *ThreadNameWithParenthesis(AsanThreadContext *t, char buff[], |
| 247 | uptr buff_len) { |
| 248 | const char *name = t->name; |
| 249 | if (name[0] == '\0') return ""; |
| 250 | buff[0] = 0; |
| 251 | internal_strncat(buff, " (", 3); |
| 252 | internal_strncat(buff, name, buff_len - 4); |
| 253 | internal_strncat(buff, ")", 2); |
| 254 | return buff; |
| 255 | } |
| 256 | |
| 257 | const char *ThreadNameWithParenthesis(u32 tid, char buff[], |
| 258 | uptr buff_len) { |
| 259 | if (tid == kInvalidTid) return ""; |
| 260 | asanThreadRegistry().CheckLocked(); |
| 261 | AsanThreadContext *t = GetThreadContextByTidLocked(tid); |
| 262 | return ThreadNameWithParenthesis(t, buff, buff_len); |
| 263 | } |
| 264 | |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 265 | void PrintAccessAndVarIntersection(const char *var_name, |
| 266 | uptr var_beg, uptr var_size, |
| 267 | uptr addr, uptr access_size, |
| 268 | uptr prev_var_end, uptr next_var_beg) { |
| 269 | uptr var_end = var_beg + var_size; |
| 270 | uptr addr_end = addr + access_size; |
| 271 | const char *pos_descr = 0; |
| 272 | // If the variable [var_beg, var_end) is the nearest variable to the |
| 273 | // current memory access, indicate it in the log. |
| 274 | if (addr >= var_beg) { |
| 275 | if (addr_end <= var_end) |
| 276 | pos_descr = "is inside"; // May happen if this is a use-after-return. |
| 277 | else if (addr < var_end) |
| 278 | pos_descr = "partially overflows"; |
| 279 | else if (addr_end <= next_var_beg && |
| 280 | next_var_beg - addr_end >= addr - var_end) |
| 281 | pos_descr = "overflows"; |
| 282 | } else { |
| 283 | if (addr_end > var_beg) |
| 284 | pos_descr = "partially underflows"; |
| 285 | else if (addr >= prev_var_end && |
| 286 | addr - prev_var_end >= var_beg - addr_end) |
| 287 | pos_descr = "underflows"; |
| 288 | } |
| 289 | Printf(" [%zd, %zd) '%s'", var_beg, var_beg + var_size, var_name); |
| 290 | if (pos_descr) { |
| 291 | Decorator d; |
| 292 | // FIXME: we may want to also print the size of the access here, |
| 293 | // but in case of accesses generated by memset it may be confusing. |
| 294 | Printf("%s <== Memory access at offset %zd %s this variable%s\n", |
| 295 | d.Location(), addr, pos_descr, d.EndLocation()); |
| 296 | } else { |
| 297 | Printf("\n"); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | struct StackVarDescr { |
| 302 | uptr beg; |
| 303 | uptr size; |
| 304 | const char *name_pos; |
Kostya Serebryany | 89fe564 | 2013-09-03 14:53:02 +0000 | [diff] [blame] | 305 | uptr name_len; |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 306 | }; |
| 307 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 308 | bool DescribeAddressIfStack(uptr addr, uptr access_size) { |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 309 | AsanThread *t = FindThreadByStackAddress(addr); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 310 | if (!t) return false; |
Kostya Serebryany | 89fe564 | 2013-09-03 14:53:02 +0000 | [diff] [blame] | 311 | const uptr kBufSize = 4095; |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 312 | char buf[kBufSize]; |
| 313 | uptr offset = 0; |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 314 | uptr frame_pc = 0; |
| 315 | char tname[128]; |
| 316 | const char *frame_descr = t->GetFrameNameByAddr(addr, &offset, &frame_pc); |
Kostya Serebryany | d570bb4 | 2013-05-22 14:21:34 +0000 | [diff] [blame] | 317 | |
| 318 | #ifdef __powerpc64__ |
| 319 | // On PowerPC64, the address of a function actually points to a |
| 320 | // three-doubleword data structure with the first field containing |
| 321 | // the address of the function's code. |
| 322 | frame_pc = *reinterpret_cast<uptr *>(frame_pc); |
| 323 | #endif |
| 324 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 325 | // This string is created by the compiler and has the following form: |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 326 | // "n alloc_1 alloc_2 ... alloc_n" |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 327 | // where alloc_i looks like "offset size len ObjectName ". |
| 328 | CHECK(frame_descr); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 329 | Decorator d; |
| 330 | Printf("%s", d.Location()); |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 331 | Printf("Address %p is located in stack of thread T%d%s " |
| 332 | "at offset %zu in frame\n", |
| 333 | addr, t->tid(), |
| 334 | ThreadNameWithParenthesis(t->tid(), tname, sizeof(tname)), |
| 335 | offset); |
| 336 | // Now we print the frame where the alloca has happened. |
| 337 | // We print this frame as a stack trace with one element. |
| 338 | // The symbolizer may print more than one frame if inlining was involved. |
| 339 | // The frame numbers may be different than those in the stack trace printed |
| 340 | // previously. That's unfortunate, but I have no better solution, |
| 341 | // especially given that the alloca may be from entirely different place |
| 342 | // (e.g. use-after-scope, or different thread's stack). |
| 343 | StackTrace alloca_stack; |
| 344 | alloca_stack.trace[0] = frame_pc + 16; |
| 345 | alloca_stack.size = 1; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 346 | Printf("%s", d.EndLocation()); |
Kostya Serebryany | 50f3daa | 2013-03-22 10:36:24 +0000 | [diff] [blame] | 347 | PrintStack(&alloca_stack); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 348 | // Report the number of stack objects. |
| 349 | char *p; |
Timur Iskhodzhanov | 22917e9 | 2013-09-03 15:09:21 +0000 | [diff] [blame] | 350 | uptr n_objects = (uptr)internal_simple_strtoll(frame_descr, &p, 10); |
Kostya Serebryany | a27bdf7 | 2013-04-05 14:40:25 +0000 | [diff] [blame] | 351 | CHECK_GT(n_objects, 0); |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 352 | Printf(" This frame has %zu object(s):\n", n_objects); |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 353 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 354 | // Report all objects in this frame. |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 355 | InternalScopedBuffer<StackVarDescr> vars(n_objects); |
Kostya Serebryany | 89fe564 | 2013-09-03 14:53:02 +0000 | [diff] [blame] | 356 | for (uptr i = 0; i < n_objects; i++) { |
| 357 | uptr beg, size; |
| 358 | uptr len; |
| 359 | beg = (uptr)internal_simple_strtoll(p, &p, 10); |
| 360 | size = (uptr)internal_simple_strtoll(p, &p, 10); |
| 361 | len = (uptr)internal_simple_strtoll(p, &p, 10); |
| 362 | if (beg == 0 || size == 0 || *p != ' ') { |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 363 | Printf("AddressSanitizer can't parse the stack frame " |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 364 | "descriptor: |%s|\n", frame_descr); |
| 365 | break; |
| 366 | } |
| 367 | p++; |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 368 | vars[i].beg = beg; |
| 369 | vars[i].size = size; |
| 370 | vars[i].name_pos = p; |
| 371 | vars[i].name_len = len; |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 372 | p += len; |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 373 | } |
Kostya Serebryany | 89fe564 | 2013-09-03 14:53:02 +0000 | [diff] [blame] | 374 | for (uptr i = 0; i < n_objects; i++) { |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 375 | buf[0] = 0; |
| 376 | internal_strncat(buf, vars[i].name_pos, |
| 377 | static_cast<uptr>(Min(kBufSize, vars[i].name_len))); |
| 378 | uptr prev_var_end = i ? vars[i - 1].beg + vars[i - 1].size : 0; |
Timur Iskhodzhanov | 22917e9 | 2013-09-03 15:09:21 +0000 | [diff] [blame] | 379 | uptr next_var_beg = i + 1 < n_objects ? vars[i + 1].beg : ~(0UL); |
Kostya Serebryany | edb39c7 | 2013-09-03 13:58:04 +0000 | [diff] [blame] | 380 | PrintAccessAndVarIntersection(buf, vars[i].beg, vars[i].size, |
| 381 | offset, access_size, |
| 382 | prev_var_end, next_var_beg); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 383 | } |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 384 | Printf("HINT: this may be a false positive if your program uses " |
Alexey Samsonov | 0870028 | 2012-11-23 09:46:34 +0000 | [diff] [blame] | 385 | "some custom stack unwind mechanism or swapcontext\n" |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 386 | " (longjmp and C++ exceptions *are* supported)\n"); |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 387 | DescribeThread(t); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 388 | return true; |
| 389 | } |
| 390 | |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 391 | static void DescribeAccessToHeapChunk(AsanChunkView chunk, uptr addr, |
| 392 | uptr access_size) { |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 393 | sptr offset; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 394 | Decorator d; |
| 395 | Printf("%s", d.Location()); |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 396 | if (chunk.AddrIsAtLeft(addr, access_size, &offset)) { |
| 397 | Printf("%p is located %zd bytes to the left of", (void*)addr, offset); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 398 | } else if (chunk.AddrIsAtRight(addr, access_size, &offset)) { |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 399 | if (offset < 0) { |
| 400 | addr -= offset; |
| 401 | offset = 0; |
| 402 | } |
| 403 | Printf("%p is located %zd bytes to the right of", (void*)addr, offset); |
| 404 | } else if (chunk.AddrIsInside(addr, access_size, &offset)) { |
| 405 | Printf("%p is located %zd bytes inside of", (void*)addr, offset); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 406 | } else { |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 407 | Printf("%p is located somewhere around (this is AddressSanitizer bug!)", |
| 408 | (void*)addr); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 409 | } |
| 410 | Printf(" %zu-byte region [%p,%p)\n", chunk.UsedSize(), |
| 411 | (void*)(chunk.Beg()), (void*)(chunk.End())); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 412 | Printf("%s", d.EndLocation()); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void DescribeHeapAddress(uptr addr, uptr access_size) { |
| 416 | AsanChunkView chunk = FindHeapChunkByAddress(addr); |
| 417 | if (!chunk.IsValid()) return; |
| 418 | DescribeAccessToHeapChunk(chunk, addr, access_size); |
| 419 | CHECK(chunk.AllocTid() != kInvalidTid); |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 420 | asanThreadRegistry().CheckLocked(); |
| 421 | AsanThreadContext *alloc_thread = |
| 422 | GetThreadContextByTidLocked(chunk.AllocTid()); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 423 | StackTrace alloc_stack; |
| 424 | chunk.GetAllocStack(&alloc_stack); |
Kostya Serebryany | 716e2f2 | 2012-12-07 15:15:01 +0000 | [diff] [blame] | 425 | char tname[128]; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 426 | Decorator d; |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 427 | AsanThreadContext *free_thread = 0; |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 428 | if (chunk.FreeTid() != kInvalidTid) { |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 429 | free_thread = GetThreadContextByTidLocked(chunk.FreeTid()); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 430 | Printf("%sfreed by thread T%d%s here:%s\n", d.Allocation(), |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 431 | free_thread->tid, |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 432 | ThreadNameWithParenthesis(free_thread, tname, sizeof(tname)), |
| 433 | d.EndAllocation()); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 434 | StackTrace free_stack; |
| 435 | chunk.GetFreeStack(&free_stack); |
| 436 | PrintStack(&free_stack); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 437 | Printf("%spreviously allocated by thread T%d%s here:%s\n", |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 438 | d.Allocation(), alloc_thread->tid, |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 439 | ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)), |
| 440 | d.EndAllocation()); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 441 | } else { |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 442 | Printf("%sallocated by thread T%d%s here:%s\n", d.Allocation(), |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 443 | alloc_thread->tid, |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 444 | ThreadNameWithParenthesis(alloc_thread, tname, sizeof(tname)), |
| 445 | d.EndAllocation()); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 446 | } |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 447 | PrintStack(&alloc_stack); |
| 448 | DescribeThread(GetCurrentThread()); |
| 449 | if (free_thread) |
| 450 | DescribeThread(free_thread); |
| 451 | DescribeThread(alloc_thread); |
Alexey Samsonov | 5c153fa | 2012-09-18 07:38:10 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 454 | void DescribeAddress(uptr addr, uptr access_size) { |
| 455 | // Check if this is shadow or shadow gap. |
| 456 | if (DescribeAddressIfShadow(addr)) |
| 457 | return; |
| 458 | CHECK(AddrIsInMem(addr)); |
Evgeniy Stepanov | 589dcda | 2013-02-05 14:32:03 +0000 | [diff] [blame] | 459 | if (DescribeAddressIfGlobal(addr, access_size)) |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 460 | return; |
| 461 | if (DescribeAddressIfStack(addr, access_size)) |
| 462 | return; |
| 463 | // Assume it is a heap address. |
| 464 | DescribeHeapAddress(addr, access_size); |
| 465 | } |
| 466 | |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 467 | // ------------------- Thread description -------------------- {{{1 |
| 468 | |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 469 | void DescribeThread(AsanThreadContext *context) { |
| 470 | CHECK(context); |
| 471 | asanThreadRegistry().CheckLocked(); |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 472 | // No need to announce the main thread. |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 473 | if (context->tid == 0 || context->announced) { |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 474 | return; |
| 475 | } |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 476 | context->announced = true; |
Kostya Serebryany | 716e2f2 | 2012-12-07 15:15:01 +0000 | [diff] [blame] | 477 | char tname[128]; |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 478 | Printf("Thread T%d%s", context->tid, |
| 479 | ThreadNameWithParenthesis(context->tid, tname, sizeof(tname))); |
Kostya Serebryany | 716e2f2 | 2012-12-07 15:15:01 +0000 | [diff] [blame] | 480 | Printf(" created by T%d%s here:\n", |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 481 | context->parent_tid, |
| 482 | ThreadNameWithParenthesis(context->parent_tid, |
Kostya Serebryany | 716e2f2 | 2012-12-07 15:15:01 +0000 | [diff] [blame] | 483 | tname, sizeof(tname))); |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 484 | PrintStack(&context->stack); |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 485 | // Recursively described parent thread if needed. |
| 486 | if (flags()->print_full_thread_history) { |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 487 | AsanThreadContext *parent_context = |
| 488 | GetThreadContextByTidLocked(context->parent_tid); |
| 489 | DescribeThread(parent_context); |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 493 | // -------------------- Different kinds of reports ----------------- {{{1 |
| 494 | |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 495 | // Use ScopedInErrorReport to run common actions just before and |
| 496 | // immediately after printing error report. |
| 497 | class ScopedInErrorReport { |
| 498 | public: |
| 499 | ScopedInErrorReport() { |
| 500 | static atomic_uint32_t num_calls; |
Alexey Samsonov | 62e2709 | 2012-09-17 08:02:19 +0000 | [diff] [blame] | 501 | static u32 reporting_thread_tid; |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 502 | if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) { |
| 503 | // Do not print more than one report, otherwise they will mix up. |
| 504 | // Error reporting functions shouldn't return at this situation, as |
| 505 | // they are defined as no-return. |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 506 | Report("AddressSanitizer: while reporting a bug found another one." |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 507 | "Ignoring.\n"); |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 508 | u32 current_tid = GetCurrentTidOrInvalid(); |
Alexey Samsonov | 62e2709 | 2012-09-17 08:02:19 +0000 | [diff] [blame] | 509 | if (current_tid != reporting_thread_tid) { |
| 510 | // ASan found two bugs in different threads simultaneously. Sleep |
| 511 | // long enough to make sure that the thread which started to print |
| 512 | // an error report will finish doing it. |
| 513 | SleepForSeconds(Max(100, flags()->sleep_before_dying + 1)); |
| 514 | } |
Alexey Samsonov | f882247 | 2013-02-20 13:54:32 +0000 | [diff] [blame] | 515 | // If we're still not dead for some reason, use raw _exit() instead of |
Alexey Samsonov | 031633b | 2012-11-19 11:22:22 +0000 | [diff] [blame] | 516 | // Die() to bypass any additional checks. |
Alexey Samsonov | f882247 | 2013-02-20 13:54:32 +0000 | [diff] [blame] | 517 | internal__exit(flags()->exitcode); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 518 | } |
Alexey Samsonov | 6a08d29 | 2012-12-07 22:01:28 +0000 | [diff] [blame] | 519 | ASAN_ON_ERROR(); |
Alexey Samsonov | 7ed46ff | 2013-04-05 07:30:29 +0000 | [diff] [blame] | 520 | // Make sure the registry and sanitizer report mutexes are locked while |
| 521 | // we're printing an error report. |
| 522 | // We can lock them only here to avoid self-deadlock in case of |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 523 | // recursive reports. |
| 524 | asanThreadRegistry().Lock(); |
Alexey Samsonov | 7ed46ff | 2013-04-05 07:30:29 +0000 | [diff] [blame] | 525 | CommonSanitizerReportMutex.Lock(); |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 526 | reporting_thread_tid = GetCurrentTidOrInvalid(); |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 527 | Printf("====================================================" |
Alexey Samsonov | 62e2709 | 2012-09-17 08:02:19 +0000 | [diff] [blame] | 528 | "=============\n"); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 529 | } |
| 530 | // Destructor is NORETURN, as functions that report errors are. |
| 531 | NORETURN ~ScopedInErrorReport() { |
| 532 | // Make sure the current thread is announced. |
Timur Iskhodzhanov | 997454a | 2013-09-10 08:36:21 +0000 | [diff] [blame] | 533 | DescribeThread(GetCurrentThread()); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 534 | // Print memory stats. |
Kostya Serebryany | 95f630a | 2013-01-28 07:34:22 +0000 | [diff] [blame] | 535 | if (flags()->print_stats) |
| 536 | __asan_print_accumulated_stats(); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 537 | if (error_report_callback) { |
| 538 | error_report_callback(error_message_buffer); |
| 539 | } |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 540 | Report("ABORTING\n"); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 541 | Die(); |
| 542 | } |
| 543 | }; |
| 544 | |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 545 | static void ReportSummary(const char *error_type, StackTrace *stack) { |
| 546 | if (!stack->size) return; |
Alexey Samsonov | 22e21b0 | 2013-09-16 15:45:06 +0000 | [diff] [blame] | 547 | if (&getSymbolizer && getSymbolizer()->IsAvailable()) { |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 548 | AddressInfo ai; |
| 549 | // Currently, we include the first stack frame into the report summary. |
| 550 | // Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc). |
Alexey Samsonov | 22c1c18 | 2013-04-11 11:45:04 +0000 | [diff] [blame] | 551 | uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]); |
Alexey Samsonov | 7847d77 | 2013-09-10 14:36:16 +0000 | [diff] [blame] | 552 | getSymbolizer()->SymbolizeCode(pc, &ai, 1); |
Alexey Samsonov | 90b0f1e | 2013-10-04 08:55:03 +0000 | [diff] [blame] | 553 | ReportErrorSummary(error_type, ai.file, ai.line, ai.function); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 554 | } |
| 555 | // FIXME: do we need to print anything at all if there is no symbolizer? |
| 556 | } |
| 557 | |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 558 | void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 559 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 560 | Decorator d; |
| 561 | Printf("%s", d.Warning()); |
Kostya Serebryany | 69d8ede | 2012-10-15 13:04:58 +0000 | [diff] [blame] | 562 | Report("ERROR: AddressSanitizer: SEGV on unknown address %p" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 563 | " (pc %p sp %p bp %p T%d)\n", |
| 564 | (void*)addr, (void*)pc, (void*)sp, (void*)bp, |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 565 | GetCurrentTidOrInvalid()); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 566 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 567 | Printf("AddressSanitizer can not provide additional info.\n"); |
Kostya Serebryany | a30c8f9 | 2012-12-13 09:34:23 +0000 | [diff] [blame] | 568 | GET_STACK_TRACE_FATAL(pc, bp); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 569 | PrintStack(&stack); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 570 | ReportSummary("SEGV", &stack); |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 573 | void ReportDoubleFree(uptr addr, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 574 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 575 | Decorator d; |
| 576 | Printf("%s", d.Warning()); |
Kostya Serebryany | a89a35a | 2013-03-26 08:01:37 +0000 | [diff] [blame] | 577 | char tname[128]; |
| 578 | u32 curr_tid = GetCurrentTidOrInvalid(); |
| 579 | Report("ERROR: AddressSanitizer: attempting double-free on %p in " |
| 580 | "thread T%d%s:\n", |
| 581 | addr, curr_tid, |
| 582 | ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname))); |
| 583 | |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 584 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 585 | PrintStack(stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 586 | DescribeHeapAddress(addr, 1); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 587 | ReportSummary("double-free", stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 590 | void ReportFreeNotMalloced(uptr addr, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 591 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 592 | Decorator d; |
| 593 | Printf("%s", d.Warning()); |
Kostya Serebryany | a89a35a | 2013-03-26 08:01:37 +0000 | [diff] [blame] | 594 | char tname[128]; |
| 595 | u32 curr_tid = GetCurrentTidOrInvalid(); |
Kostya Serebryany | 69d8ede | 2012-10-15 13:04:58 +0000 | [diff] [blame] | 596 | Report("ERROR: AddressSanitizer: attempting free on address " |
Kostya Serebryany | a89a35a | 2013-03-26 08:01:37 +0000 | [diff] [blame] | 597 | "which was not malloc()-ed: %p in thread T%d%s\n", addr, |
| 598 | curr_tid, ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname))); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 599 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 600 | PrintStack(stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 601 | DescribeHeapAddress(addr, 1); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 602 | ReportSummary("bad-free", stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Kostya Serebryany | fe6d916 | 2012-12-21 08:53:59 +0000 | [diff] [blame] | 605 | void ReportAllocTypeMismatch(uptr addr, StackTrace *stack, |
| 606 | AllocType alloc_type, |
| 607 | AllocType dealloc_type) { |
| 608 | static const char *alloc_names[] = |
| 609 | {"INVALID", "malloc", "operator new", "operator new []"}; |
| 610 | static const char *dealloc_names[] = |
| 611 | {"INVALID", "free", "operator delete", "operator delete []"}; |
| 612 | CHECK_NE(alloc_type, dealloc_type); |
| 613 | ScopedInErrorReport in_report; |
| 614 | Decorator d; |
| 615 | Printf("%s", d.Warning()); |
| 616 | Report("ERROR: AddressSanitizer: alloc-dealloc-mismatch (%s vs %s) on %p\n", |
| 617 | alloc_names[alloc_type], dealloc_names[dealloc_type], addr); |
| 618 | Printf("%s", d.EndWarning()); |
| 619 | PrintStack(stack); |
| 620 | DescribeHeapAddress(addr, 1); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 621 | ReportSummary("alloc-dealloc-mismatch", stack); |
Kostya Serebryany | fe6d916 | 2012-12-21 08:53:59 +0000 | [diff] [blame] | 622 | Report("HINT: if you don't care about these warnings you may set " |
| 623 | "ASAN_OPTIONS=alloc_dealloc_mismatch=0\n"); |
| 624 | } |
| 625 | |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 626 | void ReportMallocUsableSizeNotOwned(uptr addr, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 627 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 628 | Decorator d; |
| 629 | Printf("%s", d.Warning()); |
Kostya Serebryany | 69d8ede | 2012-10-15 13:04:58 +0000 | [diff] [blame] | 630 | Report("ERROR: AddressSanitizer: attempting to call " |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 631 | "malloc_usable_size() for pointer which is " |
| 632 | "not owned: %p\n", addr); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 633 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 634 | PrintStack(stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 635 | DescribeHeapAddress(addr, 1); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 636 | ReportSummary("bad-malloc_usable_size", stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 639 | void ReportAsanGetAllocatedSizeNotOwned(uptr addr, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 640 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 641 | Decorator d; |
| 642 | Printf("%s", d.Warning()); |
Kostya Serebryany | 69d8ede | 2012-10-15 13:04:58 +0000 | [diff] [blame] | 643 | Report("ERROR: AddressSanitizer: attempting to call " |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 644 | "__asan_get_allocated_size() for pointer which is " |
| 645 | "not owned: %p\n", addr); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 646 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 647 | PrintStack(stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 648 | DescribeHeapAddress(addr, 1); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 649 | ReportSummary("bad-__asan_get_allocated_size", stack); |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Alexey Samsonov | 487fee7 | 2012-08-09 08:32:33 +0000 | [diff] [blame] | 652 | void ReportStringFunctionMemoryRangesOverlap( |
| 653 | const char *function, const char *offset1, uptr length1, |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 654 | const char *offset2, uptr length2, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 655 | ScopedInErrorReport in_report; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 656 | Decorator d; |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 657 | char bug_type[100]; |
| 658 | internal_snprintf(bug_type, sizeof(bug_type), "%s-param-overlap", function); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 659 | Printf("%s", d.Warning()); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 660 | Report("ERROR: AddressSanitizer: %s: " |
Alexey Samsonov | 487fee7 | 2012-08-09 08:32:33 +0000 | [diff] [blame] | 661 | "memory ranges [%p,%p) and [%p, %p) overlap\n", \ |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 662 | bug_type, offset1, offset1 + length1, offset2, offset2 + length2); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 663 | Printf("%s", d.EndWarning()); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 664 | PrintStack(stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 665 | DescribeAddress((uptr)offset1, length1); |
| 666 | DescribeAddress((uptr)offset2, length2); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 667 | ReportSummary(bug_type, stack); |
Alexey Samsonov | 487fee7 | 2012-08-09 08:32:33 +0000 | [diff] [blame] | 668 | } |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 669 | |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 670 | // ----------------------- Mac-specific reports ----------------- {{{1 |
| 671 | |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 672 | void WarnMacFreeUnallocated( |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 673 | uptr addr, uptr zone_ptr, const char *zone_name, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 674 | // Just print a warning here. |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 675 | Printf("free_common(%p) -- attempting to free unallocated memory.\n" |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 676 | "AddressSanitizer is ignoring this error on Mac OS now.\n", |
| 677 | addr); |
| 678 | PrintZoneForPointer(addr, zone_ptr, zone_name); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 679 | PrintStack(stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 680 | DescribeHeapAddress(addr, 1); |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void ReportMacMzReallocUnknown( |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 684 | uptr addr, uptr zone_ptr, const char *zone_name, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 685 | ScopedInErrorReport in_report; |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 686 | Printf("mz_realloc(%p) -- attempting to realloc unallocated memory.\n" |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 687 | "This is an unrecoverable problem, exiting now.\n", |
| 688 | addr); |
| 689 | PrintZoneForPointer(addr, zone_ptr, zone_name); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 690 | PrintStack(stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 691 | DescribeHeapAddress(addr, 1); |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | void ReportMacCfReallocUnknown( |
Kostya Serebryany | c3390df | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 695 | uptr addr, uptr zone_ptr, const char *zone_name, StackTrace *stack) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 696 | ScopedInErrorReport in_report; |
Kostya Serebryany | 283c296 | 2012-08-28 11:34:40 +0000 | [diff] [blame] | 697 | Printf("cf_realloc(%p) -- attempting to realloc unallocated memory.\n" |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 698 | "This is an unrecoverable problem, exiting now.\n", |
| 699 | addr); |
| 700 | PrintZoneForPointer(addr, zone_ptr, zone_name); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 701 | PrintStack(stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 702 | DescribeHeapAddress(addr, 1); |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Alexey Samsonov | 812ff90 | 2012-08-09 11:29:13 +0000 | [diff] [blame] | 705 | } // namespace __asan |
| 706 | |
| 707 | // --------------------------- Interface --------------------- {{{1 |
| 708 | using namespace __asan; // NOLINT |
| 709 | |
| 710 | void __asan_report_error(uptr pc, uptr bp, uptr sp, |
| 711 | uptr addr, bool is_write, uptr access_size) { |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 712 | ScopedInErrorReport in_report; |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 713 | |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 714 | // Determine the error type. |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 715 | const char *bug_descr = "unknown-crash"; |
| 716 | if (AddrIsInMem(addr)) { |
| 717 | u8 *shadow_addr = (u8*)MemToShadow(addr); |
| 718 | // If we are accessing 16 bytes, look at the second shadow byte. |
| 719 | if (*shadow_addr == 0 && access_size > SHADOW_GRANULARITY) |
| 720 | shadow_addr++; |
| 721 | // If we are in the partial right redzone, look at the next shadow byte. |
| 722 | if (*shadow_addr > 0 && *shadow_addr < 128) |
| 723 | shadow_addr++; |
| 724 | switch (*shadow_addr) { |
| 725 | case kAsanHeapLeftRedzoneMagic: |
| 726 | case kAsanHeapRightRedzoneMagic: |
| 727 | bug_descr = "heap-buffer-overflow"; |
| 728 | break; |
| 729 | case kAsanHeapFreeMagic: |
| 730 | bug_descr = "heap-use-after-free"; |
| 731 | break; |
| 732 | case kAsanStackLeftRedzoneMagic: |
| 733 | bug_descr = "stack-buffer-underflow"; |
| 734 | break; |
Kostya Serebryany | 3945c58 | 2012-08-21 14:10:25 +0000 | [diff] [blame] | 735 | case kAsanInitializationOrderMagic: |
| 736 | bug_descr = "initialization-order-fiasco"; |
| 737 | break; |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 738 | case kAsanStackMidRedzoneMagic: |
| 739 | case kAsanStackRightRedzoneMagic: |
| 740 | case kAsanStackPartialRedzoneMagic: |
| 741 | bug_descr = "stack-buffer-overflow"; |
| 742 | break; |
| 743 | case kAsanStackAfterReturnMagic: |
| 744 | bug_descr = "stack-use-after-return"; |
| 745 | break; |
| 746 | case kAsanUserPoisonedMemoryMagic: |
| 747 | bug_descr = "use-after-poison"; |
| 748 | break; |
Alexey Samsonov | d4b5db8 | 2012-12-04 01:38:15 +0000 | [diff] [blame] | 749 | case kAsanStackUseAfterScopeMagic: |
| 750 | bug_descr = "stack-use-after-scope"; |
| 751 | break; |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 752 | case kAsanGlobalRedzoneMagic: |
| 753 | bug_descr = "global-buffer-overflow"; |
| 754 | break; |
| 755 | } |
| 756 | } |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 757 | Decorator d; |
| 758 | Printf("%s", d.Warning()); |
Kostya Serebryany | 69d8ede | 2012-10-15 13:04:58 +0000 | [diff] [blame] | 759 | Report("ERROR: AddressSanitizer: %s on address " |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 760 | "%p at pc 0x%zx bp 0x%zx sp 0x%zx\n", |
| 761 | bug_descr, (void*)addr, pc, bp, sp); |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 762 | Printf("%s", d.EndWarning()); |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 763 | |
Alexey Samsonov | 89c1384 | 2013-03-20 09:23:28 +0000 | [diff] [blame] | 764 | u32 curr_tid = GetCurrentTidOrInvalid(); |
Kostya Serebryany | 716e2f2 | 2012-12-07 15:15:01 +0000 | [diff] [blame] | 765 | char tname[128]; |
Kostya Serebryany | 58f5455 | 2012-12-18 07:32:16 +0000 | [diff] [blame] | 766 | Printf("%s%s of size %zu at %p thread T%d%s%s\n", |
| 767 | d.Access(), |
| 768 | access_size ? (is_write ? "WRITE" : "READ") : "ACCESS", |
| 769 | access_size, (void*)addr, curr_tid, |
| 770 | ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname)), |
| 771 | d.EndAccess()); |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 772 | |
Kostya Serebryany | a30c8f9 | 2012-12-13 09:34:23 +0000 | [diff] [blame] | 773 | GET_STACK_TRACE_FATAL(pc, bp); |
Kostya Serebryany | cc34722 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 774 | PrintStack(&stack); |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 775 | |
| 776 | DescribeAddress(addr, access_size); |
Kostya Serebryany | 2673fd8 | 2013-02-06 12:36:49 +0000 | [diff] [blame] | 777 | ReportSummary(bug_descr, &stack); |
Alexey Samsonov | 9873792 | 2012-08-10 15:13:05 +0000 | [diff] [blame] | 778 | PrintShadowMemoryForAddress(addr); |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Alexey Samsonov | c98570b | 2012-08-09 10:56:57 +0000 | [diff] [blame] | 781 | void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) { |
| 782 | error_report_callback = callback; |
| 783 | if (callback) { |
| 784 | error_message_buffer_size = 1 << 16; |
| 785 | error_message_buffer = |
| 786 | (char*)MmapOrDie(error_message_buffer_size, __FUNCTION__); |
| 787 | error_message_buffer_pos = 0; |
| 788 | } |
| 789 | } |
Alexey Samsonov | f657a19 | 2012-08-13 11:23:40 +0000 | [diff] [blame] | 790 | |
Kostya Serebryany | 17a7c67 | 2012-12-29 10:18:31 +0000 | [diff] [blame] | 791 | void __asan_describe_address(uptr addr) { |
| 792 | DescribeAddress(addr, 1); |
| 793 | } |
| 794 | |
Alexey Samsonov | 6a08d29 | 2012-12-07 22:01:28 +0000 | [diff] [blame] | 795 | #if !SANITIZER_SUPPORTS_WEAK_HOOKS |
Alexey Samsonov | 8663343 | 2012-10-02 14:06:39 +0000 | [diff] [blame] | 796 | // Provide default implementation of __asan_on_error that does nothing |
| 797 | // and may be overriden by user. |
Timur Iskhodzhanov | 3c80c6c | 2013-08-13 11:42:45 +0000 | [diff] [blame] | 798 | SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE |
Alexey Samsonov | 8663343 | 2012-10-02 14:06:39 +0000 | [diff] [blame] | 799 | void __asan_on_error() {} |
Alexey Samsonov | 6a08d29 | 2012-12-07 22:01:28 +0000 | [diff] [blame] | 800 | #endif |