asan_report.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. void PrintMemoryByte(InternalScopedString *str, const char *before, u8 byte,
  34. bool in_shadow, const char *after = "\n");
  35. // The following functions prints address description depending
  36. // on the memory type (shadow/heap/stack/global).
  37. bool ParseFrameDescription(const char *frame_descr,
  38. InternalMmapVector<StackVarDescr> *vars);
  39. // Different kinds of error reports.
  40. void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
  41. uptr access_size, u32 exp, bool fatal);
  42. void ReportDeadlySignal(const SignalContext &sig);
  43. void ReportNewDeleteTypeMismatch(uptr addr, uptr delete_size,
  44. uptr delete_alignment,
  45. BufferedStackTrace *free_stack);
  46. void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
  47. void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
  48. void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
  49. AllocType alloc_type,
  50. AllocType dealloc_type);
  51. void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
  52. void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
  53. BufferedStackTrace *stack);
  54. void ReportCallocOverflow(uptr count, uptr size, BufferedStackTrace *stack);
  55. void ReportReallocArrayOverflow(uptr count, uptr size,
  56. BufferedStackTrace *stack);
  57. void ReportPvallocOverflow(uptr size, BufferedStackTrace *stack);
  58. void ReportInvalidAllocationAlignment(uptr alignment,
  59. BufferedStackTrace *stack);
  60. void ReportInvalidAlignedAllocAlignment(uptr size, uptr alignment,
  61. BufferedStackTrace *stack);
  62. void ReportInvalidPosixMemalignAlignment(uptr alignment,
  63. BufferedStackTrace *stack);
  64. void ReportAllocationSizeTooBig(uptr user_size, uptr total_size, uptr max_size,
  65. BufferedStackTrace *stack);
  66. void ReportRssLimitExceeded(BufferedStackTrace *stack);
  67. void ReportOutOfMemory(uptr requested_size, BufferedStackTrace *stack);
  68. void ReportStringFunctionMemoryRangesOverlap(const char *function,
  69. const char *offset1, uptr length1,
  70. const char *offset2, uptr length2,
  71. BufferedStackTrace *stack);
  72. void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
  73. BufferedStackTrace *stack);
  74. void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
  75. uptr old_mid, uptr new_mid,
  76. BufferedStackTrace *stack);
  77. void ReportODRViolation(const __asan_global *g1, u32 stack_id1,
  78. const __asan_global *g2, u32 stack_id2);
  79. // Mac-specific errors and warnings.
  80. void ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
  81. const char *zone_name,
  82. BufferedStackTrace *stack);
  83. void ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
  84. const char *zone_name,
  85. BufferedStackTrace *stack);
  86. } // namespace __asan
  87. #endif // ASAN_REPORT_H