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