lsan_interface.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //===-- sanitizer/lsan_interface.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 LeakSanitizer.
  9. //
  10. // Public interface header.
  11. //===----------------------------------------------------------------------===//
  12. #ifndef SANITIZER_LSAN_INTERFACE_H
  13. #define SANITIZER_LSAN_INTERFACE_H
  14. #include <sanitizer/common_interface_defs.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // Allocations made between calls to __lsan_disable() and __lsan_enable() will
  19. // be treated as non-leaks. Disable/enable pairs may be nested.
  20. void __lsan_disable();
  21. void __lsan_enable();
  22. // The heap object into which p points will be treated as a non-leak.
  23. void __lsan_ignore_object(const void *p);
  24. // Memory regions registered through this interface will be treated as sources
  25. // of live pointers during leak checking. Useful if you store pointers in
  26. // mapped memory.
  27. // Points of note:
  28. // - __lsan_unregister_root_region() must be called with the same pointer and
  29. // size that have earlier been passed to __lsan_register_root_region()
  30. // - LSan will skip any inaccessible memory when scanning a root region. E.g.,
  31. // if you map memory within a larger region that you have mprotect'ed, you can
  32. // register the entire large region.
  33. // - the implementation is not optimized for performance. This interface is
  34. // intended to be used for a small number of relatively static regions.
  35. void __lsan_register_root_region(const void *p, size_t size);
  36. void __lsan_unregister_root_region(const void *p, size_t size);
  37. // Calling this function makes LSan enter the leak checking phase immediately.
  38. // Use this if normal end-of-process leak checking happens too late (e.g. if
  39. // you have intentional memory leaks in your shutdown code). Calling this
  40. // function overrides end-of-process leak checking; it must be called at
  41. // most once per process. This function will terminate the process if there
  42. // are memory leaks and the exit_code flag is non-zero.
  43. void __lsan_do_leak_check();
  44. // The user may optionally provide this function to disallow leak checking
  45. // for the program it is linked into (if the return value is non-zero). This
  46. // function must be defined as returning a constant value; any behavior beyond
  47. // that is unsupported.
  48. int __lsan_is_turned_off();
  49. // This function may be optionally provided by the user and should return
  50. // a string containing LSan suppressions.
  51. const char *__lsan_default_suppressions();
  52. #ifdef __cplusplus
  53. } // extern "C"
  54. namespace __lsan {
  55. class ScopedDisabler {
  56. public:
  57. ScopedDisabler() { __lsan_disable(); }
  58. ~ScopedDisabler() { __lsan_enable(); }
  59. };
  60. } // namespace __lsan
  61. #endif
  62. #endif // SANITIZER_LSAN_INTERFACE_H