asan_report.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===-- asan_report.h -------------------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of AddressSanitizer, an address sanity checker.
  9. //
  10. // ASan-private header for error reporting functions.
  11. //===----------------------------------------------------------------------===//
  12. #include "asan_allocator.h"
  13. #include "asan_internal.h"
  14. #include "asan_thread.h"
  15. namespace __asan {
  16. struct StackVarDescr {
  17. uptr beg;
  18. uptr size;
  19. const char *name_pos;
  20. uptr name_len;
  21. };
  22. struct AddressDescription {
  23. char *name;
  24. uptr name_size;
  25. uptr region_address;
  26. uptr region_size;
  27. const char *region_kind;
  28. };
  29. // The following functions prints address description depending
  30. // on the memory type (shadow/heap/stack/global).
  31. void DescribeHeapAddress(uptr addr, uptr access_size);
  32. bool DescribeAddressIfGlobal(uptr addr, uptr access_size);
  33. bool DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
  34. const __asan_global &g);
  35. bool IsAddressNearGlobal(uptr addr, const __asan_global &g);
  36. bool GetInfoForAddressIfGlobal(uptr addr, AddressDescription *descr);
  37. bool DescribeAddressIfShadow(uptr addr, AddressDescription *descr = nullptr,
  38. bool print = true);
  39. bool ParseFrameDescription(const char *frame_descr,
  40. InternalMmapVector<StackVarDescr> *vars);
  41. bool DescribeAddressIfStack(uptr addr, uptr access_size);
  42. // Determines memory type on its own.
  43. void DescribeAddress(uptr addr, uptr access_size);
  44. void DescribeThread(AsanThreadContext *context);
  45. // Different kinds of error reports.
  46. void NORETURN
  47. ReportStackOverflow(uptr pc, uptr sp, uptr bp, void *context, uptr addr);
  48. void NORETURN ReportSIGSEGV(const char *description, uptr pc, uptr sp, uptr bp,
  49. void *context, uptr addr);
  50. void NORETURN ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
  51. BufferedStackTrace *free_stack);
  52. void NORETURN ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack);
  53. void NORETURN ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack);
  54. void NORETURN ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
  55. AllocType alloc_type,
  56. AllocType dealloc_type);
  57. void NORETURN
  58. ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack);
  59. void NORETURN
  60. ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
  61. BufferedStackTrace *stack);
  62. void NORETURN
  63. ReportStringFunctionMemoryRangesOverlap(const char *function,
  64. const char *offset1, uptr length1,
  65. const char *offset2, uptr length2,
  66. BufferedStackTrace *stack);
  67. void NORETURN ReportStringFunctionSizeOverflow(uptr offset, uptr size,
  68. BufferedStackTrace *stack);
  69. void NORETURN
  70. ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
  71. uptr old_mid, uptr new_mid,
  72. BufferedStackTrace *stack);
  73. void NORETURN
  74. ReportODRViolation(const __asan_global *g1, u32 stack_id1,
  75. const __asan_global *g2, u32 stack_id2);
  76. // Mac-specific errors and warnings.
  77. void WarnMacFreeUnallocated(uptr addr, uptr zone_ptr, const char *zone_name,
  78. BufferedStackTrace *stack);
  79. void NORETURN ReportMacMzReallocUnknown(uptr addr, uptr zone_ptr,
  80. const char *zone_name,
  81. BufferedStackTrace *stack);
  82. void NORETURN ReportMacCfReallocUnknown(uptr addr, uptr zone_ptr,
  83. const char *zone_name,
  84. BufferedStackTrace *stack);
  85. } // namespace __asan