blob: 3540b3b4b1bfe0d7361730793939455dc47f6719 [file] [log] [blame]
Alexey Samsonov47c57662012-08-09 07:40:58 +00001//===-- asan_report.h -------------------------------------------*- C++ -*-===//
2//
Chandler Carruth0748fbc2019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Alexey Samsonov47c57662012-08-09 07:40:58 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of AddressSanitizer, an address sanity checker.
10//
11// ASan-private header for error reporting functions.
12//===----------------------------------------------------------------------===//
13
Filipe Cabecinhas654a9602018-08-02 11:05:07 +000014#ifndef ASAN_REPORT_H
15#define ASAN_REPORT_H
16
Kostya Serebryany583b2242012-12-21 08:53:59 +000017#include "asan_allocator.h"
Alexey Samsonov47c57662012-08-09 07:40:58 +000018#include "asan_internal.h"
Alexey Samsonov6c65d1c2012-09-05 07:37:15 +000019#include "asan_thread.h"
Alexey Samsonov47c57662012-08-09 07:40:58 +000020
21namespace __asan {
22
Kuba Brecka33c72fa2014-07-17 00:18:03 +000023struct StackVarDescr {
24 uptr beg;
25 uptr size;
26 const char *name_pos;
27 uptr name_len;
Kuba Mracek64a0ab32017-03-30 00:41:09 +000028 uptr line;
Kuba Brecka33c72fa2014-07-17 00:18:03 +000029};
30
Alexey Samsonov0c3a4632015-04-22 20:30:15 +000031// Returns the number of globals close to the provided address and copies
32// them to "globals" array.
Alexey Samsonov6ccfd162015-04-22 20:30:19 +000033int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites,
34 int max_globals);
Filipe Cabecinhas194d6ec2016-08-17 19:52:12 +000035
36const char *MaybeDemangleGlobalName(const char *name);
37void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g);
Fangrui Song499c9ee2023-11-10 13:12:27 -080038void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g,
39 bool print_module_name);
Filipe Cabecinhas194d6ec2016-08-17 19:52:12 +000040
Filipe Cabecinhas1aaf2fc2016-09-08 12:58:15 +000041void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
42 bool in_shadow, const char *after = "\n");
43
Alexey Samsonov0c186272012-08-09 09:06:52 +000044// The following functions prints address description depending
45// on the memory type (shadow/heap/stack/global).
Kuba Brecka33c72fa2014-07-17 00:18:03 +000046bool ParseFrameDescription(const char *frame_descr,
47 InternalMmapVector<StackVarDescr> *vars);
Alexey Samsonov6c65d1c2012-09-05 07:37:15 +000048
Alexey Samsonov0c186272012-08-09 09:06:52 +000049// Different kinds of error reports.
Yury Gribovc6152712015-11-11 11:59:38 +000050void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
51 uptr access_size, u32 exp, bool fatal);
Vitaly Buka50018162017-09-13 18:30:06 +000052void ReportDeadlySignal(const SignalContext &sig);
Alex Shlyapnikov12016182017-10-25 17:21:37 +000053void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size,
54 uptr delete_alignment,
Yury Gribovc6152712015-11-11 11:59:38 +000055 BufferedStackTrace *free_stack);
56void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
57void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
58void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
59 AllocType alloc_type,
60 AllocType dealloc_type);
61void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
62void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
63 BufferedStackTrace *stack);
Alex Shlyapnikov67613492018-03-28 18:22:40 +000064void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack);
Evgeniy Stepanov0ec7ff52019-05-01 17:33:01 +000065void ReportReallocArrayOverflow(uptr count, uptr size,
66 BufferedStackTrace *stack);
Alex Shlyapnikov67613492018-03-28 18:22:40 +000067void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack);
68void ReportInvalidAllocationAlignment(uptr alignment,
69 BufferedStackTrace *stack);
Alex Shlyapnikov188de712018-06-08 20:40:35 +000070void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
71 BufferedStackTrace *stack);
Alex Shlyapnikov67613492018-03-28 18:22:40 +000072void ReportInvalidPosixMemalignAlignment(uptr alignment,
73 BufferedStackTrace *stack);
74void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
75 BufferedStackTrace *stack);
76void ReportRssLimitExceeded(BufferedStackTrace *stack);
77void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack);
Yury Gribovc6152712015-11-11 11:59:38 +000078void ReportStringFunctionMemoryRangesOverlap(const char *function,
79 const char *offset1, uptr length1,
80 const char *offset2, uptr length2,
81 BufferedStackTrace *stack);
82void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
83 BufferedStackTrace *stack);
84void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
85 uptr old_mid, uptr new_mid,
86 BufferedStackTrace *stack);
Advenam Tacetc27b0c22022-11-19 17:34:46 -080087void ReportBadParamsToAnnotateDoubleEndedContiguousContainer(
88 uptr storage_beg, uptr storage_end, uptr old_container_beg,
89 uptr old_container_end, uptr new_container_beg, uptr new_container_end,
90 BufferedStackTrace *stack);
Alexey Samsonov47c57662012-08-09 07:40:58 +000091
Yury Gribovc6152712015-11-11 11:59:38 +000092void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
93 const __asan_global *g2, u32 stack_id2);
Kostya Serebryany927e65a2014-04-25 08:58:28 +000094
Alexey Samsonov41f8e9b2012-08-09 12:15:40 +000095// Mac-specific errors and warnings.
Yury Gribovc6152712015-11-11 11:59:38 +000096void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
97 const char *zone_name,
98 BufferedStackTrace *stack);
99void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
100 const char *zone_name,
101 BufferedStackTrace *stack);
Alexey Samsonov41f8e9b2012-08-09 12:15:40 +0000102
Alexey Samsonov47c57662012-08-09 07:40:58 +0000103} // namespace __asan
Filipe Cabecinhas654a9602018-08-02 11:05:07 +0000104#endif // ASAN_REPORT_H