| 1 |
//===-- asan_report.h -------------------------------------------*- C++ -*-===// |
| 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 |
// ASan-private header for error reporting functions. |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#ifndef ASAN_REPORT_H |
| 15 |
#define ASAN_REPORT_H |
| 16 |
|
| 17 |
#include "asan_allocator.h" |
| 18 |
#include "asan_internal.h" |
| 19 |
#include "asan_thread.h" |
| 20 |
|
| 21 |
namespace __asan { |
| 22 |
|
| 23 |
struct StackVarDescr { |
| 24 |
uptr beg; |
| 25 |
uptr size; |
| 26 |
const char *name_pos; |
| 27 |
uptr name_len; |
| 28 |
uptr line; |
| 29 |
}; |
| 30 |
|
| 31 |
// Returns the number of globals close to the provided address and copies |
| 32 |
// them to "globals" array. |
| 33 |
int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites, |
| 34 |
int max_globals); |
| 35 |
|
| 36 |
const char *MaybeDemangleGlobalName(const char *name); |
| 37 |
void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g); |
| 38 |
void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g, |
| 39 |
bool print_module_name); |
| 40 |
|
| 41 |
void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte, |
| 42 |
bool in_shadow, const char *after = "\n"); |
| 43 |
|
| 44 |
// The following functions prints address description depending |
| 45 |
// on the memory type (shadow/heap/stack/global). |
| 46 |
bool ParseFrameDescription(const char *frame_descr, |
| 47 |
InternalMmapVector<StackVarDescr> *vars); |
| 48 |
|
| 49 |
// Different kinds of error reports. |
| 50 |
void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write, |
| 51 |
uptr access_size, u32 exp, bool fatal); |
| 52 |
void ReportDeadlySignal(const SignalContext &sig); |
| 53 |
void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size, |
| 54 |
uptr delete_alignment, |
| 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); |
| 64 |
void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack); |
| 65 |
void ReportReallocArrayOverflow(uptr count, uptr size, |
| 66 |
BufferedStackTrace *stack); |
| 67 |
void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack); |
| 68 |
void ReportInvalidAllocationAlignment(uptr alignment, |
| 69 |
BufferedStackTrace *stack); |
| 70 |
void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment, |
| 71 |
BufferedStackTrace *stack); |
| 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); |
| 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); |
| 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); |
| 91 |
void ReportBadParamsToCopyContiguousContainerAnnotations( |
| 92 |
uptr old_storage_beg, uptr old_storage_end, uptr new_storage_beg, |
| 93 |
uptr new_storage_end, BufferedStackTrace *stack); |
| 94 |
|
| 95 |
void ReportODRViolation(const __asan_global *g1, u32 stack_id1, |
| 96 |
const __asan_global *g2, u32 stack_id2); |
| 97 |
|
| 98 |
// Mac-specific errors and warnings. |
| 99 |
void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr, |
| 100 |
const char *zone_name, |
| 101 |
BufferedStackTrace *stack); |
| 102 |
void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr, |
| 103 |
const char *zone_name, |
| 104 |
BufferedStackTrace *stack); |
| 105 |
|
| 106 |
} // namespace __asan |
| 107 |
#endif // ASAN_REPORT_H |