Home | History | Annotate | Line # | Download | only in asan
      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 
     15 #ifndef ASAN_REPORT_H
     16 #define ASAN_REPORT_H
     17 
     18 #include "asan_allocator.h"
     19 #include "asan_internal.h"
     20 #include "asan_thread.h"
     21 
     22 namespace __asan {
     23 
     24 struct StackVarDescr {
     25   uptr beg;
     26   uptr size;
     27   const char *name_pos;
     28   uptr name_len;
     29   uptr line;
     30 };
     31 
     32 // Returns the number of globals close to the provided address and copies
     33 // them to "globals" array.
     34 int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites,
     35                          int max_globals);
     36 
     37 const char *MaybeDemangleGlobalName(const char *name);
     38 void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g);
     39 void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g);
     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 ReportPvallocOverflow(uptr size, BufferedStackTrace *stack);
     66 void ReportInvalidAllocationAlignment(uptr alignment,
     67                                       BufferedStackTrace *stack);
     68 void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
     69                                         BufferedStackTrace *stack);
     70 void ReportInvalidPosixMemalignAlignment(uptr alignment,
     71                                          BufferedStackTrace *stack);
     72 void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
     73                                 BufferedStackTrace *stack);
     74 void ReportRssLimitExceeded(BufferedStackTrace *stack);
     75 void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack);
     76 void ReportStringFunctionMemoryRangesOverlap(const char *function,
     77                                              const char *offset1, uptr length1,
     78                                              const char *offset2, uptr length2,
     79                                              BufferedStackTrace *stack);
     80 void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
     81                                       BufferedStackTrace *stack);
     82 void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
     83                                                   uptr old_mid, uptr new_mid,
     84                                                   BufferedStackTrace *stack);
     85 
     86 void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
     87                         const __asan_global *g2, u32 stack_id2);
     88 
     89 // Mac-specific errors and warnings.
     90 void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
     91                                const char *zone_name,
     92                                BufferedStackTrace *stack);
     93 void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
     94                                const char *zone_name,
     95                                BufferedStackTrace *stack);
     96 
     97 }  // namespace __asan
     98 #endif  // ASAN_REPORT_H
     99