blob: e2786b0f260ce3bd40309980b1dadb18860e8258 [file] [log] [blame]
Alexey Samsonov73545092012-08-09 07:40:58 +00001//===-- 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
Kostya Serebryanyfe6d9162012-12-21 08:53:59 +000015#include "asan_allocator.h"
Alexey Samsonov73545092012-08-09 07:40:58 +000016#include "asan_internal.h"
Alexey Samsonov71b42c92012-09-05 07:37:15 +000017#include "asan_thread.h"
Alexey Samsonov73545092012-08-09 07:40:58 +000018
19namespace __asan {
20
Stephen Hines6d186232014-11-26 17:56:19 -080021struct StackVarDescr {
22 uptr beg;
23 uptr size;
24 const char *name_pos;
25 uptr name_len;
26};
27
28struct AddressDescription {
29 char *name;
30 uptr name_size;
31 uptr region_address;
32 uptr region_size;
33 const char *region_kind;
34};
35
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070036// Returns the number of globals close to the provided address and copies
37// them to "globals" array.
38int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites,
39 int max_globals);
40bool GetInfoForAddressIfGlobal(uptr addr, AddressDescription *descr);
Alexey Samsonove218beb2012-08-09 09:06:52 +000041// The following functions prints address description depending
42// on the memory type (shadow/heap/stack/global).
43void DescribeHeapAddress(uptr addr, uptr access_size);
Stephen Hines6d186232014-11-26 17:56:19 -080044bool DescribeAddressIfShadow(uptr addr, AddressDescription *descr = nullptr,
45 bool print = true);
46bool ParseFrameDescription(const char *frame_descr,
47 InternalMmapVector<StackVarDescr> *vars);
Alexey Samsonove218beb2012-08-09 09:06:52 +000048bool DescribeAddressIfStack(uptr addr, uptr access_size);
Alexey Samsonovdef1be92013-03-21 11:23:41 +000049void DescribeThread(AsanThreadContext *context);
Alexey Samsonov71b42c92012-09-05 07:37:15 +000050
Alexey Samsonove218beb2012-08-09 09:06:52 +000051// Different kinds of error reports.
Stephen Hines86277eb2015-03-23 12:06:32 -070052void NORETURN ReportStackOverflow(const SignalContext &sig);
53void NORETURN ReportSIGSEGV(const char *description, const SignalContext &sig);
Stephen Hines6d186232014-11-26 17:56:19 -080054void NORETURN ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
55 BufferedStackTrace *free_stack);
56void NORETURN ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
57void NORETURN ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
58void NORETURN ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
Kostya Serebryanyfe6d9162012-12-21 08:53:59 +000059 AllocType alloc_type,
60 AllocType dealloc_type);
Stephen Hines6a211c52014-07-21 00:49:56 -070061void NORETURN
Stephen Hines6d186232014-11-26 17:56:19 -080062 ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070063void NORETURN
Stephen Hines6d186232014-11-26 17:56:19 -080064 ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
65 BufferedStackTrace *stack);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070066void NORETURN
Stephen Hines6d186232014-11-26 17:56:19 -080067 ReportStringFunctionMemoryRangesOverlap(const char *function,
68 const char *offset1, uptr length1,
69 const char *offset2, uptr length2,
70 BufferedStackTrace *stack);
71void NORETURN ReportStringFunctionSizeOverflow(uptr offset, uptr size,
72 BufferedStackTrace *stack);
73void NORETURN
74 ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
75 uptr old_mid, uptr new_mid,
76 BufferedStackTrace *stack);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070077
78void NORETURN
Stephen Hines6a211c52014-07-21 00:49:56 -070079ReportODRViolation(const __asan_global *g1, u32 stack_id1,
80 const __asan_global *g2, u32 stack_id2);
Alexey Samsonov73545092012-08-09 07:40:58 +000081
Alexey Samsonov663c5012012-08-09 12:15:40 +000082// Mac-specific errors and warnings.
Stephen Hines6d186232014-11-26 17:56:19 -080083void WarnMacFreeUnallocated(uptr addr, uptr zone_ptr, const char *zone_name,
84 BufferedStackTrace *stack);
85void NORETURN ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
86 const char *zone_name,
87 BufferedStackTrace *stack);
88void NORETURN ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
89 const char *zone_name,
90 BufferedStackTrace *stack);
Alexey Samsonov663c5012012-08-09 12:15:40 +000091
Alexey Samsonov73545092012-08-09 07:40:58 +000092} // namespace __asan