Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 1 | //===-- asan_report.h -------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 0748fbc | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file is a part of AddressSanitizer, an address sanity checker. |
| 10 | // |
| 11 | // ASan-private header for error reporting functions. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Filipe Cabecinhas | 654a960 | 2018-08-02 11:05:07 +0000 | [diff] [blame] | 14 | #ifndef ASAN_REPORT_H |
| 15 | #define ASAN_REPORT_H |
| 16 | |
Kostya Serebryany | 583b224 | 2012-12-21 08:53:59 +0000 | [diff] [blame] | 17 | #include "asan_allocator.h" |
Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 18 | #include "asan_internal.h" |
Alexey Samsonov | 6c65d1c | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 19 | #include "asan_thread.h" |
Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 20 | |
| 21 | namespace __asan { |
| 22 | |
Kuba Brecka | 33c72fa | 2014-07-17 00:18:03 +0000 | [diff] [blame] | 23 | struct StackVarDescr { |
| 24 | uptr beg; |
| 25 | uptr size; |
| 26 | const char *name_pos; |
| 27 | uptr name_len; |
Kuba Mracek | 64a0ab3 | 2017-03-30 00:41:09 +0000 | [diff] [blame] | 28 | uptr line; |
Kuba Brecka | 33c72fa | 2014-07-17 00:18:03 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
Alexey Samsonov | 0c3a463 | 2015-04-22 20:30:15 +0000 | [diff] [blame] | 31 | // Returns the number of globals close to the provided address and copies |
| 32 | // them to "globals" array. |
Alexey Samsonov | 6ccfd16 | 2015-04-22 20:30:19 +0000 | [diff] [blame] | 33 | int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites, |
| 34 | int max_globals); |
Filipe Cabecinhas | 194d6ec | 2016-08-17 19:52:12 +0000 | [diff] [blame] | 35 | |
| 36 | const char *MaybeDemangleGlobalName(const char *name); |
| 37 | void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g); |
Fangrui Song | 499c9ee | 2023-11-10 13:12:27 -0800 | [diff] [blame] | 38 | void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g, |
| 39 | bool print_module_name); |
Filipe Cabecinhas | 194d6ec | 2016-08-17 19:52:12 +0000 | [diff] [blame] | 40 | |
Filipe Cabecinhas | 1aaf2fc | 2016-09-08 12:58:15 +0000 | [diff] [blame] | 41 | void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte, |
| 42 | bool in_shadow, const char *after = "\n"); |
| 43 | |
Alexey Samsonov | 0c18627 | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 44 | // The following functions prints address description depending |
| 45 | // on the memory type (shadow/heap/stack/global). |
Kuba Brecka | 33c72fa | 2014-07-17 00:18:03 +0000 | [diff] [blame] | 46 | bool ParseFrameDescription(const char *frame_descr, |
| 47 | InternalMmapVector<StackVarDescr> *vars); |
Alexey Samsonov | 6c65d1c | 2012-09-05 07:37:15 +0000 | [diff] [blame] | 48 | |
Alexey Samsonov | 0c18627 | 2012-08-09 09:06:52 +0000 | [diff] [blame] | 49 | // Different kinds of error reports. |
Yury Gribov | c615271 | 2015-11-11 11:59:38 +0000 | [diff] [blame] | 50 | void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write, |
| 51 | uptr access_size, u32 exp, bool fatal); |
Vitaly Buka | 5001816 | 2017-09-13 18:30:06 +0000 | [diff] [blame] | 52 | void ReportDeadlySignal(const SignalContext &sig); |
Alex Shlyapnikov | 1201618 | 2017-10-25 17:21:37 +0000 | [diff] [blame] | 53 | void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size, |
| 54 | uptr delete_alignment, |
Yury Gribov | c615271 | 2015-11-11 11:59:38 +0000 | [diff] [blame] | 55 | BufferedStackTrace *free_stack); |
| 56 | void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack); |
| 57 | void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack); |
| 58 | void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack, |
| 59 | AllocType alloc_type, |
| 60 | AllocType dealloc_type); |
| 61 | void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack); |
| 62 | void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr, |
| 63 | BufferedStackTrace *stack); |
Alex Shlyapnikov | 6761349 | 2018-03-28 18:22:40 +0000 | [diff] [blame] | 64 | void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack); |
Evgeniy Stepanov | 0ec7ff5 | 2019-05-01 17:33:01 +0000 | [diff] [blame] | 65 | void ReportReallocArrayOverflow(uptr count, uptr size, |
| 66 | BufferedStackTrace *stack); |
Alex Shlyapnikov | 6761349 | 2018-03-28 18:22:40 +0000 | [diff] [blame] | 67 | void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack); |
| 68 | void ReportInvalidAllocationAlignment(uptr alignment, |
| 69 | BufferedStackTrace *stack); |
Alex Shlyapnikov | 188de71 | 2018-06-08 20:40:35 +0000 | [diff] [blame] | 70 | void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment, |
| 71 | BufferedStackTrace *stack); |
Alex Shlyapnikov | 6761349 | 2018-03-28 18:22:40 +0000 | [diff] [blame] | 72 | void ReportInvalidPosixMemalignAlignment(uptr alignment, |
| 73 | BufferedStackTrace *stack); |
| 74 | void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size, |
| 75 | BufferedStackTrace *stack); |
| 76 | void ReportRssLimitExceeded(BufferedStackTrace *stack); |
| 77 | void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack); |
Yury Gribov | c615271 | 2015-11-11 11:59:38 +0000 | [diff] [blame] | 78 | void ReportStringFunctionMemoryRangesOverlap(const char *function, |
| 79 | const char *offset1, uptr length1, |
| 80 | const char *offset2, uptr length2, |
| 81 | BufferedStackTrace *stack); |
| 82 | void ReportStringFunctionSizeOverflow(uptr offset, uptr size, |
| 83 | BufferedStackTrace *stack); |
| 84 | void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end, |
| 85 | uptr old_mid, uptr new_mid, |
| 86 | BufferedStackTrace *stack); |
Advenam Tacet | c27b0c2 | 2022-11-19 17:34:46 -0800 | [diff] [blame] | 87 | void ReportBadParamsToAnnotateDoubleEndedContiguousContainer( |
| 88 | uptr storage_beg, uptr storage_end, uptr old_container_beg, |
| 89 | uptr old_container_end, uptr new_container_beg, uptr new_container_end, |
| 90 | BufferedStackTrace *stack); |
Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 91 | |
Yury Gribov | c615271 | 2015-11-11 11:59:38 +0000 | [diff] [blame] | 92 | void ReportODRViolation(const __asan_global *g1, u32 stack_id1, |
| 93 | const __asan_global *g2, u32 stack_id2); |
Kostya Serebryany | 927e65a | 2014-04-25 08:58:28 +0000 | [diff] [blame] | 94 | |
Alexey Samsonov | 41f8e9b | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 95 | // Mac-specific errors and warnings. |
Yury Gribov | c615271 | 2015-11-11 11:59:38 +0000 | [diff] [blame] | 96 | void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr, |
| 97 | const char *zone_name, |
| 98 | BufferedStackTrace *stack); |
| 99 | void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr, |
| 100 | const char *zone_name, |
| 101 | BufferedStackTrace *stack); |
Alexey Samsonov | 41f8e9b | 2012-08-09 12:15:40 +0000 | [diff] [blame] | 102 | |
Alexey Samsonov | 47c5766 | 2012-08-09 07:40:58 +0000 | [diff] [blame] | 103 | } // namespace __asan |
Filipe Cabecinhas | 654a960 | 2018-08-02 11:05:07 +0000 | [diff] [blame] | 104 | #endif // ASAN_REPORT_H |