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