asan_report.h 4.9 KB

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