xref: /freebsd/contrib/llvm-project/compiler-rt/include/sanitizer/lsan_interface.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- sanitizer/lsan_interface.h ------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is a part of LeakSanitizer.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric // Public interface header.
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric #ifndef SANITIZER_LSAN_INTERFACE_H
140b57cec5SDimitry Andric #define SANITIZER_LSAN_INTERFACE_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include <sanitizer/common_interface_defs.h>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #ifdef __cplusplus
190b57cec5SDimitry Andric extern "C" {
200b57cec5SDimitry Andric #endif
210b57cec5SDimitry Andric // Allocations made between calls to __lsan_disable() and __lsan_enable() will
220b57cec5SDimitry Andric // be treated as non-leaks. Disable/enable pairs may be nested.
23*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_disable(void);
24*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_enable(void);
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric // The heap object into which p points will be treated as a non-leak.
27*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_ignore_object(const void *p);
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric // Memory regions registered through this interface will be treated as sources
300b57cec5SDimitry Andric // of live pointers during leak checking. Useful if you store pointers in
310b57cec5SDimitry Andric // mapped memory.
320b57cec5SDimitry Andric // Points of note:
330b57cec5SDimitry Andric // - __lsan_unregister_root_region() must be called with the same pointer and
340b57cec5SDimitry Andric // size that have earlier been passed to __lsan_register_root_region()
350b57cec5SDimitry Andric // - LSan will skip any inaccessible memory when scanning a root region. E.g.,
360b57cec5SDimitry Andric // if you map memory within a larger region that you have mprotect'ed, you can
370b57cec5SDimitry Andric // register the entire large region.
380b57cec5SDimitry Andric // - the implementation is not optimized for performance. This interface is
390b57cec5SDimitry Andric // intended to be used for a small number of relatively static regions.
40*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_register_root_region(const void *p, size_t size);
41*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_unregister_root_region(const void *p, size_t size);
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric // Check for leaks now. This function behaves identically to the default
440b57cec5SDimitry Andric // end-of-process leak check. In particular, it will terminate the process if
450b57cec5SDimitry Andric // leaks are found and the exitcode runtime flag is non-zero.
460b57cec5SDimitry Andric // Subsequent calls to this function will have no effect and end-of-process
470b57cec5SDimitry Andric // leak check will not run. Effectively, end-of-process leak check is moved to
480b57cec5SDimitry Andric // the time of first invocation of this function.
490b57cec5SDimitry Andric // By calling this function early during process shutdown, you can instruct
500b57cec5SDimitry Andric // LSan to ignore shutdown-only leaks which happen later on.
51*5f757f3fSDimitry Andric void SANITIZER_CDECL __lsan_do_leak_check(void);
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric // Check for leaks now. Returns zero if no leaks have been found or if leak
540b57cec5SDimitry Andric // detection is disabled, non-zero otherwise.
550b57cec5SDimitry Andric // This function may be called repeatedly, e.g. to periodically check a
560b57cec5SDimitry Andric // long-running process. It prints a leak report if appropriate, but does not
570b57cec5SDimitry Andric // terminate the process. It does not affect the behavior of
580b57cec5SDimitry Andric // __lsan_do_leak_check() or the end-of-process leak check, and is not
590b57cec5SDimitry Andric // affected by them.
60*5f757f3fSDimitry Andric int SANITIZER_CDECL __lsan_do_recoverable_leak_check(void);
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric // The user may optionally provide this function to disallow leak checking
630b57cec5SDimitry Andric // for the program it is linked into (if the return value is non-zero). This
640b57cec5SDimitry Andric // function must be defined as returning a constant value; any behavior beyond
650b57cec5SDimitry Andric // that is unsupported.
660b57cec5SDimitry Andric // To avoid dead stripping, you may need to define this function with
670b57cec5SDimitry Andric // __attribute__((used))
68*5f757f3fSDimitry Andric int SANITIZER_CDECL __lsan_is_turned_off(void);
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric // This function may be optionally provided by user and should return
710b57cec5SDimitry Andric // a string containing LSan runtime options. See lsan_flags.inc for details.
72*5f757f3fSDimitry Andric const char *SANITIZER_CDECL __lsan_default_options(void);
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric // This function may be optionally provided by the user and should return
750b57cec5SDimitry Andric // a string containing LSan suppressions.
76*5f757f3fSDimitry Andric const char *SANITIZER_CDECL __lsan_default_suppressions(void);
770b57cec5SDimitry Andric #ifdef __cplusplus
780b57cec5SDimitry Andric } // extern "C"
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric namespace __lsan {
810b57cec5SDimitry Andric class ScopedDisabler {
820b57cec5SDimitry Andric public:
830b57cec5SDimitry Andric   ScopedDisabler() { __lsan_disable(); }
840b57cec5SDimitry Andric   ~ScopedDisabler() { __lsan_enable(); }
850b57cec5SDimitry Andric };
860b57cec5SDimitry Andric } // namespace __lsan
870b57cec5SDimitry Andric #endif
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric #endif // SANITIZER_LSAN_INTERFACE_H
90