YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/debug/leak_annotations.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
#ifndef YB_UTIL_DEBUG_LEAK_ANNOTATIONS_H_
33
#define YB_UTIL_DEBUG_LEAK_ANNOTATIONS_H_
34
35
// API definitions from LLVM lsan_interface.h
36
37
extern "C" {
38
  // Allocations made between calls to __lsan_disable() and __lsan_enable() will
39
  // be treated as non-leaks. Disable/enable pairs may be nested.
40
  void __lsan_disable();
41
  void __lsan_enable();
42
  // The heap object into which p points will be treated as a non-leak.
43
  void __lsan_ignore_object(const void *p);
44
  // The user may optionally provide this function to disallow leak checking
45
  // for the program it is linked into (if the return value is non-zero). This
46
  // function must be defined as returning a constant value; any behavior beyond
47
  // that is unsupported.
48
  int __lsan_is_turned_off();
49
  // Calling this function makes LSan enter the leak checking phase immediately.
50
  // Use this if normal end-of-process leak checking happens too late (e.g. if
51
  // you have intentional memory leaks in your shutdown code). Calling this
52
  // function overrides end-of-process leak checking; it must be called at
53
  // most once per process. This function will terminate the process if there
54
  // are memory leaks and the exit_code flag is non-zero.
55
  void __lsan_do_leak_check();
56
}  // extern "C"
57
58
namespace yb {
59
namespace debug {
60
61
class ScopedLSANDisabler {
62
 public:
63
19.9k
  ScopedLSANDisabler() {
64
19.9k
#if defined(__has_feature)
65
#if __has_feature(address_sanitizer)
66
    __lsan_disable();
67
#endif
68
19.9k
#endif
69
19.9k
  }
70
71
19.9k
  ~ScopedLSANDisabler() {
72
19.9k
#if defined(__has_feature)
73
#if __has_feature(address_sanitizer)
74
    __lsan_enable();
75
#endif
76
19.9k
#endif
77
19.9k
  }
78
};
79
80
} // namespace debug
81
} // namespace yb
82
83
#endif // YB_UTIL_DEBUG_LEAK_ANNOTATIONS_H_