| 1 | // Copyright 2017 The Abseil Authors. | 
|---|
| 2 | // | 
|---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|---|
| 4 | // you may not use this file except in compliance with the License. | 
|---|
| 5 | // You may obtain a copy of the License at | 
|---|
| 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/debugging/leak_check.h" | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef LEAK_SANITIZER | 
|---|
| 22 |  | 
|---|
| 23 | namespace absl { | 
|---|
| 24 | bool HaveLeakSanitizer() { return false; } | 
|---|
| 25 | void DoIgnoreLeak(const void*) { } | 
|---|
| 26 | void RegisterLivePointers(const void*, size_t) { } | 
|---|
| 27 | void UnRegisterLivePointers(const void*, size_t) { } | 
|---|
| 28 | LeakCheckDisabler::LeakCheckDisabler() { } | 
|---|
| 29 | LeakCheckDisabler::~LeakCheckDisabler() { } | 
|---|
| 30 | }  // namespace absl | 
|---|
| 31 |  | 
|---|
| 32 | #else | 
|---|
| 33 |  | 
|---|
| 34 | #include <sanitizer/lsan_interface.h> | 
|---|
| 35 |  | 
|---|
| 36 | namespace absl { | 
|---|
| 37 | bool HaveLeakSanitizer() { return true; } | 
|---|
| 38 | void DoIgnoreLeak(const void* ptr) { __lsan_ignore_object(ptr); } | 
|---|
| 39 | void RegisterLivePointers(const void* ptr, size_t size) { | 
|---|
| 40 | __lsan_register_root_region(ptr, size); | 
|---|
| 41 | } | 
|---|
| 42 | void UnRegisterLivePointers(const void* ptr, size_t size) { | 
|---|
| 43 | __lsan_unregister_root_region(ptr, size); | 
|---|
| 44 | } | 
|---|
| 45 | LeakCheckDisabler::LeakCheckDisabler() { __lsan_disable(); } | 
|---|
| 46 | LeakCheckDisabler::~LeakCheckDisabler() { __lsan_enable(); } | 
|---|
| 47 | }  // namespace absl | 
|---|
| 48 |  | 
|---|
| 49 | #endif  // LEAK_SANITIZER | 
|---|
| 50 |  | 
|---|