003 File Manager
Current Path:
/usr/src/contrib/llvm-project/compiler-rt/lib/asan
usr
/
src
/
contrib
/
llvm-project
/
compiler-rt
/
lib
/
asan
/
📁
..
📄
README.txt
(924 B)
📄
asan.syms.extra
(39 B)
📄
asan_activation.cpp
(4.55 KB)
📄
asan_activation.h
(736 B)
📄
asan_activation_flags.inc
(1.42 KB)
📄
asan_allocator.cpp
(40.63 KB)
📄
asan_allocator.h
(8.05 KB)
📄
asan_blacklist.txt
(513 B)
📄
asan_debugging.cpp
(4.7 KB)
📄
asan_descriptions.cpp
(16.44 KB)
📄
asan_descriptions.h
(7.59 KB)
📄
asan_errors.cpp
(21.78 KB)
📄
asan_errors.h
(14.75 KB)
📄
asan_fake_stack.cpp
(10.82 KB)
📄
asan_fake_stack.h
(6.89 KB)
📄
asan_flags.cpp
(7.32 KB)
📄
asan_flags.h
(1.45 KB)
📄
asan_flags.inc
(7.92 KB)
📄
asan_fuchsia.cpp
(8.18 KB)
📄
asan_globals.cpp
(16.98 KB)
📄
asan_globals_win.cpp
(2.03 KB)
📄
asan_init_version.h
(1.88 KB)
📄
asan_interceptors.cpp
(23.89 KB)
📄
asan_interceptors.h
(4.86 KB)
📄
asan_interceptors_memintrinsics.cpp
(1.52 KB)
📄
asan_interceptors_memintrinsics.h
(8.12 KB)
📄
asan_interceptors_vfork.S
(526 B)
📄
asan_interface.inc
(7.25 KB)
📄
asan_interface_internal.h
(10.88 KB)
📄
asan_internal.h
(5.95 KB)
📄
asan_linux.cpp
(7.45 KB)
📄
asan_lock.h
(0 B)
📄
asan_mac.cpp
(11.64 KB)
📄
asan_malloc_linux.cpp
(9.8 KB)
📄
asan_malloc_local.h
(1.92 KB)
📄
asan_malloc_mac.cpp
(3.83 KB)
📄
asan_malloc_win.cpp
(19.55 KB)
📄
asan_mapping.h
(14.72 KB)
📄
asan_mapping_myriad.h
(2.11 KB)
📄
asan_mapping_sparc64.h
(2.95 KB)
📄
asan_memory_profile.cpp
(4.12 KB)
📄
asan_new_delete.cpp
(8.16 KB)
📄
asan_poisoning.cpp
(16 KB)
📄
asan_poisoning.h
(3.85 KB)
📄
asan_posix.cpp
(4.12 KB)
📄
asan_preinit.cpp
(1 KB)
📄
asan_premap_shadow.cpp
(2.7 KB)
📄
asan_premap_shadow.h
(913 B)
📄
asan_report.cpp
(20.2 KB)
📄
asan_report.h
(4.59 KB)
📄
asan_rtems.cpp
(8.9 KB)
📄
asan_rtl.cpp
(22.99 KB)
📄
asan_scariness_score.h
(2.25 KB)
📄
asan_shadow_setup.cpp
(6.2 KB)
📄
asan_stack.cpp
(2.28 KB)
📄
asan_stack.h
(3.29 KB)
📄
asan_stats.cpp
(5.62 KB)
📄
asan_stats.h
(2.05 KB)
📄
asan_suppressions.cpp
(3.62 KB)
📄
asan_suppressions.h
(1.01 KB)
📄
asan_thread.cpp
(18.01 KB)
📄
asan_thread.h
(5.56 KB)
📄
asan_win.cpp
(13.74 KB)
📄
asan_win_dll_thunk.cpp
(5.12 KB)
📄
asan_win_dynamic_runtime_thunk.cpp
(5.4 KB)
📄
asan_win_weak_interception.cpp
(1.14 KB)
📄
weak_symbols.txt
(268 B)
Editing: asan_stats.cpp
//===-- asan_stats.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file is a part of AddressSanitizer, an address sanity checker. // // Code related to statistics collected by AddressSanitizer. //===----------------------------------------------------------------------===// #include "asan_interceptors.h" #include "asan_internal.h" #include "asan_stats.h" #include "asan_thread.h" #include "sanitizer_common/sanitizer_allocator_interface.h" #include "sanitizer_common/sanitizer_mutex.h" #include "sanitizer_common/sanitizer_stackdepot.h" namespace __asan { AsanStats::AsanStats() { Clear(); } void AsanStats::Clear() { CHECK(REAL(memset)); REAL(memset)(this, 0, sizeof(AsanStats)); } static void PrintMallocStatsArray(const char *prefix, uptr (&array)[kNumberOfSizeClasses]) { Printf("%s", prefix); for (uptr i = 0; i < kNumberOfSizeClasses; i++) { if (!array[i]) continue; Printf("%zu:%zu; ", i, array[i]); } Printf("\n"); } void AsanStats::Print() { Printf("Stats: %zuM malloced (%zuM for red zones) by %zu calls\n", malloced>>20, malloced_redzones>>20, mallocs); Printf("Stats: %zuM realloced by %zu calls\n", realloced>>20, reallocs); Printf("Stats: %zuM freed by %zu calls\n", freed>>20, frees); Printf("Stats: %zuM really freed by %zu calls\n", really_freed>>20, real_frees); Printf("Stats: %zuM (%zuM-%zuM) mmaped; %zu maps, %zu unmaps\n", (mmaped-munmaped)>>20, mmaped>>20, munmaped>>20, mmaps, munmaps); PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size); Printf("Stats: malloc large: %zu\n", malloc_large); } void AsanStats::MergeFrom(const AsanStats *stats) { uptr *dst_ptr = reinterpret_cast<uptr*>(this); const uptr *src_ptr = reinterpret_cast<const uptr*>(stats); uptr num_fields = sizeof(*this) / sizeof(uptr); for (uptr i = 0; i < num_fields; i++) dst_ptr[i] += src_ptr[i]; } static BlockingMutex print_lock(LINKER_INITIALIZED); static AsanStats unknown_thread_stats(LINKER_INITIALIZED); static AsanStats dead_threads_stats(LINKER_INITIALIZED); static BlockingMutex dead_threads_stats_lock(LINKER_INITIALIZED); // Required for malloc_zone_statistics() on OS X. This can't be stored in // per-thread AsanStats. static uptr max_malloced_memory; static void MergeThreadStats(ThreadContextBase *tctx_base, void *arg) { AsanStats *accumulated_stats = reinterpret_cast<AsanStats*>(arg); AsanThreadContext *tctx = static_cast<AsanThreadContext*>(tctx_base); if (AsanThread *t = tctx->thread) accumulated_stats->MergeFrom(&t->stats()); } static void GetAccumulatedStats(AsanStats *stats) { stats->Clear(); { ThreadRegistryLock l(&asanThreadRegistry()); asanThreadRegistry() .RunCallbackForEachThreadLocked(MergeThreadStats, stats); } stats->MergeFrom(&unknown_thread_stats); { BlockingMutexLock lock(&dead_threads_stats_lock); stats->MergeFrom(&dead_threads_stats); } // This is not very accurate: we may miss allocation peaks that happen // between two updates of accumulated_stats_. For more accurate bookkeeping // the maximum should be updated on every malloc(), which is unacceptable. if (max_malloced_memory < stats->malloced) { max_malloced_memory = stats->malloced; } } void FlushToDeadThreadStats(AsanStats *stats) { BlockingMutexLock lock(&dead_threads_stats_lock); dead_threads_stats.MergeFrom(stats); stats->Clear(); } void FillMallocStatistics(AsanMallocStats *malloc_stats) { AsanStats stats; GetAccumulatedStats(&stats); malloc_stats->blocks_in_use = stats.mallocs; malloc_stats->size_in_use = stats.malloced; malloc_stats->max_size_in_use = max_malloced_memory; malloc_stats->size_allocated = stats.mmaped; } AsanStats &GetCurrentThreadStats() { AsanThread *t = GetCurrentThread(); return (t) ? t->stats() : unknown_thread_stats; } static void PrintAccumulatedStats() { AsanStats stats; GetAccumulatedStats(&stats); // Use lock to keep reports from mixing up. BlockingMutexLock lock(&print_lock); stats.Print(); StackDepotStats *stack_depot_stats = StackDepotGetStats(); Printf("Stats: StackDepot: %zd ids; %zdM allocated\n", stack_depot_stats->n_uniq_ids, stack_depot_stats->allocated >> 20); PrintInternalAllocatorStats(); } } // namespace __asan // ---------------------- Interface ---------------- {{{1 using namespace __asan; uptr __sanitizer_get_current_allocated_bytes() { AsanStats stats; GetAccumulatedStats(&stats); uptr malloced = stats.malloced; uptr freed = stats.freed; // Return sane value if malloced < freed due to racy // way we update accumulated stats. return (malloced > freed) ? malloced - freed : 1; } uptr __sanitizer_get_heap_size() { AsanStats stats; GetAccumulatedStats(&stats); return stats.mmaped - stats.munmaped; } uptr __sanitizer_get_free_bytes() { AsanStats stats; GetAccumulatedStats(&stats); uptr total_free = stats.mmaped - stats.munmaped + stats.really_freed; uptr total_used = stats.malloced + stats.malloced_redzones; // Return sane value if total_free < total_used due to racy // way we update accumulated stats. return (total_free > total_used) ? total_free - total_used : 1; } uptr __sanitizer_get_unmapped_bytes() { return 0; } void __asan_print_accumulated_stats() { PrintAccumulatedStats(); }
Upload File
Create Folder