1 //=-- lsan_common.cc ------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of LeakSanitizer.
11 // Implementation of common leak checking functionality.
13 //===----------------------------------------------------------------------===//
15 #include "lsan_common.h"
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_flags.h"
19 #include "sanitizer_common/sanitizer_flag_parser.h"
20 #include "sanitizer_common/sanitizer_placement_new.h"
21 #include "sanitizer_common/sanitizer_procmaps.h"
22 #include "sanitizer_common/sanitizer_stackdepot.h"
23 #include "sanitizer_common/sanitizer_stacktrace.h"
24 #include "sanitizer_common/sanitizer_suppressions.h"
25 #include "sanitizer_common/sanitizer_report_decorator.h"
27 #if CAN_SANITIZE_LEAKS
30 // This mutex is used to prevent races between DoLeakCheck and IgnoreObject, and
31 // also to protect the global list of root regions.
32 BlockingMutex global_mutex(LINKER_INITIALIZED);
34 THREADLOCAL int disable_counter;
35 bool DisabledInThisThread() { return disable_counter > 0; }
39 void Flags::SetDefaults() {
40 #define LSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
41 #include "lsan_flags.inc"
45 void RegisterLsanFlags(FlagParser *parser, Flags *f) {
46 #define LSAN_FLAG(Type, Name, DefaultValue, Description) \
47 RegisterFlag(parser, #Name, Description, &f->Name);
48 #include "lsan_flags.inc"
52 #define LOG_POINTERS(...) \
54 if (flags()->log_pointers) Report(__VA_ARGS__); \
57 #define LOG_THREADS(...) \
59 if (flags()->log_threads) Report(__VA_ARGS__); \
62 ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
63 static SuppressionContext *suppression_ctx = nullptr;
64 static const char kSuppressionLeak[] = "leak";
65 static const char *kSuppressionTypes[] = { kSuppressionLeak };
67 void InitializeSuppressions() {
68 CHECK_EQ(nullptr, suppression_ctx);
69 suppression_ctx = new (suppression_placeholder) // NOLINT
70 SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
71 suppression_ctx->ParseFromFile(flags()->suppressions);
72 if (&__lsan_default_suppressions)
73 suppression_ctx->Parse(__lsan_default_suppressions());
76 static SuppressionContext *GetSuppressionContext() {
77 CHECK(suppression_ctx);
78 return suppression_ctx;
86 InternalMmapVector<RootRegion> *root_regions;
88 void InitializeRootRegions() {
90 ALIGNED(64) static char placeholder[sizeof(InternalMmapVector<RootRegion>)];
91 root_regions = new(placeholder) InternalMmapVector<RootRegion>(1);
94 void InitCommonLsan() {
95 InitializeRootRegions();
96 if (common_flags()->detect_leaks) {
97 // Initialization which can fail or print warnings should only be done if
98 // LSan is actually enabled.
99 InitializeSuppressions();
100 InitializePlatformSpecificModules();
104 class Decorator: public __sanitizer::SanitizerCommonDecorator {
106 Decorator() : SanitizerCommonDecorator() { }
107 const char *Error() { return Red(); }
108 const char *Leak() { return Blue(); }
109 const char *End() { return Default(); }
112 static inline bool CanBeAHeapPointer(uptr p) {
113 // Since our heap is located in mmap-ed memory, we can assume a sensible lower
114 // bound on heap addresses.
115 const uptr kMinAddress = 4 * 4096;
116 if (p < kMinAddress) return false;
117 #if defined(__x86_64__)
118 // Accept only canonical form user-space addresses.
119 return ((p >> 47) == 0);
120 #elif defined(__mips64)
121 return ((p >> 40) == 0);
127 // Scans the memory range, looking for byte patterns that point into allocator
128 // chunks. Marks those chunks with |tag| and adds them to |frontier|.
129 // There are two usage modes for this function: finding reachable chunks
130 // (|tag| = kReachable) and finding indirectly leaked chunks
131 // (|tag| = kIndirectlyLeaked). In the second case, there's no flood fill,
132 // so |frontier| = 0.
133 void ScanRangeForPointers(uptr begin, uptr end,
135 const char *region_type, ChunkTag tag) {
136 CHECK(tag == kReachable || tag == kIndirectlyLeaked);
137 const uptr alignment = flags()->pointer_alignment();
138 LOG_POINTERS("Scanning %s range %p-%p.\n", region_type, begin, end);
141 pp = pp + alignment - pp % alignment;
142 for (; pp + sizeof(void *) <= end; pp += alignment) { // NOLINT
143 void *p = *reinterpret_cast<void **>(pp);
144 if (!CanBeAHeapPointer(reinterpret_cast<uptr>(p))) continue;
145 uptr chunk = PointsIntoChunk(p);
146 if (!chunk) continue;
147 // Pointers to self don't count. This matters when tag == kIndirectlyLeaked.
148 if (chunk == begin) continue;
149 LsanMetadata m(chunk);
150 if (m.tag() == kReachable || m.tag() == kIgnored) continue;
152 // Do this check relatively late so we can log only the interesting cases.
153 if (!flags()->use_poisoned && WordIsPoisoned(pp)) {
155 "%p is poisoned: ignoring %p pointing into chunk %p-%p of size "
157 pp, p, chunk, chunk + m.requested_size(), m.requested_size());
162 LOG_POINTERS("%p: found %p pointing into chunk %p-%p of size %zu.\n", pp, p,
163 chunk, chunk + m.requested_size(), m.requested_size());
165 frontier->push_back(chunk);
169 void ForEachExtraStackRangeCb(uptr begin, uptr end, void* arg) {
170 Frontier *frontier = reinterpret_cast<Frontier *>(arg);
171 ScanRangeForPointers(begin, end, frontier, "FAKE STACK", kReachable);
174 // Scans thread data (stacks and TLS) for heap pointers.
175 static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
176 Frontier *frontier) {
177 InternalScopedBuffer<uptr> registers(SuspendedThreadsList::RegisterCount());
178 uptr registers_begin = reinterpret_cast<uptr>(registers.data());
179 uptr registers_end = registers_begin + registers.size();
180 for (uptr i = 0; i < suspended_threads.thread_count(); i++) {
181 uptr os_id = static_cast<uptr>(suspended_threads.GetThreadID(i));
182 LOG_THREADS("Processing thread %d.\n", os_id);
183 uptr stack_begin, stack_end, tls_begin, tls_end, cache_begin, cache_end;
184 bool thread_found = GetThreadRangesLocked(os_id, &stack_begin, &stack_end,
185 &tls_begin, &tls_end,
186 &cache_begin, &cache_end);
188 // If a thread can't be found in the thread registry, it's probably in the
189 // process of destruction. Log this event and move on.
190 LOG_THREADS("Thread %d not found in registry.\n", os_id);
194 bool have_registers =
195 (suspended_threads.GetRegistersAndSP(i, registers.data(), &sp) == 0);
196 if (!have_registers) {
197 Report("Unable to get registers from thread %d.\n");
198 // If unable to get SP, consider the entire stack to be reachable.
202 if (flags()->use_registers && have_registers)
203 ScanRangeForPointers(registers_begin, registers_end, frontier,
204 "REGISTERS", kReachable);
206 if (flags()->use_stacks) {
207 LOG_THREADS("Stack at %p-%p (SP = %p).\n", stack_begin, stack_end, sp);
208 if (sp < stack_begin || sp >= stack_end) {
209 // SP is outside the recorded stack range (e.g. the thread is running a
210 // signal handler on alternate stack). Again, consider the entire stack
211 // range to be reachable.
212 LOG_THREADS("WARNING: stack pointer not in stack range.\n");
214 // Shrink the stack range to ignore out-of-scope values.
217 ScanRangeForPointers(stack_begin, stack_end, frontier, "STACK",
219 ForEachExtraStackRange(os_id, ForEachExtraStackRangeCb, frontier);
222 if (flags()->use_tls) {
223 LOG_THREADS("TLS at %p-%p.\n", tls_begin, tls_end);
224 if (cache_begin == cache_end) {
225 ScanRangeForPointers(tls_begin, tls_end, frontier, "TLS", kReachable);
227 // Because LSan should not be loaded with dlopen(), we can assume
228 // that allocator cache will be part of static TLS image.
229 CHECK_LE(tls_begin, cache_begin);
230 CHECK_GE(tls_end, cache_end);
231 if (tls_begin < cache_begin)
232 ScanRangeForPointers(tls_begin, cache_begin, frontier, "TLS",
234 if (tls_end > cache_end)
235 ScanRangeForPointers(cache_end, tls_end, frontier, "TLS", kReachable);
241 static void ProcessRootRegion(Frontier *frontier, uptr root_begin,
243 MemoryMappingLayout proc_maps(/*cache_enabled*/true);
244 uptr begin, end, prot;
245 while (proc_maps.Next(&begin, &end,
246 /*offset*/ 0, /*filename*/ 0, /*filename_size*/ 0,
248 uptr intersection_begin = Max(root_begin, begin);
249 uptr intersection_end = Min(end, root_end);
250 if (intersection_begin >= intersection_end) continue;
251 bool is_readable = prot & MemoryMappingLayout::kProtectionRead;
252 LOG_POINTERS("Root region %p-%p intersects with mapped region %p-%p (%s)\n",
253 root_begin, root_end, begin, end,
254 is_readable ? "readable" : "unreadable");
256 ScanRangeForPointers(intersection_begin, intersection_end, frontier,
261 // Scans root regions for heap pointers.
262 static void ProcessRootRegions(Frontier *frontier) {
263 if (!flags()->use_root_regions) return;
265 for (uptr i = 0; i < root_regions->size(); i++) {
266 RootRegion region = (*root_regions)[i];
267 uptr begin_addr = reinterpret_cast<uptr>(region.begin);
268 ProcessRootRegion(frontier, begin_addr, begin_addr + region.size);
272 static void FloodFillTag(Frontier *frontier, ChunkTag tag) {
273 while (frontier->size()) {
274 uptr next_chunk = frontier->back();
275 frontier->pop_back();
276 LsanMetadata m(next_chunk);
277 ScanRangeForPointers(next_chunk, next_chunk + m.requested_size(), frontier,
282 // ForEachChunk callback. If the chunk is marked as leaked, marks all chunks
283 // which are reachable from it as indirectly leaked.
284 static void MarkIndirectlyLeakedCb(uptr chunk, void *arg) {
285 chunk = GetUserBegin(chunk);
286 LsanMetadata m(chunk);
287 if (m.allocated() && m.tag() != kReachable) {
288 ScanRangeForPointers(chunk, chunk + m.requested_size(),
289 /* frontier */ nullptr, "HEAP", kIndirectlyLeaked);
293 // ForEachChunk callback. If chunk is marked as ignored, adds its address to
295 static void CollectIgnoredCb(uptr chunk, void *arg) {
297 chunk = GetUserBegin(chunk);
298 LsanMetadata m(chunk);
299 if (m.allocated() && m.tag() == kIgnored) {
300 LOG_POINTERS("Ignored: chunk %p-%p of size %zu.\n",
301 chunk, chunk + m.requested_size(), m.requested_size());
302 reinterpret_cast<Frontier *>(arg)->push_back(chunk);
306 // Sets the appropriate tag on each chunk.
307 static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads) {
308 // Holds the flood fill frontier.
309 Frontier frontier(1);
311 ForEachChunk(CollectIgnoredCb, &frontier);
312 ProcessGlobalRegions(&frontier);
313 ProcessThreads(suspended_threads, &frontier);
314 ProcessRootRegions(&frontier);
315 FloodFillTag(&frontier, kReachable);
317 // The check here is relatively expensive, so we do this in a separate flood
318 // fill. That way we can skip the check for chunks that are reachable
320 LOG_POINTERS("Processing platform-specific allocations.\n");
321 CHECK_EQ(0, frontier.size());
322 ProcessPlatformSpecificAllocations(&frontier);
323 FloodFillTag(&frontier, kReachable);
325 // Iterate over leaked chunks and mark those that are reachable from other
327 LOG_POINTERS("Scanning leaked chunks.\n");
328 ForEachChunk(MarkIndirectlyLeakedCb, nullptr);
331 // ForEachChunk callback. Resets the tags to pre-leak-check state.
332 static void ResetTagsCb(uptr chunk, void *arg) {
334 chunk = GetUserBegin(chunk);
335 LsanMetadata m(chunk);
336 if (m.allocated() && m.tag() != kIgnored)
337 m.set_tag(kDirectlyLeaked);
340 static void PrintStackTraceById(u32 stack_trace_id) {
341 CHECK(stack_trace_id);
342 StackDepotGet(stack_trace_id).Print();
345 // ForEachChunk callback. Aggregates information about unreachable chunks into
347 static void CollectLeaksCb(uptr chunk, void *arg) {
349 LeakReport *leak_report = reinterpret_cast<LeakReport *>(arg);
350 chunk = GetUserBegin(chunk);
351 LsanMetadata m(chunk);
352 if (!m.allocated()) return;
353 if (m.tag() == kDirectlyLeaked || m.tag() == kIndirectlyLeaked) {
354 u32 resolution = flags()->resolution;
355 u32 stack_trace_id = 0;
356 if (resolution > 0) {
357 StackTrace stack = StackDepotGet(m.stack_trace_id());
358 stack.size = Min(stack.size, resolution);
359 stack_trace_id = StackDepotPut(stack);
361 stack_trace_id = m.stack_trace_id();
363 leak_report->AddLeakedChunk(chunk, stack_trace_id, m.requested_size(),
368 static void PrintMatchedSuppressions() {
369 InternalMmapVector<Suppression *> matched(1);
370 GetSuppressionContext()->GetMatched(&matched);
373 const char *line = "-----------------------------------------------------";
374 Printf("%s\n", line);
375 Printf("Suppressions used:\n");
376 Printf(" count bytes template\n");
377 for (uptr i = 0; i < matched.size(); i++)
378 Printf("%7zu %10zu %s\n", static_cast<uptr>(matched[i]->hit_count),
379 matched[i]->weight, matched[i]->templ);
380 Printf("%s\n\n", line);
383 struct CheckForLeaksParam {
385 LeakReport leak_report;
388 static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
390 CheckForLeaksParam *param = reinterpret_cast<CheckForLeaksParam *>(arg);
392 CHECK(!param->success);
393 ClassifyAllChunks(suspended_threads);
394 ForEachChunk(CollectLeaksCb, ¶m->leak_report);
395 // Clean up for subsequent leak checks. This assumes we did not overwrite any
397 ForEachChunk(ResetTagsCb, nullptr);
398 param->success = true;
401 static bool CheckForLeaks() {
402 if (&__lsan_is_turned_off && __lsan_is_turned_off())
404 EnsureMainThreadIDIsCorrect();
405 CheckForLeaksParam param;
406 param.success = false;
407 LockThreadRegistry();
409 DoStopTheWorld(CheckForLeaksCallback, ¶m);
411 UnlockThreadRegistry();
413 if (!param.success) {
414 Report("LeakSanitizer has encountered a fatal error.\n");
417 param.leak_report.ApplySuppressions();
418 uptr unsuppressed_count = param.leak_report.UnsuppressedLeakCount();
419 if (unsuppressed_count > 0) {
422 "================================================================="
424 Printf("%s", d.Error());
425 Report("ERROR: LeakSanitizer: detected memory leaks\n");
426 Printf("%s", d.End());
427 param.leak_report.ReportTopLeaks(flags()->max_leaks);
429 if (common_flags()->print_suppressions)
430 PrintMatchedSuppressions();
431 if (unsuppressed_count > 0) {
432 param.leak_report.PrintSummary();
439 BlockingMutexLock l(&global_mutex);
440 static bool already_done;
441 if (already_done) return;
443 bool have_leaks = CheckForLeaks();
447 if (flags()->exitcode) {
448 if (common_flags()->coverage)
449 __sanitizer_cov_dump();
450 internal__exit(flags()->exitcode);
454 static int DoRecoverableLeakCheck() {
455 BlockingMutexLock l(&global_mutex);
456 bool have_leaks = CheckForLeaks();
457 return have_leaks ? 1 : 0;
460 static Suppression *GetSuppressionForAddr(uptr addr) {
461 Suppression *s = nullptr;
463 // Suppress by module name.
464 SuppressionContext *suppressions = GetSuppressionContext();
465 if (const char *module_name =
466 Symbolizer::GetOrInit()->GetModuleNameForPc(addr))
467 if (suppressions->Match(module_name, kSuppressionLeak, &s))
470 // Suppress by file or function name.
471 SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(addr);
472 for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
473 if (suppressions->Match(cur->info.function, kSuppressionLeak, &s) ||
474 suppressions->Match(cur->info.file, kSuppressionLeak, &s)) {
482 static Suppression *GetSuppressionForStack(u32 stack_trace_id) {
483 StackTrace stack = StackDepotGet(stack_trace_id);
484 for (uptr i = 0; i < stack.size; i++) {
485 Suppression *s = GetSuppressionForAddr(
486 StackTrace::GetPreviousInstructionPc(stack.trace[i]));
492 ///// LeakReport implementation. /////
494 // A hard limit on the number of distinct leaks, to avoid quadratic complexity
495 // in LeakReport::AddLeakedChunk(). We don't expect to ever see this many leaks
496 // in real-world applications.
497 // FIXME: Get rid of this limit by changing the implementation of LeakReport to
499 const uptr kMaxLeaksConsidered = 5000;
501 void LeakReport::AddLeakedChunk(uptr chunk, u32 stack_trace_id,
502 uptr leaked_size, ChunkTag tag) {
503 CHECK(tag == kDirectlyLeaked || tag == kIndirectlyLeaked);
504 bool is_directly_leaked = (tag == kDirectlyLeaked);
506 for (i = 0; i < leaks_.size(); i++) {
507 if (leaks_[i].stack_trace_id == stack_trace_id &&
508 leaks_[i].is_directly_leaked == is_directly_leaked) {
509 leaks_[i].hit_count++;
510 leaks_[i].total_size += leaked_size;
514 if (i == leaks_.size()) {
515 if (leaks_.size() == kMaxLeaksConsidered) return;
516 Leak leak = { next_id_++, /* hit_count */ 1, leaked_size, stack_trace_id,
517 is_directly_leaked, /* is_suppressed */ false };
518 leaks_.push_back(leak);
520 if (flags()->report_objects) {
521 LeakedObject obj = {leaks_[i].id, chunk, leaked_size};
522 leaked_objects_.push_back(obj);
526 static bool LeakComparator(const Leak &leak1, const Leak &leak2) {
527 if (leak1.is_directly_leaked == leak2.is_directly_leaked)
528 return leak1.total_size > leak2.total_size;
530 return leak1.is_directly_leaked;
533 void LeakReport::ReportTopLeaks(uptr num_leaks_to_report) {
534 CHECK(leaks_.size() <= kMaxLeaksConsidered);
536 if (leaks_.size() == kMaxLeaksConsidered)
537 Printf("Too many leaks! Only the first %zu leaks encountered will be "
539 kMaxLeaksConsidered);
541 uptr unsuppressed_count = UnsuppressedLeakCount();
542 if (num_leaks_to_report > 0 && num_leaks_to_report < unsuppressed_count)
543 Printf("The %zu top leak(s):\n", num_leaks_to_report);
544 InternalSort(&leaks_, leaks_.size(), LeakComparator);
545 uptr leaks_reported = 0;
546 for (uptr i = 0; i < leaks_.size(); i++) {
547 if (leaks_[i].is_suppressed) continue;
548 PrintReportForLeak(i);
550 if (leaks_reported == num_leaks_to_report) break;
552 if (leaks_reported < unsuppressed_count) {
553 uptr remaining = unsuppressed_count - leaks_reported;
554 Printf("Omitting %zu more leak(s).\n", remaining);
558 void LeakReport::PrintReportForLeak(uptr index) {
560 Printf("%s", d.Leak());
561 Printf("%s leak of %zu byte(s) in %zu object(s) allocated from:\n",
562 leaks_[index].is_directly_leaked ? "Direct" : "Indirect",
563 leaks_[index].total_size, leaks_[index].hit_count);
564 Printf("%s", d.End());
566 PrintStackTraceById(leaks_[index].stack_trace_id);
568 if (flags()->report_objects) {
569 Printf("Objects leaked above:\n");
570 PrintLeakedObjectsForLeak(index);
575 void LeakReport::PrintLeakedObjectsForLeak(uptr index) {
576 u32 leak_id = leaks_[index].id;
577 for (uptr j = 0; j < leaked_objects_.size(); j++) {
578 if (leaked_objects_[j].leak_id == leak_id)
579 Printf("%p (%zu bytes)\n", leaked_objects_[j].addr,
580 leaked_objects_[j].size);
584 void LeakReport::PrintSummary() {
585 CHECK(leaks_.size() <= kMaxLeaksConsidered);
586 uptr bytes = 0, allocations = 0;
587 for (uptr i = 0; i < leaks_.size(); i++) {
588 if (leaks_[i].is_suppressed) continue;
589 bytes += leaks_[i].total_size;
590 allocations += leaks_[i].hit_count;
592 InternalScopedString summary(kMaxSummaryLength);
593 summary.append("%zu byte(s) leaked in %zu allocation(s).", bytes,
595 ReportErrorSummary(summary.data());
598 void LeakReport::ApplySuppressions() {
599 for (uptr i = 0; i < leaks_.size(); i++) {
600 Suppression *s = GetSuppressionForStack(leaks_[i].stack_trace_id);
602 s->weight += leaks_[i].total_size;
603 s->hit_count += leaks_[i].hit_count;
604 leaks_[i].is_suppressed = true;
609 uptr LeakReport::UnsuppressedLeakCount() {
611 for (uptr i = 0; i < leaks_.size(); i++)
612 if (!leaks_[i].is_suppressed) result++;
616 } // namespace __lsan
617 #endif // CAN_SANITIZE_LEAKS
619 using namespace __lsan; // NOLINT
622 SANITIZER_INTERFACE_ATTRIBUTE
623 void __lsan_ignore_object(const void *p) {
624 #if CAN_SANITIZE_LEAKS
625 if (!common_flags()->detect_leaks)
627 // Cannot use PointsIntoChunk or LsanMetadata here, since the allocator is not
629 BlockingMutexLock l(&global_mutex);
630 IgnoreObjectResult res = IgnoreObjectLocked(p);
631 if (res == kIgnoreObjectInvalid)
632 VReport(1, "__lsan_ignore_object(): no heap object found at %p", p);
633 if (res == kIgnoreObjectAlreadyIgnored)
634 VReport(1, "__lsan_ignore_object(): "
635 "heap object at %p is already being ignored\n", p);
636 if (res == kIgnoreObjectSuccess)
637 VReport(1, "__lsan_ignore_object(): ignoring heap object at %p\n", p);
638 #endif // CAN_SANITIZE_LEAKS
641 SANITIZER_INTERFACE_ATTRIBUTE
642 void __lsan_register_root_region(const void *begin, uptr size) {
643 #if CAN_SANITIZE_LEAKS
644 BlockingMutexLock l(&global_mutex);
646 RootRegion region = {begin, size};
647 root_regions->push_back(region);
648 VReport(1, "Registered root region at %p of size %llu\n", begin, size);
649 #endif // CAN_SANITIZE_LEAKS
652 SANITIZER_INTERFACE_ATTRIBUTE
653 void __lsan_unregister_root_region(const void *begin, uptr size) {
654 #if CAN_SANITIZE_LEAKS
655 BlockingMutexLock l(&global_mutex);
657 bool removed = false;
658 for (uptr i = 0; i < root_regions->size(); i++) {
659 RootRegion region = (*root_regions)[i];
660 if (region.begin == begin && region.size == size) {
662 uptr last_index = root_regions->size() - 1;
663 (*root_regions)[i] = (*root_regions)[last_index];
664 root_regions->pop_back();
665 VReport(1, "Unregistered root region at %p of size %llu\n", begin, size);
671 "__lsan_unregister_root_region(): region at %p of size %llu has not "
672 "been registered.\n",
676 #endif // CAN_SANITIZE_LEAKS
679 SANITIZER_INTERFACE_ATTRIBUTE
680 void __lsan_disable() {
681 #if CAN_SANITIZE_LEAKS
682 __lsan::disable_counter++;
686 SANITIZER_INTERFACE_ATTRIBUTE
687 void __lsan_enable() {
688 #if CAN_SANITIZE_LEAKS
689 if (!__lsan::disable_counter && common_flags()->detect_leaks) {
690 Report("Unmatched call to __lsan_enable().\n");
693 __lsan::disable_counter--;
697 SANITIZER_INTERFACE_ATTRIBUTE
698 void __lsan_do_leak_check() {
699 #if CAN_SANITIZE_LEAKS
700 if (common_flags()->detect_leaks)
701 __lsan::DoLeakCheck();
702 #endif // CAN_SANITIZE_LEAKS
705 SANITIZER_INTERFACE_ATTRIBUTE
706 int __lsan_do_recoverable_leak_check() {
707 #if CAN_SANITIZE_LEAKS
708 if (common_flags()->detect_leaks)
709 return __lsan::DoRecoverableLeakCheck();
710 #endif // CAN_SANITIZE_LEAKS
714 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
715 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
716 int __lsan_is_turned_off() {