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