lsan_interface.h 3.8 KB

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