Path: blob/main/contrib/llvm-project/compiler-rt/include/sanitizer/lsan_interface.h
35235 views
//===-- sanitizer/lsan_interface.h ------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of LeakSanitizer.9//10// Public interface header.11//===----------------------------------------------------------------------===//12#ifndef SANITIZER_LSAN_INTERFACE_H13#define SANITIZER_LSAN_INTERFACE_H1415#include <sanitizer/common_interface_defs.h>1617#ifdef __cplusplus18extern "C" {19#endif20// Allocations made between calls to __lsan_disable() and __lsan_enable() will21// be treated as non-leaks. Disable/enable pairs may be nested.22void SANITIZER_CDECL __lsan_disable(void);23void SANITIZER_CDECL __lsan_enable(void);2425// The heap object into which p points will be treated as a non-leak.26void SANITIZER_CDECL __lsan_ignore_object(const void *p);2728// Memory regions registered through this interface will be treated as sources29// of live pointers during leak checking. Useful if you store pointers in30// mapped memory.31// Points of note:32// - __lsan_unregister_root_region() must be called with the same pointer and33// 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 can36// register the entire large region.37// - the implementation is not optimized for performance. This interface is38// intended to be used for a small number of relatively static regions.39void SANITIZER_CDECL __lsan_register_root_region(const void *p, size_t size);40void SANITIZER_CDECL __lsan_unregister_root_region(const void *p, size_t size);4142// Check for leaks now. This function behaves identically to the default43// end-of-process leak check. In particular, it will terminate the process if44// leaks are found and the exitcode runtime flag is non-zero.45// Subsequent calls to this function will have no effect and end-of-process46// leak check will not run. Effectively, end-of-process leak check is moved to47// the time of first invocation of this function.48// By calling this function early during process shutdown, you can instruct49// LSan to ignore shutdown-only leaks which happen later on.50void SANITIZER_CDECL __lsan_do_leak_check(void);5152// Check for leaks now. Returns zero if no leaks have been found or if leak53// detection is disabled, non-zero otherwise.54// This function may be called repeatedly, e.g. to periodically check a55// long-running process. It prints a leak report if appropriate, but does not56// terminate the process. It does not affect the behavior of57// __lsan_do_leak_check() or the end-of-process leak check, and is not58// affected by them.59int SANITIZER_CDECL __lsan_do_recoverable_leak_check(void);6061// The user may optionally provide this function to disallow leak checking62// for the program it is linked into (if the return value is non-zero). This63// function must be defined as returning a constant value; any behavior beyond64// that is unsupported.65// To avoid dead stripping, you may need to define this function with66// __attribute__((used))67int SANITIZER_CDECL __lsan_is_turned_off(void);6869// This function may be optionally provided by user and should return70// a string containing LSan runtime options. See lsan_flags.inc for details.71const char *SANITIZER_CDECL __lsan_default_options(void);7273// This function may be optionally provided by the user and should return74// a string containing LSan suppressions.75const char *SANITIZER_CDECL __lsan_default_suppressions(void);76#ifdef __cplusplus77} // extern "C"7879namespace __lsan {80class ScopedDisabler {81public:82ScopedDisabler() { __lsan_disable(); }83~ScopedDisabler() { __lsan_enable(); }84};85} // namespace __lsan86#endif8788#endif // SANITIZER_LSAN_INTERFACE_H899091