2013-06-03 19:21:34 +08:00
|
|
|
//===-- sanitizer/lsan_interface.h ------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-06-03 19:21:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of LeakSanitizer.
|
|
|
|
//
|
|
|
|
// Public interface header.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_LSAN_INTERFACE_H
|
|
|
|
#define SANITIZER_LSAN_INTERFACE_H
|
|
|
|
|
|
|
|
#include <sanitizer/common_interface_defs.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
// Allocations made between calls to __lsan_disable() and __lsan_enable() will
|
2013-07-18 22:06:07 +08:00
|
|
|
// be treated as non-leaks. Disable/enable pairs may be nested.
|
2017-12-22 04:51:16 +08:00
|
|
|
void __lsan_disable(void);
|
|
|
|
void __lsan_enable(void);
|
2013-12-17 19:11:23 +08:00
|
|
|
|
2013-06-06 22:17:56 +08:00
|
|
|
// The heap object into which p points will be treated as a non-leak.
|
|
|
|
void __lsan_ignore_object(const void *p);
|
2013-12-17 19:11:23 +08:00
|
|
|
|
|
|
|
// Memory regions registered through this interface will be treated as sources
|
|
|
|
// of live pointers during leak checking. Useful if you store pointers in
|
|
|
|
// mapped memory.
|
|
|
|
// Points of note:
|
|
|
|
// - __lsan_unregister_root_region() must be called with the same pointer and
|
|
|
|
// size that have earlier been passed to __lsan_register_root_region()
|
|
|
|
// - LSan will skip any inaccessible memory when scanning a root region. E.g.,
|
|
|
|
// if you map memory within a larger region that you have mprotect'ed, you can
|
|
|
|
// register the entire large region.
|
|
|
|
// - the implementation is not optimized for performance. This interface is
|
|
|
|
// intended to be used for a small number of relatively static regions.
|
|
|
|
void __lsan_register_root_region(const void *p, size_t size);
|
|
|
|
void __lsan_unregister_root_region(const void *p, size_t size);
|
|
|
|
|
2015-04-25 00:53:15 +08:00
|
|
|
// Check for leaks now. This function behaves identically to the default
|
|
|
|
// end-of-process leak check. In particular, it will terminate the process if
|
2015-08-22 04:49:37 +08:00
|
|
|
// leaks are found and the exitcode runtime flag is non-zero.
|
2015-04-25 00:53:15 +08:00
|
|
|
// Subsequent calls to this function will have no effect and end-of-process
|
|
|
|
// leak check will not run. Effectively, end-of-process leak check is moved to
|
|
|
|
// the time of first invocation of this function.
|
|
|
|
// By calling this function early during process shutdown, you can instruct
|
|
|
|
// LSan to ignore shutdown-only leaks which happen later on.
|
2017-12-22 04:51:16 +08:00
|
|
|
void __lsan_do_leak_check(void);
|
2014-01-14 01:26:57 +08:00
|
|
|
|
2015-04-25 00:53:15 +08:00
|
|
|
// Check for leaks now. Returns zero if no leaks have been found or if leak
|
|
|
|
// detection is disabled, non-zero otherwise.
|
|
|
|
// This function may be called repeatedly, e.g. to periodically check a
|
|
|
|
// long-running process. It prints a leak report if appropriate, but does not
|
|
|
|
// terminate the process. It does not affect the behavior of
|
|
|
|
// __lsan_do_leak_check() or the end-of-process leak check, and is not
|
|
|
|
// affected by them.
|
2017-12-22 04:51:16 +08:00
|
|
|
int __lsan_do_recoverable_leak_check(void);
|
2015-04-25 00:53:15 +08:00
|
|
|
|
2013-06-27 17:35:50 +08:00
|
|
|
// The user may optionally provide this function to disallow leak checking
|
2013-07-18 22:06:07 +08:00
|
|
|
// for the program it is linked into (if the return value is non-zero). This
|
|
|
|
// function must be defined as returning a constant value; any behavior beyond
|
|
|
|
// that is unsupported.
|
2017-09-09 03:43:53 +08:00
|
|
|
// To avoid dead stripping, you may need to define this function with
|
|
|
|
// __attribute__((used))
|
2017-12-22 04:51:16 +08:00
|
|
|
int __lsan_is_turned_off(void);
|
2013-12-17 19:11:23 +08:00
|
|
|
|
2017-09-23 07:49:49 +08:00
|
|
|
// This function may be optionally provided by user and should return
|
|
|
|
// a string containing LSan runtime options. See lsan_flags.inc for details.
|
2017-12-22 04:51:16 +08:00
|
|
|
const char *__lsan_default_options(void);
|
2017-09-23 07:49:49 +08:00
|
|
|
|
2014-01-14 01:26:57 +08:00
|
|
|
// This function may be optionally provided by the user and should return
|
|
|
|
// a string containing LSan suppressions.
|
2017-12-22 04:51:16 +08:00
|
|
|
const char *__lsan_default_suppressions(void);
|
2013-06-03 19:21:34 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
namespace __lsan {
|
|
|
|
class ScopedDisabler {
|
|
|
|
public:
|
|
|
|
ScopedDisabler() { __lsan_disable(); }
|
|
|
|
~ScopedDisabler() { __lsan_enable(); }
|
|
|
|
};
|
|
|
|
} // namespace __lsan
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // SANITIZER_LSAN_INTERFACE_H
|