asan_report.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. //===-- asan_report.cpp ---------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of AddressSanitizer, an address sanity checker.
  10. //
  11. // This file contains error reporting code.
  12. //===----------------------------------------------------------------------===//
  13. #include "asan_errors.h"
  14. #include "asan_flags.h"
  15. #include "asan_descriptions.h"
  16. #include "asan_internal.h"
  17. #include "asan_mapping.h"
  18. #include "asan_report.h"
  19. #include "asan_scariness_score.h"
  20. #include "asan_stack.h"
  21. #include "asan_thread.h"
  22. #include "sanitizer_common/sanitizer_common.h"
  23. #include "sanitizer_common/sanitizer_flags.h"
  24. #include "sanitizer_common/sanitizer_report_decorator.h"
  25. #include "sanitizer_common/sanitizer_stackdepot.h"
  26. #include "sanitizer_common/sanitizer_symbolizer.h"
  27. namespace __asan {
  28. // -------------------- User-specified callbacks ----------------- {{{1
  29. static void (*error_report_callback)(const char*);
  30. static char *error_message_buffer = nullptr;
  31. static uptr error_message_buffer_pos = 0;
  32. static Mutex error_message_buf_mutex;
  33. static const unsigned kAsanBuggyPcPoolSize = 25;
  34. static __sanitizer::atomic_uintptr_t AsanBuggyPcPool[kAsanBuggyPcPoolSize];
  35. void AppendToErrorMessageBuffer(const char *buffer) {
  36. Lock l(&error_message_buf_mutex);
  37. if (!error_message_buffer) {
  38. error_message_buffer =
  39. (char*)MmapOrDieQuietly(kErrorMessageBufferSize, __func__);
  40. error_message_buffer_pos = 0;
  41. }
  42. uptr length = internal_strlen(buffer);
  43. RAW_CHECK(kErrorMessageBufferSize >= error_message_buffer_pos);
  44. uptr remaining = kErrorMessageBufferSize - error_message_buffer_pos;
  45. internal_strncpy(error_message_buffer + error_message_buffer_pos,
  46. buffer, remaining);
  47. error_message_buffer[kErrorMessageBufferSize - 1] = '\0';
  48. // FIXME: reallocate the buffer instead of truncating the message.
  49. error_message_buffer_pos += Min(remaining, length);
  50. }
  51. // ---------------------- Helper functions ----------------------- {{{1
  52. void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
  53. bool in_shadow, const char *after) {
  54. Decorator d;
  55. str->append("%s%s%x%x%s%s", before,
  56. in_shadow ? d.ShadowByte(byte) : d.MemoryByte(), byte >> 4,
  57. byte & 15, d.Default(), after);
  58. }
  59. static void PrintZoneForPointer(uptr ptr, uptr zone_ptr,
  60. const char *zone_name) {
  61. if (zone_ptr) {
  62. if (zone_name) {
  63. Printf("malloc_zone_from_ptr(%p) = %p, which is %s\n", (void *)ptr,
  64. (void *)zone_ptr, zone_name);
  65. } else {
  66. Printf("malloc_zone_from_ptr(%p) = %p, which doesn't have a name\n",
  67. (void *)ptr, (void *)zone_ptr);
  68. }
  69. } else {
  70. Printf("malloc_zone_from_ptr(%p) = 0\n", (void *)ptr);
  71. }
  72. }
  73. // ---------------------- Address Descriptions ------------------- {{{1
  74. bool ParseFrameDescription(const char *frame_descr,
  75. InternalMmapVector<StackVarDescr> *vars) {
  76. CHECK(frame_descr);
  77. const char *p;
  78. // This string is created by the compiler and has the following form:
  79. // "n alloc_1 alloc_2 ... alloc_n"
  80. // where alloc_i looks like "offset size len ObjectName"
  81. // or "offset size len ObjectName:line".
  82. uptr n_objects = (uptr)internal_simple_strtoll(frame_descr, &p, 10);
  83. if (n_objects == 0)
  84. return false;
  85. for (uptr i = 0; i < n_objects; i++) {
  86. uptr beg = (uptr)internal_simple_strtoll(p, &p, 10);
  87. uptr size = (uptr)internal_simple_strtoll(p, &p, 10);
  88. uptr len = (uptr)internal_simple_strtoll(p, &p, 10);
  89. if (beg == 0 || size == 0 || *p != ' ') {
  90. return false;
  91. }
  92. p++;
  93. char *colon_pos = internal_strchr(p, ':');
  94. uptr line = 0;
  95. uptr name_len = len;
  96. if (colon_pos != nullptr && colon_pos < p + len) {
  97. name_len = colon_pos - p;
  98. line = (uptr)internal_simple_strtoll(colon_pos + 1, nullptr, 10);
  99. }
  100. StackVarDescr var = {beg, size, p, name_len, line};
  101. vars->push_back(var);
  102. p += len;
  103. }
  104. return true;
  105. }
  106. // -------------------- Different kinds of reports ----------------- {{{1
  107. // Use ScopedInErrorReport to run common actions just before and
  108. // immediately after printing error report.
  109. class ScopedInErrorReport {
  110. public:
  111. explicit ScopedInErrorReport(bool fatal = false)
  112. : halt_on_error_(fatal || flags()->halt_on_error) {
  113. // Make sure the registry and sanitizer report mutexes are locked while
  114. // we're printing an error report.
  115. // We can lock them only here to avoid self-deadlock in case of
  116. // recursive reports.
  117. asanThreadRegistry().Lock();
  118. Printf(
  119. "=================================================================\n");
  120. }
  121. ~ScopedInErrorReport() {
  122. if (halt_on_error_ && !__sanitizer_acquire_crash_state()) {
  123. asanThreadRegistry().Unlock();
  124. return;
  125. }
  126. ASAN_ON_ERROR();
  127. if (current_error_.IsValid()) current_error_.Print();
  128. // Make sure the current thread is announced.
  129. DescribeThread(GetCurrentThread());
  130. // We may want to grab this lock again when printing stats.
  131. asanThreadRegistry().Unlock();
  132. // Print memory stats.
  133. if (flags()->print_stats)
  134. __asan_print_accumulated_stats();
  135. if (common_flags()->print_cmdline)
  136. PrintCmdline();
  137. if (common_flags()->print_module_map == 2)
  138. DumpProcessMap();
  139. // Copy the message buffer so that we could start logging without holding a
  140. // lock that gets acquired during printing.
  141. InternalMmapVector<char> buffer_copy(kErrorMessageBufferSize);
  142. {
  143. Lock l(&error_message_buf_mutex);
  144. internal_memcpy(buffer_copy.data(),
  145. error_message_buffer, kErrorMessageBufferSize);
  146. // Clear error_message_buffer so that if we find other errors
  147. // we don't re-log this error.
  148. error_message_buffer_pos = 0;
  149. }
  150. LogFullErrorReport(buffer_copy.data());
  151. if (error_report_callback) {
  152. error_report_callback(buffer_copy.data());
  153. }
  154. if (halt_on_error_ && common_flags()->abort_on_error) {
  155. // On Android the message is truncated to 512 characters.
  156. // FIXME: implement "compact" error format, possibly without, or with
  157. // highly compressed stack traces?
  158. // FIXME: or just use the summary line as abort message?
  159. SetAbortMessage(buffer_copy.data());
  160. }
  161. // In halt_on_error = false mode, reset the current error object (before
  162. // unlocking).
  163. if (!halt_on_error_)
  164. internal_memset(&current_error_, 0, sizeof(current_error_));
  165. if (halt_on_error_) {
  166. Report("ABORTING\n");
  167. Die();
  168. }
  169. }
  170. void ReportError(const ErrorDescription &description) {
  171. // Can only report one error per ScopedInErrorReport.
  172. CHECK_EQ(current_error_.kind, kErrorKindInvalid);
  173. internal_memcpy(&current_error_, &description, sizeof(current_error_));
  174. }
  175. static ErrorDescription &CurrentError() {
  176. return current_error_;
  177. }
  178. private:
  179. ScopedErrorReportLock error_report_lock_;
  180. // Error currently being reported. This enables the destructor to interact
  181. // with the debugger and point it to an error description.
  182. static ErrorDescription current_error_;
  183. bool halt_on_error_;
  184. };
  185. ErrorDescription ScopedInErrorReport::current_error_(LINKER_INITIALIZED);
  186. void ReportDeadlySignal(const SignalContext &sig) {
  187. ScopedInErrorReport in_report(/*fatal*/ true);
  188. ErrorDeadlySignal error(GetCurrentTidOrInvalid(), sig);
  189. in_report.ReportError(error);
  190. }
  191. void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack) {
  192. ScopedInErrorReport in_report;
  193. ErrorDoubleFree error(GetCurrentTidOrInvalid(), free_stack, addr);
  194. in_report.ReportError(error);
  195. }
  196. void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size,
  197. uptr delete_alignment,
  198. BufferedStackTrace *free_stack) {
  199. ScopedInErrorReport in_report;
  200. ErrorNewDeleteTypeMismatch error(GetCurrentTidOrInvalid(), free_stack, addr,
  201. delete_size, delete_alignment);
  202. in_report.ReportError(error);
  203. }
  204. void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack) {
  205. ScopedInErrorReport in_report;
  206. ErrorFreeNotMalloced error(GetCurrentTidOrInvalid(), free_stack, addr);
  207. in_report.ReportError(error);
  208. }
  209. void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
  210. AllocType alloc_type,
  211. AllocType dealloc_type) {
  212. ScopedInErrorReport in_report;
  213. ErrorAllocTypeMismatch error(GetCurrentTidOrInvalid(), free_stack, addr,
  214. alloc_type, dealloc_type);
  215. in_report.ReportError(error);
  216. }
  217. void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) {
  218. ScopedInErrorReport in_report;
  219. ErrorMallocUsableSizeNotOwned error(GetCurrentTidOrInvalid(), stack, addr);
  220. in_report.ReportError(error);
  221. }
  222. void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
  223. BufferedStackTrace *stack) {
  224. ScopedInErrorReport in_report;
  225. ErrorSanitizerGetAllocatedSizeNotOwned error(GetCurrentTidOrInvalid(), stack,
  226. addr);
  227. in_report.ReportError(error);
  228. }
  229. void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack) {
  230. ScopedInErrorReport in_report(/*fatal*/ true);
  231. ErrorCallocOverflow error(GetCurrentTidOrInvalid(), stack, count, size);
  232. in_report.ReportError(error);
  233. }
  234. void ReportReallocArrayOverflow(uptr count, uptr size,
  235. BufferedStackTrace *stack) {
  236. ScopedInErrorReport in_report(/*fatal*/ true);
  237. ErrorReallocArrayOverflow error(GetCurrentTidOrInvalid(), stack, count, size);
  238. in_report.ReportError(error);
  239. }
  240. void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack) {
  241. ScopedInErrorReport in_report(/*fatal*/ true);
  242. ErrorPvallocOverflow error(GetCurrentTidOrInvalid(), stack, size);
  243. in_report.ReportError(error);
  244. }
  245. void ReportInvalidAllocationAlignment(uptr alignment,
  246. BufferedStackTrace *stack) {
  247. ScopedInErrorReport in_report(/*fatal*/ true);
  248. ErrorInvalidAllocationAlignment error(GetCurrentTidOrInvalid(), stack,
  249. alignment);
  250. in_report.ReportError(error);
  251. }
  252. void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
  253. BufferedStackTrace *stack) {
  254. ScopedInErrorReport in_report(/*fatal*/ true);
  255. ErrorInvalidAlignedAllocAlignment error(GetCurrentTidOrInvalid(), stack,
  256. size, alignment);
  257. in_report.ReportError(error);
  258. }
  259. void ReportInvalidPosixMemalignAlignment(uptr alignment,
  260. BufferedStackTrace *stack) {
  261. ScopedInErrorReport in_report(/*fatal*/ true);
  262. ErrorInvalidPosixMemalignAlignment error(GetCurrentTidOrInvalid(), stack,
  263. alignment);
  264. in_report.ReportError(error);
  265. }
  266. void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
  267. BufferedStackTrace *stack) {
  268. ScopedInErrorReport in_report(/*fatal*/ true);
  269. ErrorAllocationSizeTooBig error(GetCurrentTidOrInvalid(), stack, user_size,
  270. total_size, max_size);
  271. in_report.ReportError(error);
  272. }
  273. void ReportRssLimitExceeded(BufferedStackTrace *stack) {
  274. ScopedInErrorReport in_report(/*fatal*/ true);
  275. ErrorRssLimitExceeded error(GetCurrentTidOrInvalid(), stack);
  276. in_report.ReportError(error);
  277. }
  278. void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack) {
  279. ScopedInErrorReport in_report(/*fatal*/ true);
  280. ErrorOutOfMemory error(GetCurrentTidOrInvalid(), stack, requested_size);
  281. in_report.ReportError(error);
  282. }
  283. void ReportStringFunctionMemoryRangesOverlap(const char *function,
  284. const char *offset1, uptr length1,
  285. const char *offset2, uptr length2,
  286. BufferedStackTrace *stack) {
  287. ScopedInErrorReport in_report;
  288. ErrorStringFunctionMemoryRangesOverlap error(
  289. GetCurrentTidOrInvalid(), stack, (uptr)offset1, length1, (uptr)offset2,
  290. length2, function);
  291. in_report.ReportError(error);
  292. }
  293. void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
  294. BufferedStackTrace *stack) {
  295. ScopedInErrorReport in_report;
  296. ErrorStringFunctionSizeOverflow error(GetCurrentTidOrInvalid(), stack, offset,
  297. size);
  298. in_report.ReportError(error);
  299. }
  300. void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
  301. uptr old_mid, uptr new_mid,
  302. BufferedStackTrace *stack) {
  303. ScopedInErrorReport in_report;
  304. ErrorBadParamsToAnnotateContiguousContainer error(
  305. GetCurrentTidOrInvalid(), stack, beg, end, old_mid, new_mid);
  306. in_report.ReportError(error);
  307. }
  308. void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
  309. const __asan_global *g2, u32 stack_id2) {
  310. ScopedInErrorReport in_report;
  311. ErrorODRViolation error(GetCurrentTidOrInvalid(), g1, stack_id1, g2,
  312. stack_id2);
  313. in_report.ReportError(error);
  314. }
  315. // ----------------------- CheckForInvalidPointerPair ----------- {{{1
  316. static NOINLINE void ReportInvalidPointerPair(uptr pc, uptr bp, uptr sp,
  317. uptr a1, uptr a2) {
  318. ScopedInErrorReport in_report;
  319. ErrorInvalidPointerPair error(GetCurrentTidOrInvalid(), pc, bp, sp, a1, a2);
  320. in_report.ReportError(error);
  321. }
  322. static bool IsInvalidPointerPair(uptr a1, uptr a2) {
  323. if (a1 == a2)
  324. return false;
  325. // 256B in shadow memory can be iterated quite fast
  326. static const uptr kMaxOffset = 2048;
  327. uptr left = a1 < a2 ? a1 : a2;
  328. uptr right = a1 < a2 ? a2 : a1;
  329. uptr offset = right - left;
  330. if (offset <= kMaxOffset)
  331. return __asan_region_is_poisoned(left, offset);
  332. AsanThread *t = GetCurrentThread();
  333. // check whether left is a stack memory pointer
  334. if (uptr shadow_offset1 = t->GetStackVariableShadowStart(left)) {
  335. uptr shadow_offset2 = t->GetStackVariableShadowStart(right);
  336. return shadow_offset2 == 0 || shadow_offset1 != shadow_offset2;
  337. }
  338. // check whether left is a heap memory address
  339. HeapAddressDescription hdesc1, hdesc2;
  340. if (GetHeapAddressInformation(left, 0, &hdesc1) &&
  341. hdesc1.chunk_access.access_type == kAccessTypeInside)
  342. return !GetHeapAddressInformation(right, 0, &hdesc2) ||
  343. hdesc2.chunk_access.access_type != kAccessTypeInside ||
  344. hdesc1.chunk_access.chunk_begin != hdesc2.chunk_access.chunk_begin;
  345. // check whether left is an address of a global variable
  346. GlobalAddressDescription gdesc1, gdesc2;
  347. if (GetGlobalAddressInformation(left, 0, &gdesc1))
  348. return !GetGlobalAddressInformation(right - 1, 0, &gdesc2) ||
  349. !gdesc1.PointsInsideTheSameVariable(gdesc2);
  350. if (t->GetStackVariableShadowStart(right) ||
  351. GetHeapAddressInformation(right, 0, &hdesc2) ||
  352. GetGlobalAddressInformation(right - 1, 0, &gdesc2))
  353. return true;
  354. // At this point we know nothing about both a1 and a2 addresses.
  355. return false;
  356. }
  357. static inline void CheckForInvalidPointerPair(void *p1, void *p2) {
  358. switch (flags()->detect_invalid_pointer_pairs) {
  359. case 0:
  360. return;
  361. case 1:
  362. if (p1 == nullptr || p2 == nullptr)
  363. return;
  364. break;
  365. }
  366. uptr a1 = reinterpret_cast<uptr>(p1);
  367. uptr a2 = reinterpret_cast<uptr>(p2);
  368. if (IsInvalidPointerPair(a1, a2)) {
  369. GET_CALLER_PC_BP_SP;
  370. ReportInvalidPointerPair(pc, bp, sp, a1, a2);
  371. }
  372. }
  373. // ----------------------- Mac-specific reports ----------------- {{{1
  374. void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr, const char *zone_name,
  375. BufferedStackTrace *stack) {
  376. ScopedInErrorReport in_report;
  377. Printf(
  378. "mz_realloc(%p) -- attempting to realloc unallocated memory.\n"
  379. "This is an unrecoverable problem, exiting now.\n",
  380. (void *)addr);
  381. PrintZoneForPointer(addr, zone_ptr, zone_name);
  382. stack->Print();
  383. DescribeAddressIfHeap(addr);
  384. }
  385. // -------------- SuppressErrorReport -------------- {{{1
  386. // Avoid error reports duplicating for ASan recover mode.
  387. static bool SuppressErrorReport(uptr pc) {
  388. if (!common_flags()->suppress_equal_pcs) return false;
  389. for (unsigned i = 0; i < kAsanBuggyPcPoolSize; i++) {
  390. uptr cmp = atomic_load_relaxed(&AsanBuggyPcPool[i]);
  391. if (cmp == 0 && atomic_compare_exchange_strong(&AsanBuggyPcPool[i], &cmp,
  392. pc, memory_order_relaxed))
  393. return false;
  394. if (cmp == pc) return true;
  395. }
  396. Die();
  397. }
  398. void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
  399. uptr access_size, u32 exp, bool fatal) {
  400. if (__asan_test_only_reported_buggy_pointer) {
  401. *__asan_test_only_reported_buggy_pointer = addr;
  402. return;
  403. }
  404. if (!fatal && SuppressErrorReport(pc)) return;
  405. ENABLE_FRAME_POINTER;
  406. // Optimization experiments.
  407. // The experiments can be used to evaluate potential optimizations that remove
  408. // instrumentation (assess false negatives). Instead of completely removing
  409. // some instrumentation, compiler can emit special calls into runtime
  410. // (e.g. __asan_report_exp_load1 instead of __asan_report_load1) and pass
  411. // mask of experiments (exp).
  412. // The reaction to a non-zero value of exp is to be defined.
  413. (void)exp;
  414. ScopedInErrorReport in_report(fatal);
  415. ErrorGeneric error(GetCurrentTidOrInvalid(), pc, bp, sp, addr, is_write,
  416. access_size);
  417. in_report.ReportError(error);
  418. }
  419. } // namespace __asan
  420. // --------------------------- Interface --------------------- {{{1
  421. using namespace __asan;
  422. void __asan_report_error(uptr pc, uptr bp, uptr sp, uptr addr, int is_write,
  423. uptr access_size, u32 exp) {
  424. ENABLE_FRAME_POINTER;
  425. bool fatal = flags()->halt_on_error;
  426. ReportGenericError(pc, bp, sp, addr, is_write, access_size, exp, fatal);
  427. }
  428. void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) {
  429. Lock l(&error_message_buf_mutex);
  430. error_report_callback = callback;
  431. }
  432. void __asan_describe_address(uptr addr) {
  433. // Thread registry must be locked while we're describing an address.
  434. asanThreadRegistry().Lock();
  435. PrintAddressDescription(addr, 1, "");
  436. asanThreadRegistry().Unlock();
  437. }
  438. int __asan_report_present() {
  439. return ScopedInErrorReport::CurrentError().kind != kErrorKindInvalid;
  440. }
  441. uptr __asan_get_report_pc() {
  442. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  443. return ScopedInErrorReport::CurrentError().Generic.pc;
  444. return 0;
  445. }
  446. uptr __asan_get_report_bp() {
  447. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  448. return ScopedInErrorReport::CurrentError().Generic.bp;
  449. return 0;
  450. }
  451. uptr __asan_get_report_sp() {
  452. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  453. return ScopedInErrorReport::CurrentError().Generic.sp;
  454. return 0;
  455. }
  456. uptr __asan_get_report_address() {
  457. ErrorDescription &err = ScopedInErrorReport::CurrentError();
  458. if (err.kind == kErrorKindGeneric)
  459. return err.Generic.addr_description.Address();
  460. else if (err.kind == kErrorKindDoubleFree)
  461. return err.DoubleFree.addr_description.addr;
  462. return 0;
  463. }
  464. int __asan_get_report_access_type() {
  465. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  466. return ScopedInErrorReport::CurrentError().Generic.is_write;
  467. return 0;
  468. }
  469. uptr __asan_get_report_access_size() {
  470. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  471. return ScopedInErrorReport::CurrentError().Generic.access_size;
  472. return 0;
  473. }
  474. const char *__asan_get_report_description() {
  475. if (ScopedInErrorReport::CurrentError().kind == kErrorKindGeneric)
  476. return ScopedInErrorReport::CurrentError().Generic.bug_descr;
  477. return ScopedInErrorReport::CurrentError().Base.scariness.GetDescription();
  478. }
  479. extern "C" {
  480. SANITIZER_INTERFACE_ATTRIBUTE
  481. void __sanitizer_ptr_sub(void *a, void *b) {
  482. CheckForInvalidPointerPair(a, b);
  483. }
  484. SANITIZER_INTERFACE_ATTRIBUTE
  485. void __sanitizer_ptr_cmp(void *a, void *b) {
  486. CheckForInvalidPointerPair(a, b);
  487. }
  488. } // extern "C"
  489. // Provide default implementation of __asan_on_error that does nothing
  490. // and may be overriden by user.
  491. SANITIZER_INTERFACE_WEAK_DEF(void, __asan_on_error, void) {}