sanitizers/
lsan.rs

1/// LeakSanitizer interface.
2///
3/// For more information about LeakSanitizer, see
4/// https://clang.llvm.org/docs/LeakSanitizer.html.
5use crate::ffi::lsan::*;
6
7use std::os::raw::c_void;
8
9/// Disables leak detection.
10pub fn disable() {
11    unsafe {
12        __lsan_disable();
13    }
14}
15
16/// Enables leak detection.
17pub fn enable() {
18    unsafe {
19        __lsan_enable();
20    }
21}
22
23/// The heap object into which p points will be treated as a non-leak.
24pub fn ignore_object(p: *const c_void) {
25    unsafe {
26        __lsan_ignore_object(p);
27    }
28}
29
30/// Memory regions registered through this interface will be treated as sources
31/// of live pointers during leak checking.
32pub fn register_root_region(p: *const c_void, size: usize) {
33    unsafe {
34        __lsan_register_root_region(p, size);
35    }
36}
37
38/// Unregisters a root region previously registered.
39pub fn unregister_root_region(p: *const c_void, size: usize) {
40    unsafe {
41        __lsan_unregister_root_region(p, size);
42    }
43}
44
45/// Check for leaks now. This function behaves identically to the default
46/// end-of-process leak check.
47pub fn do_leak_check() {
48    unsafe {
49        __lsan_do_leak_check();
50    }
51}
52
53/// Check for leaks now and return whether leaks were found.
54pub fn do_recoverable_leak_check() -> bool {
55    unsafe { __lsan_do_recoverable_leak_check() != 0 }
56}