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