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 #ifndef ASAN_REPORT_H
14 #define ASAN_REPORT_H
15 
16 #include "asan_allocator.h"
17 #include "asan_internal.h"
18 #include "asan_thread.h"
19 
20 namespace __asan {
21 
22 struct StackVarDescr {
23   uptr beg;
24   uptr size;
25   const char *name_pos;
26   uptr name_len;
27   uptr line;
28 };
29 
30 // Returns the number of globals close to the provided address and copies
31 // them to "globals" array.
32 int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites,
33                          int max_globals);
34 
35 const char *MaybeDemangleGlobalName(const char *name);
36 void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g);
37 void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g);
38 
39 void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
40                      bool in_shadow, const char *after = "\n");
41 
42 // The following functions prints address description depending
43 // on the memory type (shadow/heap/stack/global).
44 bool ParseFrameDescription(const char *frame_descr,
45                            InternalMmapVector<StackVarDescr> *vars);
46 
47 // Different kinds of error reports.
48 void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
49                         uptr access_size, u32 exp, bool fatal);
50 void ReportDeadlySignal(const SignalContext &sig);
51 void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size,
52                                  uptr delete_alignment,
53                                  BufferedStackTrace *free_stack);
54 void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
55 void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
56 void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
57                              AllocType alloc_type,
58                              AllocType dealloc_type);
59 void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
60 void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
61                                              BufferedStackTrace *stack);
62 void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack);
63 void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack);
64 void ReportInvalidAllocationAlignment(uptr alignment,
65                                       BufferedStackTrace *stack);
66 void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
67                                         BufferedStackTrace *stack);
68 void ReportInvalidPosixMemalignAlignment(uptr alignment,
69                                          BufferedStackTrace *stack);
70 void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
71                                 BufferedStackTrace *stack);
72 void ReportRssLimitExceeded(BufferedStackTrace *stack);
73 void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack);
74 void ReportStringFunctionMemoryRangesOverlap(const char *function,
75                                              const char *offset1, uptr length1,
76                                              const char *offset2, uptr length2,
77                                              BufferedStackTrace *stack);
78 void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
79                                       BufferedStackTrace *stack);
80 void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
81                                                   uptr old_mid, uptr new_mid,
82                                                   BufferedStackTrace *stack);
83 
84 void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
85                         const __asan_global *g2, u32 stack_id2);
86 
87 // Mac-specific errors and warnings.
88 void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
89                                const char *zone_name,
90                                BufferedStackTrace *stack);
91 void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
92                                const char *zone_name,
93                                BufferedStackTrace *stack);
94 
95 }  // namespace __asan
96 #endif  // ASAN_REPORT_H
97