90 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file is a part of LeakSanitizer.10//11// Public interface header.12//===----------------------------------------------------------------------===//13#ifndef SANITIZER_LSAN_INTERFACE_H14#define SANITIZER_LSAN_INTERFACE_H15 16#include <sanitizer/common_interface_defs.h>17 18#ifdef __cplusplus19extern "C" {20#endif21// Allocations made between calls to __lsan_disable() and __lsan_enable() will22// be treated as non-leaks. Disable/enable pairs may be nested.23void SANITIZER_CDECL __lsan_disable(void);24void SANITIZER_CDECL __lsan_enable(void);25 26// The heap object into which p points will be treated as a non-leak.27void SANITIZER_CDECL __lsan_ignore_object(const void *p);28 29// Memory regions registered through this interface will be treated as sources30// of live pointers during leak checking. Useful if you store pointers in31// mapped memory.32// Points of note:33// - __lsan_unregister_root_region() must be called with the same pointer and34// 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 can37// register the entire large region.38// - the implementation is not optimized for performance. This interface is39// intended to be used for a small number of relatively static regions.40void SANITIZER_CDECL __lsan_register_root_region(const void *p, size_t size);41void SANITIZER_CDECL __lsan_unregister_root_region(const void *p, size_t size);42 43// Check for leaks now. This function behaves identically to the default44// end-of-process leak check. In particular, it will terminate the process if45// leaks are found and the exitcode runtime flag is non-zero.46// Subsequent calls to this function will have no effect and end-of-process47// leak check will not run. Effectively, end-of-process leak check is moved to48// the time of first invocation of this function.49// By calling this function early during process shutdown, you can instruct50// LSan to ignore shutdown-only leaks which happen later on.51void SANITIZER_CDECL __lsan_do_leak_check(void);52 53// Check for leaks now. Returns zero if no leaks have been found or if leak54// detection is disabled, non-zero otherwise.55// This function may be called repeatedly, e.g. to periodically check a56// long-running process. It prints a leak report if appropriate, but does not57// terminate the process. It does not affect the behavior of58// __lsan_do_leak_check() or the end-of-process leak check, and is not59// affected by them.60int SANITIZER_CDECL __lsan_do_recoverable_leak_check(void);61 62// The user may optionally provide this function to disallow leak checking63// for the program it is linked into (if the return value is non-zero). This64// function must be defined as returning a constant value; any behavior beyond65// that is unsupported.66// To avoid dead stripping, you may need to define this function with67// __attribute__((used))68int SANITIZER_CDECL __lsan_is_turned_off(void);69 70// This function may be optionally provided by user and should return71// a string containing LSan runtime options. See lsan_flags.inc for details.72const char *SANITIZER_CDECL __lsan_default_options(void);73 74// This function may be optionally provided by the user and should return75// a string containing LSan suppressions.76const char *SANITIZER_CDECL __lsan_default_suppressions(void);77#ifdef __cplusplus78} // extern "C"79 80namespace __lsan {81class ScopedDisabler {82public:83 ScopedDisabler() { __lsan_disable(); }84 ~ScopedDisabler() { __lsan_enable(); }85};86} // namespace __lsan87#endif88 89#endif // SANITIZER_LSAN_INTERFACE_H90