| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | // Wrappers around lsan_interface functions. |
| 16 | // When lsan is not linked in, these functions are not available, |
| 17 | // therefore Abseil code which depends on these functions is conditioned on the |
| 18 | // definition of LEAK_SANITIZER. |
| 19 | #include "absl/base/attributes.h" |
| 20 | #include "absl/debugging/leak_check.h" |
| 21 |
| 22 | #ifndef LEAK_SANITIZER |
| 23 |
| 24 | namespace absl { |
| 25 | ABSL_NAMESPACE_BEGIN |
| 26 | bool HaveLeakSanitizer() { return false; } |
| 27 | bool LeakCheckerIsActive() { return false; } |
| 28 | void DoIgnoreLeak(const void*) { } |
| 29 | void RegisterLivePointers(const void*, size_t) { } |
| 30 | void UnRegisterLivePointers(const void*, size_t) { } |
| 31 | LeakCheckDisabler::LeakCheckDisabler() { } |
| 32 | LeakCheckDisabler::~LeakCheckDisabler() { } |
| 33 | ABSL_NAMESPACE_END |
| 34 | } // namespace absl |
| 35 |
| 36 | #else |
| 37 |
| 38 | #include <sanitizer/lsan_interface.h> |
| 39 |
| 40 | #if ABSL_HAVE_ATTRIBUTE_WEAK |
| 41 | extern "C" ABSL_ATTRIBUTE_WEAK int __lsan_is_turned_off(); |
| 42 | #endif |
| 43 |
| 44 | namespace absl { |
| 45 | ABSL_NAMESPACE_BEGIN |
| 46 | bool HaveLeakSanitizer() { return true; } |
| 47 |
| 48 | #if ABSL_HAVE_ATTRIBUTE_WEAK |
| 49 | bool LeakCheckerIsActive() { |
| 50 | return !(&__lsan_is_turned_off && __lsan_is_turned_off()); |
| 51 | } |
| 52 | #else |
| 53 | bool LeakCheckerIsActive() { return true; } |
| 54 | #endif |
| 55 |
| 56 | bool FindAndReportLeaks() { return __lsan_do_recoverable_leak_check(); } |
| 57 | void DoIgnoreLeak(const void* ptr) { __lsan_ignore_object(ptr); } |
| 58 | void RegisterLivePointers(const void* ptr, size_t size) { |
| 59 | __lsan_register_root_region(ptr, size); |
| 60 | } |
| 61 | void UnRegisterLivePointers(const void* ptr, size_t size) { |
| 62 | __lsan_unregister_root_region(ptr, size); |
| 63 | } |
| 64 | LeakCheckDisabler::LeakCheckDisabler() { __lsan_disable(); } |
| 65 | LeakCheckDisabler::~LeakCheckDisabler() { __lsan_enable(); } |
| 66 | ABSL_NAMESPACE_END |
| 67 | } // namespace absl |
| 68 |
| 69 | #endif // LEAK_SANITIZER |
| 70 |