• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "asan_allocator.h"
16 #include "asan_internal.h"
17 #include "asan_thread.h"
18 
19 namespace __asan {
20 
21 struct StackVarDescr {
22   uptr beg;
23   uptr size;
24   const char *name_pos;
25   uptr name_len;
26 };
27 
28 struct AddressDescription {
29   char *name;
30   uptr name_size;
31   uptr region_address;
32   uptr region_size;
33   const char *region_kind;
34 };
35 
36 // The following functions prints address description depending
37 // on the memory type (shadow/heap/stack/global).
38 void DescribeHeapAddress(uptr addr, uptr access_size);
39 bool DescribeAddressIfGlobal(uptr addr, uptr access_size);
40 bool DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
41                                      const __asan_global &g);
42 bool IsAddressNearGlobal(uptr addr, const __asan_global &g);
43 bool GetInfoForAddressIfGlobal(uptr addr, AddressDescription *descr);
44 bool DescribeAddressIfShadow(uptr addr, AddressDescription *descr = nullptr,
45                              bool print = true);
46 bool ParseFrameDescription(const char *frame_descr,
47                            InternalMmapVector<StackVarDescr> *vars);
48 bool DescribeAddressIfStack(uptr addr, uptr access_size);
49 // Determines memory type on its own.
50 void DescribeAddress(uptr addr, uptr access_size);
51 
52 void DescribeThread(AsanThreadContext *context);
53 
54 // Different kinds of error reports.
55 void NORETURN ReportStackOverflow(const SignalContext &sig);
56 void NORETURN ReportSIGSEGV(const char *description, const SignalContext &sig);
57 void NORETURN ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
58                                           BufferedStackTrace *free_stack);
59 void NORETURN ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
60 void NORETURN ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
61 void NORETURN ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
62                                       AllocType alloc_type,
63                                       AllocType dealloc_type);
64 void NORETURN
65     ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
66 void NORETURN
67     ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
68                                             BufferedStackTrace *stack);
69 void NORETURN
70     ReportStringFunctionMemoryRangesOverlap(const char *function,
71                                             const char *offset1, uptr length1,
72                                             const char *offset2, uptr length2,
73                                             BufferedStackTrace *stack);
74 void NORETURN ReportStringFunctionSizeOverflow(uptr offset, uptr size,
75                                                BufferedStackTrace *stack);
76 void NORETURN
77     ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
78                                                  uptr old_mid, uptr new_mid,
79                                                  BufferedStackTrace *stack);
80 
81 void NORETURN
82 ReportODRViolation(const __asan_global *g1, u32 stack_id1,
83                    const __asan_global *g2, u32 stack_id2);
84 
85 // Mac-specific errors and warnings.
86 void WarnMacFreeUnallocated(uptr addr, uptr zone_ptr, const char *zone_name,
87                             BufferedStackTrace *stack);
88 void NORETURN ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
89                                         const char *zone_name,
90                                         BufferedStackTrace *stack);
91 void NORETURN ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
92                                         const char *zone_name,
93                                         BufferedStackTrace *stack);
94 
95 }  // namespace __asan
96