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