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