lsan_interface.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //===-- sanitizer/lsan_interface.h ------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file is a part of LeakSanitizer.
  11. //
  12. // Public interface header.
  13. //===----------------------------------------------------------------------===//
  14. #ifndef SANITIZER_LSAN_INTERFACE_H
  15. #define SANITIZER_LSAN_INTERFACE_H
  16. #include <sanitizer/common_interface_defs.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. // Allocations made between calls to __lsan_disable() and __lsan_enable() will
  21. // be treated as non-leaks. Disable/enable pairs may be nested.
  22. void __lsan_disable(void);
  23. void __lsan_enable(void);
  24. // The heap object into which p points will be treated as a non-leak.
  25. void __lsan_ignore_object(const void *p);
  26. // Memory regions registered through this interface will be treated as sources
  27. // of live pointers during leak checking. Useful if you store pointers in
  28. // mapped memory.
  29. // Points of note:
  30. // - __lsan_unregister_root_region() must be called with the same pointer and
  31. // size that have earlier been passed to __lsan_register_root_region()
  32. // - LSan will skip any inaccessible memory when scanning a root region. E.g.,
  33. // if you map memory within a larger region that you have mprotect'ed, you can
  34. // register the entire large region.
  35. // - the implementation is not optimized for performance. This interface is
  36. // intended to be used for a small number of relatively static regions.
  37. void __lsan_register_root_region(const void *p, size_t size);
  38. void __lsan_unregister_root_region(const void *p, size_t size);
  39. // Check for leaks now. This function behaves identically to the default
  40. // end-of-process leak check. In particular, it will terminate the process if
  41. // leaks are found and the exitcode runtime flag is non-zero.
  42. // Subsequent calls to this function will have no effect and end-of-process
  43. // leak check will not run. Effectively, end-of-process leak check is moved to
  44. // the time of first invocation of this function.
  45. // By calling this function early during process shutdown, you can instruct
  46. // LSan to ignore shutdown-only leaks which happen later on.
  47. void __lsan_do_leak_check(void);
  48. // Check for leaks now. Returns zero if no leaks have been found or if leak
  49. // detection is disabled, non-zero otherwise.
  50. // This function may be called repeatedly, e.g. to periodically check a
  51. // long-running process. It prints a leak report if appropriate, but does not
  52. // terminate the process. It does not affect the behavior of
  53. // __lsan_do_leak_check() or the end-of-process leak check, and is not
  54. // affected by them.
  55. int __lsan_do_recoverable_leak_check(void);
  56. // The user may optionally provide this function to disallow leak checking
  57. // for the program it is linked into (if the return value is non-zero). This
  58. // function must be defined as returning a constant value; any behavior beyond
  59. // that is unsupported.
  60. // To avoid dead stripping, you may need to define this function with
  61. // __attribute__((used))
  62. int __lsan_is_turned_off(void);
  63. // This function may be optionally provided by user and should return
  64. // a string containing LSan runtime options. See lsan_flags.inc for details.
  65. const char *__lsan_default_options(void);
  66. // This function may be optionally provided by the user and should return
  67. // a string containing LSan suppressions.
  68. const char *__lsan_default_suppressions(void);
  69. #ifdef __cplusplus
  70. } // extern "C"
  71. namespace __lsan {
  72. class ScopedDisabler {
  73. public:
  74. ScopedDisabler() { __lsan_disable(); }
  75. ~ScopedDisabler() { __lsan_enable(); }
  76. };
  77. } // namespace __lsan
  78. #endif
  79. #endif // SANITIZER_LSAN_INTERFACE_H