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