From 3a1720af1d7f43edc5b214cde0be11bfb94d077e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 23 Oct 2019 17:52:22 +0000 Subject: Vendor import of stripped compiler-rt trunk r375505, the last commit before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505 --- lib/stats/stats.cc | 136 --------------------------------------------- lib/stats/stats.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ lib/stats/stats_client.cc | 83 --------------------------- lib/stats/stats_client.cpp | 83 +++++++++++++++++++++++++++ 4 files changed, 219 insertions(+), 219 deletions(-) delete mode 100644 lib/stats/stats.cc create mode 100644 lib/stats/stats.cpp delete mode 100644 lib/stats/stats_client.cc create mode 100644 lib/stats/stats_client.cpp (limited to 'lib/stats') diff --git a/lib/stats/stats.cc b/lib/stats/stats.cc deleted file mode 100644 index 8d4a115d1aef..000000000000 --- a/lib/stats/stats.cc +++ /dev/null @@ -1,136 +0,0 @@ -//===-- stats.cc ----------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// Sanitizer statistics gathering. Manages statistics for a process and is -// responsible for writing the report file. -// -//===----------------------------------------------------------------------===// - -#include "sanitizer_common/sanitizer_common.h" -#include "sanitizer_common/sanitizer_file.h" -#include "sanitizer_common/sanitizer_internal_defs.h" -#if SANITIZER_POSIX -#include "sanitizer_common/sanitizer_posix.h" -#endif -#include "sanitizer_common/sanitizer_symbolizer.h" -#include "stats/stats.h" -#if SANITIZER_POSIX -#include -#endif - -using namespace __sanitizer; - -namespace { - -InternalMmapVectorNoCtor modules; -StaticSpinMutex modules_mutex; - -fd_t stats_fd; - -void WriteLE(fd_t fd, uptr val) { - char chars[sizeof(uptr)]; - for (unsigned i = 0; i != sizeof(uptr); ++i) { - chars[i] = val >> (i * 8); - } - WriteToFile(fd, chars, sizeof(uptr)); -} - -void OpenStatsFile(const char *path_env) { - InternalMmapVector path(kMaxPathLength); - SubstituteForFlagValue(path_env, path.data(), kMaxPathLength); - - error_t err; - stats_fd = OpenFile(path.data(), WrOnly, &err); - if (stats_fd == kInvalidFd) { - Report("stats: failed to open %s for writing (reason: %d)\n", path.data(), - err); - return; - } - char sizeof_uptr = sizeof(uptr); - WriteToFile(stats_fd, &sizeof_uptr, 1); -} - -void WriteModuleReport(StatModule **smodp) { - CHECK(smodp); - const char *path_env = GetEnv("SANITIZER_STATS_PATH"); - if (!path_env || stats_fd == kInvalidFd) - return; - if (!stats_fd) - OpenStatsFile(path_env); - const LoadedModule *mod = Symbolizer::GetOrInit()->FindModuleForAddress( - reinterpret_cast(smodp)); - WriteToFile(stats_fd, mod->full_name(), - internal_strlen(mod->full_name()) + 1); - for (StatModule *smod = *smodp; smod; smod = smod->next) { - for (u32 i = 0; i != smod->size; ++i) { - StatInfo *s = &smod->infos[i]; - if (!s->addr) - continue; - WriteLE(stats_fd, s->addr - mod->base_address()); - WriteLE(stats_fd, s->data); - } - } - WriteLE(stats_fd, 0); - WriteLE(stats_fd, 0); -} - -} // namespace - -extern "C" -SANITIZER_INTERFACE_ATTRIBUTE -unsigned __sanitizer_stats_register(StatModule **mod) { - SpinMutexLock l(&modules_mutex); - modules.push_back(mod); - return modules.size() - 1; -} - -extern "C" -SANITIZER_INTERFACE_ATTRIBUTE -void __sanitizer_stats_unregister(unsigned index) { - SpinMutexLock l(&modules_mutex); - WriteModuleReport(modules[index]); - modules[index] = 0; -} - -namespace { - -void WriteFullReport() { - SpinMutexLock l(&modules_mutex); - for (StatModule **mod : modules) { - if (!mod) - continue; - WriteModuleReport(mod); - } - if (stats_fd != 0 && stats_fd != kInvalidFd) { - CloseFile(stats_fd); - stats_fd = kInvalidFd; - } -} - -#if SANITIZER_POSIX -void USR2Handler(int sig) { - WriteFullReport(); -} -#endif - -struct WriteReportOnExitOrSignal { - WriteReportOnExitOrSignal() { -#if SANITIZER_POSIX - struct sigaction sigact; - internal_memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = USR2Handler; - internal_sigaction(SIGUSR2, &sigact, nullptr); -#endif - } - - ~WriteReportOnExitOrSignal() { - WriteFullReport(); - } -} wr; - -} // namespace diff --git a/lib/stats/stats.cpp b/lib/stats/stats.cpp new file mode 100644 index 000000000000..da254fdb5a52 --- /dev/null +++ b/lib/stats/stats.cpp @@ -0,0 +1,136 @@ +//===-- 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 +// +//===----------------------------------------------------------------------===// +// +// Sanitizer statistics gathering. Manages statistics for a process and is +// responsible for writing the report file. +// +//===----------------------------------------------------------------------===// + +#include "sanitizer_common/sanitizer_common.h" +#include "sanitizer_common/sanitizer_file.h" +#include "sanitizer_common/sanitizer_internal_defs.h" +#if SANITIZER_POSIX +#include "sanitizer_common/sanitizer_posix.h" +#endif +#include "sanitizer_common/sanitizer_symbolizer.h" +#include "stats/stats.h" +#if SANITIZER_POSIX +#include +#endif + +using namespace __sanitizer; + +namespace { + +InternalMmapVectorNoCtor modules; +StaticSpinMutex modules_mutex; + +fd_t stats_fd; + +void WriteLE(fd_t fd, uptr val) { + char chars[sizeof(uptr)]; + for (unsigned i = 0; i != sizeof(uptr); ++i) { + chars[i] = val >> (i * 8); + } + WriteToFile(fd, chars, sizeof(uptr)); +} + +void OpenStatsFile(const char *path_env) { + InternalMmapVector path(kMaxPathLength); + SubstituteForFlagValue(path_env, path.data(), kMaxPathLength); + + error_t err; + stats_fd = OpenFile(path.data(), WrOnly, &err); + if (stats_fd == kInvalidFd) { + Report("stats: failed to open %s for writing (reason: %d)\n", path.data(), + err); + return; + } + char sizeof_uptr = sizeof(uptr); + WriteToFile(stats_fd, &sizeof_uptr, 1); +} + +void WriteModuleReport(StatModule **smodp) { + CHECK(smodp); + const char *path_env = GetEnv("SANITIZER_STATS_PATH"); + if (!path_env || stats_fd == kInvalidFd) + return; + if (!stats_fd) + OpenStatsFile(path_env); + const LoadedModule *mod = Symbolizer::GetOrInit()->FindModuleForAddress( + reinterpret_cast(smodp)); + WriteToFile(stats_fd, mod->full_name(), + internal_strlen(mod->full_name()) + 1); + for (StatModule *smod = *smodp; smod; smod = smod->next) { + for (u32 i = 0; i != smod->size; ++i) { + StatInfo *s = &smod->infos[i]; + if (!s->addr) + continue; + WriteLE(stats_fd, s->addr - mod->base_address()); + WriteLE(stats_fd, s->data); + } + } + WriteLE(stats_fd, 0); + WriteLE(stats_fd, 0); +} + +} // namespace + +extern "C" +SANITIZER_INTERFACE_ATTRIBUTE +unsigned __sanitizer_stats_register(StatModule **mod) { + SpinMutexLock l(&modules_mutex); + modules.push_back(mod); + return modules.size() - 1; +} + +extern "C" +SANITIZER_INTERFACE_ATTRIBUTE +void __sanitizer_stats_unregister(unsigned index) { + SpinMutexLock l(&modules_mutex); + WriteModuleReport(modules[index]); + modules[index] = 0; +} + +namespace { + +void WriteFullReport() { + SpinMutexLock l(&modules_mutex); + for (StatModule **mod : modules) { + if (!mod) + continue; + WriteModuleReport(mod); + } + if (stats_fd != 0 && stats_fd != kInvalidFd) { + CloseFile(stats_fd); + stats_fd = kInvalidFd; + } +} + +#if SANITIZER_POSIX +void USR2Handler(int sig) { + WriteFullReport(); +} +#endif + +struct WriteReportOnExitOrSignal { + WriteReportOnExitOrSignal() { +#if SANITIZER_POSIX + struct sigaction sigact; + internal_memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = USR2Handler; + internal_sigaction(SIGUSR2, &sigact, nullptr); +#endif + } + + ~WriteReportOnExitOrSignal() { + WriteFullReport(); + } +} wr; + +} // namespace diff --git a/lib/stats/stats_client.cc b/lib/stats/stats_client.cc deleted file mode 100644 index 0790f57372f4..000000000000 --- a/lib/stats/stats_client.cc +++ /dev/null @@ -1,83 +0,0 @@ -//===-- stats_client.cc ---------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// Sanitizer statistics gathering. Manages statistics for a module (executable -// or DSO) and registers statistics with the process. -// -// This is linked into each individual modle and cannot directly use functions -// declared in sanitizer_common. -// -//===----------------------------------------------------------------------===// - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#else -#include -#endif -#include -#include - -#include "sanitizer_common/sanitizer_internal_defs.h" -#include "stats/stats.h" - -using namespace __sanitizer; - -namespace { - -void *LookupSymbolFromMain(const char *name) { -#ifdef _WIN32 - return reinterpret_cast(GetProcAddress(GetModuleHandle(0), name)); -#else - return dlsym(RTLD_DEFAULT, name); -#endif -} - -StatModule *list; - -struct RegisterSanStats { - unsigned module_id; - - RegisterSanStats() { - typedef unsigned (*reg_func_t)(StatModule **); - reg_func_t reg_func = reinterpret_cast( - LookupSymbolFromMain("__sanitizer_stats_register")); - if (reg_func) - module_id = reg_func(&list); - } - - ~RegisterSanStats() { - typedef void (*unreg_func_t)(unsigned); - unreg_func_t unreg_func = reinterpret_cast( - LookupSymbolFromMain("__sanitizer_stats_unregister")); - if (unreg_func) - unreg_func(module_id); - } -} reg; - -} - -extern "C" void __sanitizer_stat_init(StatModule *mod) { - mod->next = list; - list = mod; -} - -extern "C" void __sanitizer_stat_report(StatInfo *s) { - s->addr = GET_CALLER_PC(); -#if defined(_WIN64) && !defined(__clang__) - uptr old_data = InterlockedIncrement64(reinterpret_cast(&s->data)); -#elif defined(_WIN32) && !defined(__clang__) - uptr old_data = InterlockedIncrement(&s->data); -#else - uptr old_data = __sync_fetch_and_add(&s->data, 1); -#endif - - // Overflow check. - if (CountFromData(old_data + 1) == 0) - Trap(); -} diff --git a/lib/stats/stats_client.cpp b/lib/stats/stats_client.cpp new file mode 100644 index 000000000000..52eab8eea079 --- /dev/null +++ b/lib/stats/stats_client.cpp @@ -0,0 +1,83 @@ +//===-- stats_client.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 +// +//===----------------------------------------------------------------------===// +// +// Sanitizer statistics gathering. Manages statistics for a module (executable +// or DSO) and registers statistics with the process. +// +// This is linked into each individual modle and cannot directly use functions +// declared in sanitizer_common. +// +//===----------------------------------------------------------------------===// + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif +#include +#include + +#include "sanitizer_common/sanitizer_internal_defs.h" +#include "stats/stats.h" + +using namespace __sanitizer; + +namespace { + +void *LookupSymbolFromMain(const char *name) { +#ifdef _WIN32 + return reinterpret_cast(GetProcAddress(GetModuleHandle(0), name)); +#else + return dlsym(RTLD_DEFAULT, name); +#endif +} + +StatModule *list; + +struct RegisterSanStats { + unsigned module_id; + + RegisterSanStats() { + typedef unsigned (*reg_func_t)(StatModule **); + reg_func_t reg_func = reinterpret_cast( + LookupSymbolFromMain("__sanitizer_stats_register")); + if (reg_func) + module_id = reg_func(&list); + } + + ~RegisterSanStats() { + typedef void (*unreg_func_t)(unsigned); + unreg_func_t unreg_func = reinterpret_cast( + LookupSymbolFromMain("__sanitizer_stats_unregister")); + if (unreg_func) + unreg_func(module_id); + } +} reg; + +} + +extern "C" void __sanitizer_stat_init(StatModule *mod) { + mod->next = list; + list = mod; +} + +extern "C" void __sanitizer_stat_report(StatInfo *s) { + s->addr = GET_CALLER_PC(); +#if defined(_WIN64) && !defined(__clang__) + uptr old_data = InterlockedIncrement64(reinterpret_cast(&s->data)); +#elif defined(_WIN32) && !defined(__clang__) + uptr old_data = InterlockedIncrement(&s->data); +#else + uptr old_data = __sync_fetch_and_add(&s->data, 1); +#endif + + // Overflow check. + if (CountFromData(old_data + 1) == 0) + Trap(); +} -- cgit v1.2.3