xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/asan/asan_report.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- asan_report.h -------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is a part of AddressSanitizer, an address sanity checker.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric // ASan-private header for error reporting functions.
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef ASAN_REPORT_H
150b57cec5SDimitry Andric #define ASAN_REPORT_H
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "asan_allocator.h"
180b57cec5SDimitry Andric #include "asan_internal.h"
190b57cec5SDimitry Andric #include "asan_thread.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace __asan {
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric struct StackVarDescr {
240b57cec5SDimitry Andric   uptr beg;
250b57cec5SDimitry Andric   uptr size;
260b57cec5SDimitry Andric   const char *name_pos;
270b57cec5SDimitry Andric   uptr name_len;
280b57cec5SDimitry Andric   uptr line;
290b57cec5SDimitry Andric };
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric // Returns the number of globals close to the provided address and copies
320b57cec5SDimitry Andric // them to "globals" array.
330b57cec5SDimitry Andric int GetGlobalsForAddress(uptr addr, __asan_global *globals, u32 *reg_sites,
340b57cec5SDimitry Andric                          int max_globals);
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric const char *MaybeDemangleGlobalName(const char *name);
370b57cec5SDimitry Andric void PrintGlobalNameIfASCII(InternalScopedString *str, const __asan_global &g);
38*5f757f3fSDimitry Andric void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g,
39*5f757f3fSDimitry Andric                          bool print_module_name);
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
420b57cec5SDimitry Andric                      bool in_shadow, const char *after = "\n");
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric // The following functions prints address description depending
450b57cec5SDimitry Andric // on the memory type (shadow/heap/stack/global).
460b57cec5SDimitry Andric bool ParseFrameDescription(const char *frame_descr,
470b57cec5SDimitry Andric                            InternalMmapVector<StackVarDescr> *vars);
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric // Different kinds of error reports.
500b57cec5SDimitry Andric void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
510b57cec5SDimitry Andric                         uptr access_size, u32 exp, bool fatal);
520b57cec5SDimitry Andric void ReportDeadlySignal(const SignalContext &sig);
530b57cec5SDimitry Andric void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size,
540b57cec5SDimitry Andric                                  uptr delete_alignment,
550b57cec5SDimitry Andric                                  BufferedStackTrace *free_stack);
560b57cec5SDimitry Andric void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
570b57cec5SDimitry Andric void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
580b57cec5SDimitry Andric void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
590b57cec5SDimitry Andric                              AllocType alloc_type,
600b57cec5SDimitry Andric                              AllocType dealloc_type);
610b57cec5SDimitry Andric void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
620b57cec5SDimitry Andric void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
630b57cec5SDimitry Andric                                              BufferedStackTrace *stack);
640b57cec5SDimitry Andric void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack);
650b57cec5SDimitry Andric void ReportReallocArrayOverflow(uptr count, uptr size,
660b57cec5SDimitry Andric                                 BufferedStackTrace *stack);
670b57cec5SDimitry Andric void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack);
680b57cec5SDimitry Andric void ReportInvalidAllocationAlignment(uptr alignment,
690b57cec5SDimitry Andric                                       BufferedStackTrace *stack);
700b57cec5SDimitry Andric void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
710b57cec5SDimitry Andric                                         BufferedStackTrace *stack);
720b57cec5SDimitry Andric void ReportInvalidPosixMemalignAlignment(uptr alignment,
730b57cec5SDimitry Andric                                          BufferedStackTrace *stack);
740b57cec5SDimitry Andric void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
750b57cec5SDimitry Andric                                 BufferedStackTrace *stack);
760b57cec5SDimitry Andric void ReportRssLimitExceeded(BufferedStackTrace *stack);
770b57cec5SDimitry Andric void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack);
780b57cec5SDimitry Andric void ReportStringFunctionMemoryRangesOverlap(const char *function,
790b57cec5SDimitry Andric                                              const char *offset1, uptr length1,
800b57cec5SDimitry Andric                                              const char *offset2, uptr length2,
810b57cec5SDimitry Andric                                              BufferedStackTrace *stack);
820b57cec5SDimitry Andric void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
830b57cec5SDimitry Andric                                       BufferedStackTrace *stack);
840b57cec5SDimitry Andric void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
850b57cec5SDimitry Andric                                                   uptr old_mid, uptr new_mid,
860b57cec5SDimitry Andric                                                   BufferedStackTrace *stack);
87bdd1243dSDimitry Andric void ReportBadParamsToAnnotateDoubleEndedContiguousContainer(
88bdd1243dSDimitry Andric     uptr storage_beg, uptr storage_end, uptr old_container_beg,
89bdd1243dSDimitry Andric     uptr old_container_end, uptr new_container_beg, uptr new_container_end,
90bdd1243dSDimitry Andric     BufferedStackTrace *stack);
910b57cec5SDimitry Andric 
920b57cec5SDimitry Andric void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
930b57cec5SDimitry Andric                         const __asan_global *g2, u32 stack_id2);
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric // Mac-specific errors and warnings.
960b57cec5SDimitry Andric void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
970b57cec5SDimitry Andric                                const char *zone_name,
980b57cec5SDimitry Andric                                BufferedStackTrace *stack);
990b57cec5SDimitry Andric void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
1000b57cec5SDimitry Andric                                const char *zone_name,
1010b57cec5SDimitry Andric                                BufferedStackTrace *stack);
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric }  // namespace __asan
1040b57cec5SDimitry Andric #endif  // ASAN_REPORT_H
105