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