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