common_interface_defs.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //===-- sanitizer/common_interface_defs.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. // Common part of the public sanitizer interface.
  9. //===----------------------------------------------------------------------===//
  10. #ifndef SANITIZER_COMMON_INTERFACE_DEFS_H
  11. #define SANITIZER_COMMON_INTERFACE_DEFS_H
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. // GCC does not understand __has_feature.
  15. #if !defined(__has_feature)
  16. # define __has_feature(x) 0
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. // Arguments for __sanitizer_sandbox_on_notify() below.
  22. typedef struct {
  23. // Enable sandbox support in sanitizer coverage.
  24. int coverage_sandboxed;
  25. // File descriptor to write coverage data to. If -1 is passed, a file will
  26. // be pre-opened by __sanitizer_sandobx_on_notify(). This field has no
  27. // effect if coverage_sandboxed == 0.
  28. intptr_t coverage_fd;
  29. // If non-zero, split the coverage data into well-formed blocks. This is
  30. // useful when coverage_fd is a socket descriptor. Each block will contain
  31. // a header, allowing data from multiple processes to be sent over the same
  32. // socket.
  33. unsigned int coverage_max_block_size;
  34. } __sanitizer_sandbox_arguments;
  35. // Tell the tools to write their reports to "path.<pid>" instead of stderr.
  36. void __sanitizer_set_report_path(const char *path);
  37. // Notify the tools that the sandbox is going to be turned on. The reserved
  38. // parameter will be used in the future to hold a structure with functions
  39. // that the tools may call to bypass the sandbox.
  40. void __sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments *args);
  41. // This function is called by the tool when it has just finished reporting
  42. // an error. 'error_summary' is a one-line string that summarizes
  43. // the error message. This function can be overridden by the client.
  44. void __sanitizer_report_error_summary(const char *error_summary);
  45. // Some of the sanitizers (e.g. asan/tsan) may miss bugs that happen
  46. // in unaligned loads/stores. In order to find such bugs reliably one needs
  47. // to replace plain unaligned loads/stores with these calls.
  48. uint16_t __sanitizer_unaligned_load16(const void *p);
  49. uint32_t __sanitizer_unaligned_load32(const void *p);
  50. uint64_t __sanitizer_unaligned_load64(const void *p);
  51. void __sanitizer_unaligned_store16(void *p, uint16_t x);
  52. void __sanitizer_unaligned_store32(void *p, uint32_t x);
  53. void __sanitizer_unaligned_store64(void *p, uint64_t x);
  54. // Initialize coverage.
  55. void __sanitizer_cov_init();
  56. // Record and dump coverage info.
  57. void __sanitizer_cov_dump();
  58. // Open <name>.sancov.packed in the coverage directory and return the file
  59. // descriptor. Returns -1 on failure, or if coverage dumping is disabled.
  60. // This is intended for use by sandboxing code.
  61. intptr_t __sanitizer_maybe_open_cov_file(const char *name);
  62. // Annotate the current state of a contiguous container, such as
  63. // std::vector, std::string or similar.
  64. // A contiguous container is a container that keeps all of its elements
  65. // in a contiguous region of memory. The container owns the region of memory
  66. // [beg, end); the memory [beg, mid) is used to store the current elements
  67. // and the memory [mid, end) is reserved for future elements;
  68. // beg <= mid <= end. For example, in "std::vector<> v"
  69. // beg = &v[0];
  70. // end = beg + v.capacity() * sizeof(v[0]);
  71. // mid = beg + v.size() * sizeof(v[0]);
  72. //
  73. // This annotation tells the Sanitizer tool about the current state of the
  74. // container so that the tool can report errors when memory from [mid, end)
  75. // is accessed. Insert this annotation into methods like push_back/pop_back.
  76. // Supply the old and the new values of mid (old_mid/new_mid).
  77. // In the initial state mid == end and so should be the final
  78. // state when the container is destroyed or when it reallocates the storage.
  79. //
  80. // Use with caution and don't use for anything other than vector-like classes.
  81. //
  82. // For AddressSanitizer, 'beg' should be 8-aligned and 'end' should
  83. // be either 8-aligned or it should point to the end of a separate heap-,
  84. // stack-, or global- allocated buffer. I.e. the following will not work:
  85. // int64_t x[2]; // 16 bytes, 8-aligned.
  86. // char *beg = (char *)&x[0];
  87. // char *end = beg + 12; // Not 8 aligned, not the end of the buffer.
  88. // This however will work fine:
  89. // int32_t x[3]; // 12 bytes, but 8-aligned under AddressSanitizer.
  90. // char *beg = (char*)&x[0];
  91. // char *end = beg + 12; // Not 8-aligned, but is the end of the buffer.
  92. void __sanitizer_annotate_contiguous_container(const void *beg,
  93. const void *end,
  94. const void *old_mid,
  95. const void *new_mid);
  96. // Returns true if the contiguous container [beg, end) is properly poisoned
  97. // (e.g. with __sanitizer_annotate_contiguous_container), i.e. if
  98. // - [beg, mid) is addressable,
  99. // - [mid, end) is unaddressable.
  100. // Full verification requires O(end-beg) time; this function tries to avoid
  101. // such complexity by touching only parts of the container around beg/mid/end.
  102. int __sanitizer_verify_contiguous_container(const void *beg, const void *mid,
  103. const void *end);
  104. // Print the stack trace leading to this call. Useful for debugging user code.
  105. void __sanitizer_print_stack_trace();
  106. #ifdef __cplusplus
  107. } // extern "C"
  108. #endif
  109. #endif // SANITIZER_COMMON_INTERFACE_DEFS_H