Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 1 | //===-- asan_report.h -------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 11 | // |
| 12 | // ASan-private header for error reporting functions. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Kostya Serebryany | fe6d916 | 2012-12-21 08:53:59 +0000 | [diff] [blame] | 15 | #include "asan_allocator.h" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 16 | #include "asan_internal.h" |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 17 | #include "asan_thread.h" |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 18 | |
| 19 | namespace __asan { |
| 20 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 21 | struct StackVarDescr { |
| 22 | uptr beg; |
| 23 | uptr size; |
| 24 | const char *name_pos; |
| 25 | uptr name_len; |
| 26 | }; |
| 27 | |
| 28 | struct AddressDescription { |
| 29 | char *name; |
| 30 | uptr name_size; |
| 31 | uptr region_address; |
| 32 | uptr region_size; |
| 33 | const char *region_kind; |
| 34 | }; |
| 35 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 36 | // Returns the number of globals close to the provided address and copies |
| 37 | // them to "globals" array. |
| 38 | int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites, |
| 39 | int max_globals); |
| 40 | bool GetInfoForAddressIfGlobal(uptr addr, AddressDescription *descr); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 41 | // The following functions prints address description depending |
| 42 | // on the memory type (shadow/heap/stack/global). |
| 43 | void DescribeHeapAddress(uptr addr, uptr access_size); |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 44 | bool DescribeAddressIfShadow(uptr addr, AddressDescription *descr = nullptr, |
| 45 | bool print = true); |
| 46 | bool ParseFrameDescription(const char *frame_descr, |
| 47 | InternalMmapVector<StackVarDescr> *vars); |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 48 | bool DescribeAddressIfStack(uptr addr, uptr access_size); |
Alexey Samsonov | def1be9 | 2013-03-21 11:23:41 +0000 | [diff] [blame] | 49 | void DescribeThread(AsanThreadContext *context); |
Alexey Samsonov | 71b42c9 | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 50 | |
Alexey Samsonov | e218beb | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 51 | // Different kinds of error reports. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 52 | void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write, |
| 53 | uptr access_size, u32 exp, bool fatal); |
| 54 | void ReportStackOverflow(const SignalContext &sig); |
| 55 | void ReportDeadlySignal(const char *description, const SignalContext &sig); |
| 56 | void ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size, |
| 57 | BufferedStackTrace *free_stack); |
| 58 | void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack); |
| 59 | void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack); |
| 60 | void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack, |
| 61 | AllocType alloc_type, |
| 62 | AllocType dealloc_type); |
| 63 | void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack); |
| 64 | void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr, |
| 65 | BufferedStackTrace *stack); |
| 66 | void ReportStringFunctionMemoryRangesOverlap(const char *function, |
| 67 | const char *offset1, uptr length1, |
| 68 | const char *offset2, uptr length2, |
| 69 | BufferedStackTrace *stack); |
| 70 | void ReportStringFunctionSizeOverflow(uptr offset, uptr size, |
| 71 | BufferedStackTrace *stack); |
| 72 | void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end, |
| 73 | uptr old_mid, uptr new_mid, |
| 74 | BufferedStackTrace *stack); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 75 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 76 | void ReportODRViolation(const __asan_global *g1, u32 stack_id1, |
| 77 | const __asan_global *g2, u32 stack_id2); |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 78 | |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 79 | // Mac-specific errors and warnings. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 80 | void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr, |
| 81 | const char *zone_name, |
| 82 | BufferedStackTrace *stack); |
| 83 | void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr, |
| 84 | const char *zone_name, |
| 85 | BufferedStackTrace *stack); |
Alexey Samsonov | 663c501 | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 86 | |
Alexey Samsonov | 7354509 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 87 | } // namespace __asan |