[compiler-rt] r367562 - compiler-rt: Rename .cc file in lib/msan to .cpp

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 07:08:18 PDT 2019


Author: nico
Date: Thu Aug  1 07:08:18 2019
New Revision: 367562

URL: http://llvm.org/viewvc/llvm-project?rev=367562&view=rev
Log:
compiler-rt: Rename .cc file in lib/msan to .cpp

Like r367463, but for msan.

Added:
    compiler-rt/trunk/lib/msan/msan.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan_allocator.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_allocator.cc
    compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc
    compiler-rt/trunk/lib/msan/msan_interceptors.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/msan/msan_linux.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_linux.cc
    compiler-rt/trunk/lib/msan/msan_new_delete.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_new_delete.cc
    compiler-rt/trunk/lib/msan/msan_poisoning.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_poisoning.cc
    compiler-rt/trunk/lib/msan/msan_report.cpp
      - copied, changed from r367561, compiler-rt/trunk/lib/msan/msan_report.cc
    compiler-rt/trunk/lib/msan/msan_thread.cpp
      - copied unchanged from r367561, compiler-rt/trunk/lib/msan/msan_thread.cc
Removed:
    compiler-rt/trunk/lib/msan/msan.cc
    compiler-rt/trunk/lib/msan/msan_allocator.cc
    compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc
    compiler-rt/trunk/lib/msan/msan_interceptors.cc
    compiler-rt/trunk/lib/msan/msan_linux.cc
    compiler-rt/trunk/lib/msan/msan_new_delete.cc
    compiler-rt/trunk/lib/msan/msan_poisoning.cc
    compiler-rt/trunk/lib/msan/msan_report.cc
    compiler-rt/trunk/lib/msan/msan_thread.cc
Modified:
    compiler-rt/trunk/lib/msan/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh
    compiler-rt/trunk/test/msan/chained_origin_memcpy.cc
    compiler-rt/trunk/test/msan/msan_copy_shadow.cc

Modified: compiler-rt/trunk/lib/msan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/CMakeLists.txt?rev=367562&r1=367561&r2=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msan/CMakeLists.txt Thu Aug  1 07:08:18 2019
@@ -2,18 +2,19 @@ include_directories(..)
 
 # Runtime library sources and build flags.
 set(MSAN_RTL_SOURCES
-  msan.cc
-  msan_allocator.cc
-  msan_chained_origin_depot.cc
-  msan_interceptors.cc
-  msan_linux.cc
-  msan_report.cc
-  msan_thread.cc
-  msan_poisoning.cc
+  msan.cpp
+  msan_allocator.cpp
+  msan_chained_origin_depot.cpp
+  msan_interceptors.cpp
+  msan_linux.cpp
+  msan_report.cpp
+  msan_thread.cpp
+  msan_poisoning.cpp
   )
 
 set(MSAN_RTL_CXX_SOURCES
-  msan_new_delete.cc)
+  msan_new_delete.cpp
+  )
 
 set(MSAN_RTL_HEADERS
   msan.h

Removed: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc (removed)
@@ -1,675 +0,0 @@
-//===-- msan.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// MemorySanitizer runtime.
-//===----------------------------------------------------------------------===//
-
-#include "msan.h"
-#include "msan_chained_origin_depot.h"
-#include "msan_origin.h"
-#include "msan_report.h"
-#include "msan_thread.h"
-#include "msan_poisoning.h"
-#include "sanitizer_common/sanitizer_atomic.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_flag_parser.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_procmaps.h"
-#include "sanitizer_common/sanitizer_stacktrace.h"
-#include "sanitizer_common/sanitizer_symbolizer.h"
-#include "sanitizer_common/sanitizer_stackdepot.h"
-#include "ubsan/ubsan_flags.h"
-#include "ubsan/ubsan_init.h"
-
-// ACHTUNG! No system header includes in this file.
-
-using namespace __sanitizer;
-
-// Globals.
-static THREADLOCAL int msan_expect_umr = 0;
-static THREADLOCAL int msan_expected_umr_found = 0;
-
-// Function argument shadow. Each argument starts at the next available 8-byte
-// aligned address.
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u64 __msan_param_tls[kMsanParamTlsSize / sizeof(u64)];
-
-// Function argument origin. Each argument starts at the same offset as the
-// corresponding shadow in (__msan_param_tls). Slightly weird, but changing this
-// would break compatibility with older prebuilt binaries.
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u32 __msan_param_origin_tls[kMsanParamTlsSize / sizeof(u32)];
-
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u64 __msan_retval_tls[kMsanRetvalTlsSize / sizeof(u64)];
-
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u32 __msan_retval_origin_tls;
-
-SANITIZER_INTERFACE_ATTRIBUTE
-ALIGNED(16) THREADLOCAL u64 __msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
-
-SANITIZER_INTERFACE_ATTRIBUTE
-ALIGNED(16)
-THREADLOCAL u32 __msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];
-
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u64 __msan_va_arg_overflow_size_tls;
-
-SANITIZER_INTERFACE_ATTRIBUTE
-THREADLOCAL u32 __msan_origin_tls;
-
-static THREADLOCAL int is_in_symbolizer;
-
-extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_track_origins;
-
-int __msan_get_track_origins() {
-  return &__msan_track_origins ? __msan_track_origins : 0;
-}
-
-extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_keep_going;
-
-namespace __msan {
-
-void EnterSymbolizer() { ++is_in_symbolizer; }
-void ExitSymbolizer()  { --is_in_symbolizer; }
-bool IsInSymbolizer() { return is_in_symbolizer; }
-
-static Flags msan_flags;
-
-Flags *flags() {
-  return &msan_flags;
-}
-
-int msan_inited = 0;
-bool msan_init_is_running;
-
-int msan_report_count = 0;
-
-// Array of stack origins.
-// FIXME: make it resizable.
-static const uptr kNumStackOriginDescrs = 1024 * 1024;
-static const char *StackOriginDescr[kNumStackOriginDescrs];
-static uptr StackOriginPC[kNumStackOriginDescrs];
-static atomic_uint32_t NumStackOriginDescrs;
-
-void Flags::SetDefaults() {
-#define MSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
-#include "msan_flags.inc"
-#undef MSAN_FLAG
-}
-
-// keep_going is an old name for halt_on_error,
-// and it has inverse meaning.
-class FlagHandlerKeepGoing : public FlagHandlerBase {
-  bool *halt_on_error_;
-
- public:
-  explicit FlagHandlerKeepGoing(bool *halt_on_error)
-      : halt_on_error_(halt_on_error) {}
-  bool Parse(const char *value) final {
-    bool tmp;
-    FlagHandler<bool> h(&tmp);
-    if (!h.Parse(value)) return false;
-    *halt_on_error_ = !tmp;
-    return true;
-  }
-};
-
-static void RegisterMsanFlags(FlagParser *parser, Flags *f) {
-#define MSAN_FLAG(Type, Name, DefaultValue, Description) \
-  RegisterFlag(parser, #Name, Description, &f->Name);
-#include "msan_flags.inc"
-#undef MSAN_FLAG
-
-  FlagHandlerKeepGoing *fh_keep_going = new (FlagParser::Alloc)  // NOLINT
-      FlagHandlerKeepGoing(&f->halt_on_error);
-  parser->RegisterHandler("keep_going", fh_keep_going,
-                          "deprecated, use halt_on_error");
-}
-
-static void InitializeFlags() {
-  SetCommonFlagsDefaults();
-  {
-    CommonFlags cf;
-    cf.CopyFrom(*common_flags());
-    cf.external_symbolizer_path = GetEnv("MSAN_SYMBOLIZER_PATH");
-    cf.malloc_context_size = 20;
-    cf.handle_ioctl = true;
-    // FIXME: test and enable.
-    cf.check_printf = false;
-    cf.intercept_tls_get_addr = true;
-    cf.exitcode = 77;
-    OverrideCommonFlags(cf);
-  }
-
-  Flags *f = flags();
-  f->SetDefaults();
-
-  FlagParser parser;
-  RegisterMsanFlags(&parser, f);
-  RegisterCommonFlags(&parser);
-
-#if MSAN_CONTAINS_UBSAN
-  __ubsan::Flags *uf = __ubsan::flags();
-  uf->SetDefaults();
-
-  FlagParser ubsan_parser;
-  __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
-  RegisterCommonFlags(&ubsan_parser);
-#endif
-
-  // Override from user-specified string.
-  if (__msan_default_options)
-    parser.ParseString(__msan_default_options());
-#if MSAN_CONTAINS_UBSAN
-  const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
-  ubsan_parser.ParseString(ubsan_default_options);
-#endif
-
-  parser.ParseStringFromEnv("MSAN_OPTIONS");
-#if MSAN_CONTAINS_UBSAN
-  ubsan_parser.ParseStringFromEnv("UBSAN_OPTIONS");
-#endif
-
-  InitializeCommonFlags();
-
-  if (Verbosity()) ReportUnrecognizedFlags();
-
-  if (common_flags()->help) parser.PrintFlagDescriptions();
-
-  // Check if deprecated exit_code MSan flag is set.
-  if (f->exit_code != -1) {
-    if (Verbosity())
-      Printf("MSAN_OPTIONS=exit_code is deprecated! "
-             "Please use MSAN_OPTIONS=exitcode instead.\n");
-    CommonFlags cf;
-    cf.CopyFrom(*common_flags());
-    cf.exitcode = f->exit_code;
-    OverrideCommonFlags(cf);
-  }
-
-  // Check flag values:
-  if (f->origin_history_size < 0 ||
-      f->origin_history_size > Origin::kMaxDepth) {
-    Printf(
-        "Origin history size invalid: %d. Must be 0 (unlimited) or in [1, %d] "
-        "range.\n",
-        f->origin_history_size, Origin::kMaxDepth);
-    Die();
-  }
-  // Limiting to kStackDepotMaxUseCount / 2 to avoid overflow in
-  // StackDepotHandle::inc_use_count_unsafe.
-  if (f->origin_history_per_stack_limit < 0 ||
-      f->origin_history_per_stack_limit > kStackDepotMaxUseCount / 2) {
-    Printf(
-        "Origin per-stack limit invalid: %d. Must be 0 (unlimited) or in [1, "
-        "%d] range.\n",
-        f->origin_history_per_stack_limit, kStackDepotMaxUseCount / 2);
-    Die();
-  }
-  if (f->store_context_size < 1) f->store_context_size = 1;
-}
-
-void PrintWarning(uptr pc, uptr bp) {
-  PrintWarningWithOrigin(pc, bp, __msan_origin_tls);
-}
-
-void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) {
-  if (msan_expect_umr) {
-    // Printf("Expected UMR\n");
-    __msan_origin_tls = origin;
-    msan_expected_umr_found = 1;
-    return;
-  }
-
-  ++msan_report_count;
-
-  GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
-
-  u32 report_origin =
-    (__msan_get_track_origins() && Origin::isValidId(origin)) ? origin : 0;
-  ReportUMR(&stack, report_origin);
-
-  if (__msan_get_track_origins() && !Origin::isValidId(origin)) {
-    Printf(
-        "  ORIGIN: invalid (%x). Might be a bug in MemorySanitizer origin "
-        "tracking.\n    This could still be a bug in your code, too!\n",
-        origin);
-  }
-}
-
-void UnpoisonParam(uptr n) {
-  internal_memset(__msan_param_tls, 0, n * sizeof(*__msan_param_tls));
-}
-
-// Backup MSan runtime TLS state.
-// Implementation must be async-signal-safe.
-// Instances of this class may live on the signal handler stack, and data size
-// may be an issue.
-void ScopedThreadLocalStateBackup::Backup() {
-  va_arg_overflow_size_tls = __msan_va_arg_overflow_size_tls;
-}
-
-void ScopedThreadLocalStateBackup::Restore() {
-  // A lame implementation that only keeps essential state and resets the rest.
-  __msan_va_arg_overflow_size_tls = va_arg_overflow_size_tls;
-
-  internal_memset(__msan_param_tls, 0, sizeof(__msan_param_tls));
-  internal_memset(__msan_retval_tls, 0, sizeof(__msan_retval_tls));
-  internal_memset(__msan_va_arg_tls, 0, sizeof(__msan_va_arg_tls));
-  internal_memset(__msan_va_arg_origin_tls, 0,
-                  sizeof(__msan_va_arg_origin_tls));
-
-  if (__msan_get_track_origins()) {
-    internal_memset(&__msan_retval_origin_tls, 0,
-                    sizeof(__msan_retval_origin_tls));
-    internal_memset(__msan_param_origin_tls, 0,
-                    sizeof(__msan_param_origin_tls));
-  }
-}
-
-void UnpoisonThreadLocalState() {
-}
-
-const char *GetStackOriginDescr(u32 id, uptr *pc) {
-  CHECK_LT(id, kNumStackOriginDescrs);
-  if (pc) *pc = StackOriginPC[id];
-  return StackOriginDescr[id];
-}
-
-u32 ChainOrigin(u32 id, StackTrace *stack) {
-  MsanThread *t = GetCurrentThread();
-  if (t && t->InSignalHandler())
-    return id;
-
-  Origin o = Origin::FromRawId(id);
-  stack->tag = StackTrace::TAG_UNKNOWN;
-  Origin chained = Origin::CreateChainedOrigin(o, stack);
-  return chained.raw_id();
-}
-
-} // namespace __msan
-
-void __sanitizer::BufferedStackTrace::UnwindImpl(
-    uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
-  using namespace __msan;
-  MsanThread *t = GetCurrentThread();
-  if (!t || !StackTrace::WillUseFastUnwind(request_fast)) {
-    // Block reports from our interceptors during _Unwind_Backtrace.
-    SymbolizerScope sym_scope;
-    return Unwind(max_depth, pc, bp, context, 0, 0, false);
-  }
-  if (StackTrace::WillUseFastUnwind(request_fast))
-    Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), true);
-  else
-    Unwind(max_depth, pc, 0, context, 0, 0, false);
-}
-
-// Interface.
-
-using namespace __msan;
-
-#define MSAN_MAYBE_WARNING(type, size)              \
-  void __msan_maybe_warning_##size(type s, u32 o) { \
-    GET_CALLER_PC_BP_SP;                            \
-    (void) sp;                                      \
-    if (UNLIKELY(s)) {                              \
-      PrintWarningWithOrigin(pc, bp, o);            \
-      if (__msan::flags()->halt_on_error) {         \
-        Printf("Exiting\n");                        \
-        Die();                                      \
-      }                                             \
-    }                                               \
-  }
-
-MSAN_MAYBE_WARNING(u8, 1)
-MSAN_MAYBE_WARNING(u16, 2)
-MSAN_MAYBE_WARNING(u32, 4)
-MSAN_MAYBE_WARNING(u64, 8)
-
-#define MSAN_MAYBE_STORE_ORIGIN(type, size)                       \
-  void __msan_maybe_store_origin_##size(type s, void *p, u32 o) { \
-    if (UNLIKELY(s)) {                                            \
-      if (__msan_get_track_origins() > 1) {                       \
-        GET_CALLER_PC_BP_SP;                                      \
-        (void) sp;                                                \
-        GET_STORE_STACK_TRACE_PC_BP(pc, bp);                      \
-        o = ChainOrigin(o, &stack);                               \
-      }                                                           \
-      *(u32 *)MEM_TO_ORIGIN((uptr)p & ~3UL) = o;                  \
-    }                                                             \
-  }
-
-MSAN_MAYBE_STORE_ORIGIN(u8, 1)
-MSAN_MAYBE_STORE_ORIGIN(u16, 2)
-MSAN_MAYBE_STORE_ORIGIN(u32, 4)
-MSAN_MAYBE_STORE_ORIGIN(u64, 8)
-
-void __msan_warning() {
-  GET_CALLER_PC_BP_SP;
-  (void)sp;
-  PrintWarning(pc, bp);
-  if (__msan::flags()->halt_on_error) {
-    if (__msan::flags()->print_stats)
-      ReportStats();
-    Printf("Exiting\n");
-    Die();
-  }
-}
-
-void __msan_warning_noreturn() {
-  GET_CALLER_PC_BP_SP;
-  (void)sp;
-  PrintWarning(pc, bp);
-  if (__msan::flags()->print_stats)
-    ReportStats();
-  Printf("Exiting\n");
-  Die();
-}
-
-static void OnStackUnwind(const SignalContext &sig, const void *,
-                          BufferedStackTrace *stack) {
-  stack->Unwind(sig.pc, sig.bp, sig.context,
-                common_flags()->fast_unwind_on_fatal);
-}
-
-static void MsanOnDeadlySignal(int signo, void *siginfo, void *context) {
-  HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
-}
-
-static void MsanCheckFailed(const char *file, int line, const char *cond,
-                            u64 v1, u64 v2) {
-  Report("MemorySanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
-         line, cond, (uptr)v1, (uptr)v2);
-  PRINT_CURRENT_STACK_CHECK();
-  Die();
-}
-
-void __msan_init() {
-  CHECK(!msan_init_is_running);
-  if (msan_inited) return;
-  msan_init_is_running = 1;
-  SanitizerToolName = "MemorySanitizer";
-
-  AvoidCVE_2016_2143();
-
-  CacheBinaryName();
-  CheckASLR();
-  InitializeFlags();
-
-  // Install tool-specific callbacks in sanitizer_common.
-  SetCheckFailedCallback(MsanCheckFailed);
-
-  __sanitizer_set_report_path(common_flags()->log_path);
-
-  InitializeInterceptors();
-  InitTlsSize();
-  InstallDeadlySignalHandlers(MsanOnDeadlySignal);
-  InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
-
-  DisableCoreDumperIfNecessary();
-  if (StackSizeIsUnlimited()) {
-    VPrintf(1, "Unlimited stack, doing reexec\n");
-    // A reasonably large stack size. It is bigger than the usual 8Mb, because,
-    // well, the program could have been run with unlimited stack for a reason.
-    SetStackSizeLimitInBytes(32 * 1024 * 1024);
-    ReExec();
-  }
-
-  __msan_clear_on_return();
-  if (__msan_get_track_origins())
-    VPrintf(1, "msan_track_origins\n");
-  if (!InitShadow(__msan_get_track_origins())) {
-    Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n");
-    Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n");
-    Printf("FATAL: Disabling ASLR is known to cause this error.\n");
-    Printf("FATAL: If running under GDB, try "
-           "'set disable-randomization off'.\n");
-    DumpProcessMap();
-    Die();
-  }
-
-  Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
-
-  InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
-
-  MsanTSDInit(MsanTSDDtor);
-
-  MsanAllocatorInit();
-
-  MsanThread *main_thread = MsanThread::Create(nullptr, nullptr);
-  SetCurrentThread(main_thread);
-  main_thread->ThreadStart();
-
-#if MSAN_CONTAINS_UBSAN
-  __ubsan::InitAsPlugin();
-#endif
-
-  VPrintf(1, "MemorySanitizer init done\n");
-
-  msan_init_is_running = 0;
-  msan_inited = 1;
-}
-
-void __msan_set_keep_going(int keep_going) {
-  flags()->halt_on_error = !keep_going;
-}
-
-void __msan_set_expect_umr(int expect_umr) {
-  if (expect_umr) {
-    msan_expected_umr_found = 0;
-  } else if (!msan_expected_umr_found) {
-    GET_CALLER_PC_BP_SP;
-    (void)sp;
-    GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
-    ReportExpectedUMRNotFound(&stack);
-    Die();
-  }
-  msan_expect_umr = expect_umr;
-}
-
-void __msan_print_shadow(const void *x, uptr size) {
-  if (!MEM_IS_APP(x)) {
-    Printf("Not a valid application address: %p\n", x);
-    return;
-  }
-
-  DescribeMemoryRange(x, size);
-}
-
-void __msan_dump_shadow(const void *x, uptr size) {
-  if (!MEM_IS_APP(x)) {
-    Printf("Not a valid application address: %p\n", x);
-    return;
-  }
-
-  unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
-  for (uptr i = 0; i < size; i++)
-    Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
-  Printf("\n");
-}
-
-sptr __msan_test_shadow(const void *x, uptr size) {
-  if (!MEM_IS_APP(x)) return -1;
-  unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
-  for (uptr i = 0; i < size; ++i)
-    if (s[i])
-      return i;
-  return -1;
-}
-
-void __msan_check_mem_is_initialized(const void *x, uptr size) {
-  if (!__msan::flags()->report_umrs) return;
-  sptr offset = __msan_test_shadow(x, size);
-  if (offset < 0)
-    return;
-
-  GET_CALLER_PC_BP_SP;
-  (void)sp;
-  ReportUMRInsideAddressRange(__func__, x, size, offset);
-  __msan::PrintWarningWithOrigin(pc, bp,
-                                 __msan_get_origin(((const char *)x) + offset));
-  if (__msan::flags()->halt_on_error) {
-    Printf("Exiting\n");
-    Die();
-  }
-}
-
-int __msan_set_poison_in_malloc(int do_poison) {
-  int old = flags()->poison_in_malloc;
-  flags()->poison_in_malloc = do_poison;
-  return old;
-}
-
-int __msan_has_dynamic_component() { return false; }
-
-NOINLINE
-void __msan_clear_on_return() {
-  __msan_param_tls[0] = 0;
-}
-
-void __msan_partial_poison(const void* data, void* shadow, uptr size) {
-  internal_memcpy((void*)MEM_TO_SHADOW((uptr)data), shadow, size);
-}
-
-void __msan_load_unpoisoned(const void *src, uptr size, void *dst) {
-  internal_memcpy(dst, src, size);
-  __msan_unpoison(dst, size);
-}
-
-void __msan_set_origin(const void *a, uptr size, u32 origin) {
-  if (__msan_get_track_origins()) SetOrigin(a, size, origin);
-}
-
-// 'descr' is created at compile time and contains '----' in the beginning.
-// When we see descr for the first time we replace '----' with a uniq id
-// and set the origin to (id | (31-th bit)).
-void __msan_set_alloca_origin(void *a, uptr size, char *descr) {
-  __msan_set_alloca_origin4(a, size, descr, 0);
-}
-
-void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) {
-  static const u32 dash = '-';
-  static const u32 first_timer =
-      dash + (dash << 8) + (dash << 16) + (dash << 24);
-  u32 *id_ptr = (u32*)descr;
-  bool print = false;  // internal_strstr(descr + 4, "AllocaTOTest") != 0;
-  u32 id = *id_ptr;
-  if (id == first_timer) {
-    u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
-    CHECK_LT(idx, kNumStackOriginDescrs);
-    StackOriginDescr[idx] = descr + 4;
-#if SANITIZER_PPC64V1
-    // On PowerPC64 ELFv1, the address of a function actually points to a
-    // three-doubleword data structure with the first field containing
-    // the address of the function's code.
-    if (pc)
-      pc = *reinterpret_cast<uptr*>(pc);
-#endif
-    StackOriginPC[idx] = pc;
-    id = Origin::CreateStackOrigin(idx).raw_id();
-    *id_ptr = id;
-    if (print)
-      Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc);
-  }
-  if (print)
-    Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
-  __msan_set_origin(a, size, id);
-}
-
-u32 __msan_chain_origin(u32 id) {
-  GET_CALLER_PC_BP_SP;
-  (void)sp;
-  GET_STORE_STACK_TRACE_PC_BP(pc, bp);
-  return ChainOrigin(id, &stack);
-}
-
-u32 __msan_get_origin(const void *a) {
-  if (!__msan_get_track_origins()) return 0;
-  uptr x = (uptr)a;
-  uptr aligned = x & ~3ULL;
-  uptr origin_ptr = MEM_TO_ORIGIN(aligned);
-  return *(u32*)origin_ptr;
-}
-
-int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id) {
-  Origin o = Origin::FromRawId(this_id);
-  while (o.raw_id() != prev_id && o.isChainedOrigin())
-    o = o.getNextChainedOrigin(nullptr);
-  return o.raw_id() == prev_id;
-}
-
-u32 __msan_get_umr_origin() {
-  return __msan_origin_tls;
-}
-
-u16 __sanitizer_unaligned_load16(const uu16 *p) {
-  *(uu16 *)&__msan_retval_tls[0] = *(uu16 *)MEM_TO_SHADOW((uptr)p);
-  if (__msan_get_track_origins())
-    __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
-  return *p;
-}
-u32 __sanitizer_unaligned_load32(const uu32 *p) {
-  *(uu32 *)&__msan_retval_tls[0] = *(uu32 *)MEM_TO_SHADOW((uptr)p);
-  if (__msan_get_track_origins())
-    __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
-  return *p;
-}
-u64 __sanitizer_unaligned_load64(const uu64 *p) {
-  __msan_retval_tls[0] = *(uu64 *)MEM_TO_SHADOW((uptr)p);
-  if (__msan_get_track_origins())
-    __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
-  return *p;
-}
-void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
-  u16 s = *(uu16 *)&__msan_param_tls[1];
-  *(uu16 *)MEM_TO_SHADOW((uptr)p) = s;
-  if (s && __msan_get_track_origins())
-    if (uu32 o = __msan_param_origin_tls[2])
-      SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
-  *p = x;
-}
-void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
-  u32 s = *(uu32 *)&__msan_param_tls[1];
-  *(uu32 *)MEM_TO_SHADOW((uptr)p) = s;
-  if (s && __msan_get_track_origins())
-    if (uu32 o = __msan_param_origin_tls[2])
-      SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
-  *p = x;
-}
-void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
-  u64 s = __msan_param_tls[1];
-  *(uu64 *)MEM_TO_SHADOW((uptr)p) = s;
-  if (s && __msan_get_track_origins())
-    if (uu32 o = __msan_param_origin_tls[2])
-      SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
-  *p = x;
-}
-
-void __msan_set_death_callback(void (*callback)(void)) {
-  SetUserDieCallback(callback);
-}
-
-#if !SANITIZER_SUPPORTS_WEAK_HOOKS
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-const char* __msan_default_options() { return ""; }
-}  // extern "C"
-#endif
-
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_print_stack_trace() {
-  GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME());
-  stack.Print();
-}
-} // extern "C"

Copied: compiler-rt/trunk/lib/msan/msan.cpp (from r367561, compiler-rt/trunk/lib/msan/msan.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cpp?p2=compiler-rt/trunk/lib/msan/msan.cpp&p1=compiler-rt/trunk/lib/msan/msan.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan.cc -----------------------------------------------------------===//
+//===-- msan.cpp ----------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_allocator.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_allocator.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_allocator.cc (removed)
@@ -1,349 +0,0 @@
-//===-- msan_allocator.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// MemorySanitizer allocator.
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_allocator.h"
-#include "sanitizer_common/sanitizer_allocator_checks.h"
-#include "sanitizer_common/sanitizer_allocator_interface.h"
-#include "sanitizer_common/sanitizer_allocator_report.h"
-#include "sanitizer_common/sanitizer_errno.h"
-#include "msan.h"
-#include "msan_allocator.h"
-#include "msan_origin.h"
-#include "msan_thread.h"
-#include "msan_poisoning.h"
-
-namespace __msan {
-
-struct Metadata {
-  uptr requested_size;
-};
-
-struct MsanMapUnmapCallback {
-  void OnMap(uptr p, uptr size) const {}
-  void OnUnmap(uptr p, uptr size) const {
-    __msan_unpoison((void *)p, size);
-
-    // We are about to unmap a chunk of user memory.
-    // Mark the corresponding shadow memory as not needed.
-    uptr shadow_p = MEM_TO_SHADOW(p);
-    ReleaseMemoryPagesToOS(shadow_p, shadow_p + size);
-    if (__msan_get_track_origins()) {
-      uptr origin_p = MEM_TO_ORIGIN(p);
-      ReleaseMemoryPagesToOS(origin_p, origin_p + size);
-    }
-  }
-};
-
-#if defined(__mips64)
-static const uptr kMaxAllowedMallocSize = 2UL << 30;
-
-struct AP32 {
-  static const uptr kSpaceBeg = 0;
-  static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
-  static const uptr kMetadataSize = sizeof(Metadata);
-  typedef __sanitizer::CompactSizeClassMap SizeClassMap;
-  static const uptr kRegionSizeLog = 20;
-  using AddressSpaceView = LocalAddressSpaceView;
-  typedef MsanMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
-};
-typedef SizeClassAllocator32<AP32> PrimaryAllocator;
-#elif defined(__x86_64__)
-#if SANITIZER_NETBSD || \
-    (SANITIZER_LINUX && !defined(MSAN_LINUX_X86_64_OLD_MAPPING))
-static const uptr kAllocatorSpace = 0x700000000000ULL;
-#else
-static const uptr kAllocatorSpace = 0x600000000000ULL;
-#endif
-static const uptr kMaxAllowedMallocSize = 8UL << 30;
-
-struct AP64 {  // Allocator64 parameters. Deliberately using a short name.
-  static const uptr kSpaceBeg = kAllocatorSpace;
-  static const uptr kSpaceSize = 0x40000000000;  // 4T.
-  static const uptr kMetadataSize = sizeof(Metadata);
-  typedef DefaultSizeClassMap SizeClassMap;
-  typedef MsanMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
-  using AddressSpaceView = LocalAddressSpaceView;
-};
-
-typedef SizeClassAllocator64<AP64> PrimaryAllocator;
-
-#elif defined(__powerpc64__)
-static const uptr kMaxAllowedMallocSize = 2UL << 30;  // 2G
-
-struct AP64 {  // Allocator64 parameters. Deliberately using a short name.
-  static const uptr kSpaceBeg = 0x300000000000;
-  static const uptr kSpaceSize = 0x020000000000;  // 2T.
-  static const uptr kMetadataSize = sizeof(Metadata);
-  typedef DefaultSizeClassMap SizeClassMap;
-  typedef MsanMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
-  using AddressSpaceView = LocalAddressSpaceView;
-};
-
-typedef SizeClassAllocator64<AP64> PrimaryAllocator;
-#elif defined(__aarch64__)
-static const uptr kMaxAllowedMallocSize = 2UL << 30;  // 2G
-
-struct AP32 {
-  static const uptr kSpaceBeg = 0;
-  static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
-  static const uptr kMetadataSize = sizeof(Metadata);
-  typedef __sanitizer::CompactSizeClassMap SizeClassMap;
-  static const uptr kRegionSizeLog = 20;
-  using AddressSpaceView = LocalAddressSpaceView;
-  typedef MsanMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
-};
-typedef SizeClassAllocator32<AP32> PrimaryAllocator;
-#endif
-typedef CombinedAllocator<PrimaryAllocator> Allocator;
-typedef Allocator::AllocatorCache AllocatorCache;
-
-static Allocator allocator;
-static AllocatorCache fallback_allocator_cache;
-static StaticSpinMutex fallback_mutex;
-
-void MsanAllocatorInit() {
-  SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
-  allocator.Init(common_flags()->allocator_release_to_os_interval_ms);
-}
-
-AllocatorCache *GetAllocatorCache(MsanThreadLocalMallocStorage *ms) {
-  CHECK(ms);
-  CHECK_LE(sizeof(AllocatorCache), sizeof(ms->allocator_cache));
-  return reinterpret_cast<AllocatorCache *>(ms->allocator_cache);
-}
-
-void MsanThreadLocalMallocStorage::CommitBack() {
-  allocator.SwallowCache(GetAllocatorCache(this));
-}
-
-static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
-                          bool zeroise) {
-  if (size > kMaxAllowedMallocSize) {
-    if (AllocatorMayReturnNull()) {
-      Report("WARNING: MemorySanitizer failed to allocate 0x%zx bytes\n", size);
-      return nullptr;
-    }
-    ReportAllocationSizeTooBig(size, kMaxAllowedMallocSize, stack);
-  }
-  MsanThread *t = GetCurrentThread();
-  void *allocated;
-  if (t) {
-    AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
-    allocated = allocator.Allocate(cache, size, alignment);
-  } else {
-    SpinMutexLock l(&fallback_mutex);
-    AllocatorCache *cache = &fallback_allocator_cache;
-    allocated = allocator.Allocate(cache, size, alignment);
-  }
-  if (UNLIKELY(!allocated)) {
-    SetAllocatorOutOfMemory();
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportOutOfMemory(size, stack);
-  }
-  Metadata *meta =
-      reinterpret_cast<Metadata *>(allocator.GetMetaData(allocated));
-  meta->requested_size = size;
-  if (zeroise) {
-    __msan_clear_and_unpoison(allocated, size);
-  } else if (flags()->poison_in_malloc) {
-    __msan_poison(allocated, size);
-    if (__msan_get_track_origins()) {
-      stack->tag = StackTrace::TAG_ALLOC;
-      Origin o = Origin::CreateHeapOrigin(stack);
-      __msan_set_origin(allocated, size, o.raw_id());
-    }
-  }
-  MSAN_MALLOC_HOOK(allocated, size);
-  return allocated;
-}
-
-void MsanDeallocate(StackTrace *stack, void *p) {
-  CHECK(p);
-  MSAN_FREE_HOOK(p);
-  Metadata *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(p));
-  uptr size = meta->requested_size;
-  meta->requested_size = 0;
-  // This memory will not be reused by anyone else, so we are free to keep it
-  // poisoned.
-  if (flags()->poison_in_free) {
-    __msan_poison(p, size);
-    if (__msan_get_track_origins()) {
-      stack->tag = StackTrace::TAG_DEALLOC;
-      Origin o = Origin::CreateHeapOrigin(stack);
-      __msan_set_origin(p, size, o.raw_id());
-    }
-  }
-  MsanThread *t = GetCurrentThread();
-  if (t) {
-    AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
-    allocator.Deallocate(cache, p);
-  } else {
-    SpinMutexLock l(&fallback_mutex);
-    AllocatorCache *cache = &fallback_allocator_cache;
-    allocator.Deallocate(cache, p);
-  }
-}
-
-void *MsanReallocate(StackTrace *stack, void *old_p, uptr new_size,
-                     uptr alignment) {
-  Metadata *meta = reinterpret_cast<Metadata*>(allocator.GetMetaData(old_p));
-  uptr old_size = meta->requested_size;
-  uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(old_p);
-  if (new_size <= actually_allocated_size) {
-    // We are not reallocating here.
-    meta->requested_size = new_size;
-    if (new_size > old_size) {
-      if (flags()->poison_in_malloc) {
-        stack->tag = StackTrace::TAG_ALLOC;
-        PoisonMemory((char *)old_p + old_size, new_size - old_size, stack);
-      }
-    }
-    return old_p;
-  }
-  uptr memcpy_size = Min(new_size, old_size);
-  void *new_p = MsanAllocate(stack, new_size, alignment, false /*zeroise*/);
-  if (new_p) {
-    CopyMemory(new_p, old_p, memcpy_size, stack);
-    MsanDeallocate(stack, old_p);
-  }
-  return new_p;
-}
-
-void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
-  if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportCallocOverflow(nmemb, size, stack);
-  }
-  return MsanAllocate(stack, nmemb * size, sizeof(u64), true);
-}
-
-static uptr AllocationSize(const void *p) {
-  if (!p) return 0;
-  const void *beg = allocator.GetBlockBegin(p);
-  if (beg != p) return 0;
-  Metadata *b = (Metadata *)allocator.GetMetaData(p);
-  return b->requested_size;
-}
-
-void *msan_malloc(uptr size, StackTrace *stack) {
-  return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
-}
-
-void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack) {
-  return SetErrnoOnNull(MsanCalloc(stack, nmemb, size));
-}
-
-void *msan_realloc(void *ptr, uptr size, StackTrace *stack) {
-  if (!ptr)
-    return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
-  if (size == 0) {
-    MsanDeallocate(stack, ptr);
-    return nullptr;
-  }
-  return SetErrnoOnNull(MsanReallocate(stack, ptr, size, sizeof(u64)));
-}
-
-void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack) {
-  if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
-    errno = errno_ENOMEM;
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportReallocArrayOverflow(nmemb, size, stack);
-  }
-  return msan_realloc(ptr, nmemb * size, stack);
-}
-
-void *msan_valloc(uptr size, StackTrace *stack) {
-  return SetErrnoOnNull(MsanAllocate(stack, size, GetPageSizeCached(), false));
-}
-
-void *msan_pvalloc(uptr size, StackTrace *stack) {
-  uptr PageSize = GetPageSizeCached();
-  if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) {
-    errno = errno_ENOMEM;
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportPvallocOverflow(size, stack);
-  }
-  // pvalloc(0) should allocate one page.
-  size = size ? RoundUpTo(size, PageSize) : PageSize;
-  return SetErrnoOnNull(MsanAllocate(stack, size, PageSize, false));
-}
-
-void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack) {
-  if (UNLIKELY(!CheckAlignedAllocAlignmentAndSize(alignment, size))) {
-    errno = errno_EINVAL;
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportInvalidAlignedAllocAlignment(size, alignment, stack);
-  }
-  return SetErrnoOnNull(MsanAllocate(stack, size, alignment, false));
-}
-
-void *msan_memalign(uptr alignment, uptr size, StackTrace *stack) {
-  if (UNLIKELY(!IsPowerOfTwo(alignment))) {
-    errno = errno_EINVAL;
-    if (AllocatorMayReturnNull())
-      return nullptr;
-    ReportInvalidAllocationAlignment(alignment, stack);
-  }
-  return SetErrnoOnNull(MsanAllocate(stack, size, alignment, false));
-}
-
-int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
-                        StackTrace *stack) {
-  if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) {
-    if (AllocatorMayReturnNull())
-      return errno_EINVAL;
-    ReportInvalidPosixMemalignAlignment(alignment, stack);
-  }
-  void *ptr = MsanAllocate(stack, size, alignment, false);
-  if (UNLIKELY(!ptr))
-    // OOM error is already taken care of by MsanAllocate.
-    return errno_ENOMEM;
-  CHECK(IsAligned((uptr)ptr, alignment));
-  *memptr = ptr;
-  return 0;
-}
-
-} // namespace __msan
-
-using namespace __msan;
-
-uptr __sanitizer_get_current_allocated_bytes() {
-  uptr stats[AllocatorStatCount];
-  allocator.GetStats(stats);
-  return stats[AllocatorStatAllocated];
-}
-
-uptr __sanitizer_get_heap_size() {
-  uptr stats[AllocatorStatCount];
-  allocator.GetStats(stats);
-  return stats[AllocatorStatMapped];
-}
-
-uptr __sanitizer_get_free_bytes() { return 1; }
-
-uptr __sanitizer_get_unmapped_bytes() { return 1; }
-
-uptr __sanitizer_get_estimated_allocated_size(uptr size) { return size; }
-
-int __sanitizer_get_ownership(const void *p) { return AllocationSize(p) != 0; }
-
-uptr __sanitizer_get_allocated_size(const void *p) { return AllocationSize(p); }

Copied: compiler-rt/trunk/lib/msan/msan_allocator.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_allocator.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_allocator.cpp?p2=compiler-rt/trunk/lib/msan/msan_allocator.cpp&p1=compiler-rt/trunk/lib/msan/msan_allocator.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_allocator.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_allocator.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_allocator.cc --------------------------- ---------------------===//
+//===-- msan_allocator.cpp -------------------------- ---------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc (removed)
@@ -1,131 +0,0 @@
-//===-- msan_chained_origin_depot.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
-//
-//===----------------------------------------------------------------------===//
-//
-// A storage for chained origins.
-//===----------------------------------------------------------------------===//
-
-#include "msan_chained_origin_depot.h"
-
-#include "sanitizer_common/sanitizer_stackdepotbase.h"
-
-namespace __msan {
-
-struct ChainedOriginDepotDesc {
-  u32 here_id;
-  u32 prev_id;
-};
-
-struct ChainedOriginDepotNode {
-  ChainedOriginDepotNode *link;
-  u32 id;
-  u32 here_id;
-  u32 prev_id;
-
-  typedef ChainedOriginDepotDesc args_type;
-
-  bool eq(u32 hash, const args_type &args) const {
-    return here_id == args.here_id && prev_id == args.prev_id;
-  }
-
-  static uptr storage_size(const args_type &args) {
-    return sizeof(ChainedOriginDepotNode);
-  }
-
-  /* This is murmur2 hash for the 64->32 bit case.
-     It does not behave all that well because the keys have a very biased
-     distribution (I've seen 7-element buckets with the table only 14% full).
-
-     here_id is built of
-     * (1 bits) Reserved, zero.
-     * (8 bits) Part id = bits 13..20 of the hash value of here_id's key.
-     * (23 bits) Sequential number (each part has each own sequence).
-
-     prev_id has either the same distribution as here_id (but with 3:8:21)
-     split, or one of two reserved values (-1) or (-2). Either case can
-     dominate depending on the workload.
-  */
-  static u32 hash(const args_type &args) {
-    const u32 m = 0x5bd1e995;
-    const u32 seed = 0x9747b28c;
-    const u32 r = 24;
-    u32 h = seed;
-    u32 k = args.here_id;
-    k *= m;
-    k ^= k >> r;
-    k *= m;
-    h *= m;
-    h ^= k;
-
-    k = args.prev_id;
-    k *= m;
-    k ^= k >> r;
-    k *= m;
-    h *= m;
-    h ^= k;
-
-    h ^= h >> 13;
-    h *= m;
-    h ^= h >> 15;
-    return h;
-  }
-  static bool is_valid(const args_type &args) { return true; }
-  void store(const args_type &args, u32 other_hash) {
-    here_id = args.here_id;
-    prev_id = args.prev_id;
-  }
-
-  args_type load() const {
-    args_type ret = {here_id, prev_id};
-    return ret;
-  }
-
-  struct Handle {
-    ChainedOriginDepotNode *node_;
-    Handle() : node_(nullptr) {}
-    explicit Handle(ChainedOriginDepotNode *node) : node_(node) {}
-    bool valid() { return node_; }
-    u32 id() { return node_->id; }
-    int here_id() { return node_->here_id; }
-    int prev_id() { return node_->prev_id; }
-  };
-
-  Handle get_handle() { return Handle(this); }
-
-  typedef Handle handle_type;
-};
-
-static StackDepotBase<ChainedOriginDepotNode, 4, 20> chainedOriginDepot;
-
-StackDepotStats *ChainedOriginDepotGetStats() {
-  return chainedOriginDepot.GetStats();
-}
-
-bool ChainedOriginDepotPut(u32 here_id, u32 prev_id, u32 *new_id) {
-  ChainedOriginDepotDesc desc = {here_id, prev_id};
-  bool inserted;
-  ChainedOriginDepotNode::Handle h = chainedOriginDepot.Put(desc, &inserted);
-  *new_id = h.valid() ? h.id() : 0;
-  return inserted;
-}
-
-// Retrieves a stored stack trace by the id.
-u32 ChainedOriginDepotGet(u32 id, u32 *other) {
-  ChainedOriginDepotDesc desc = chainedOriginDepot.Get(id);
-  *other = desc.prev_id;
-  return desc.here_id;
-}
-
-void ChainedOriginDepotLockAll() {
-  chainedOriginDepot.LockAll();
-}
-
-void ChainedOriginDepotUnlockAll() {
-  chainedOriginDepot.UnlockAll();
-}
-
-} // namespace __msan

Copied: compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cpp?p2=compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cpp&p1=compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_chained_origin_depot.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_chained_origin_depot.cc -----------------------------------===//
+//===-- msan_chained_origin_depot.cpp ----------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc (removed)
@@ -1,1715 +0,0 @@
-//===-- msan_interceptors.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// Interceptors for standard library functions.
-//
-// FIXME: move as many interceptors as possible into
-// sanitizer_common/sanitizer_common_interceptors.h
-//===----------------------------------------------------------------------===//
-
-#include "interception/interception.h"
-#include "msan.h"
-#include "msan_chained_origin_depot.h"
-#include "msan_origin.h"
-#include "msan_report.h"
-#include "msan_thread.h"
-#include "msan_poisoning.h"
-#include "sanitizer_common/sanitizer_platform_limits_posix.h"
-#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
-#include "sanitizer_common/sanitizer_allocator.h"
-#include "sanitizer_common/sanitizer_allocator_interface.h"
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_atomic.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_errno.h"
-#include "sanitizer_common/sanitizer_stackdepot.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_linux.h"
-#include "sanitizer_common/sanitizer_tls_get_addr.h"
-#include "sanitizer_common/sanitizer_vector.h"
-
-#if SANITIZER_NETBSD
-#define fstat __fstat50
-#define gettimeofday __gettimeofday50
-#define getrusage __getrusage50
-#define tzset __tzset50
-#endif
-
-#include <stdarg.h>
-// ACHTUNG! No other system header includes in this file.
-// Ideally, we should get rid of stdarg.h as well.
-
-using namespace __msan;
-
-using __sanitizer::memory_order;
-using __sanitizer::atomic_load;
-using __sanitizer::atomic_store;
-using __sanitizer::atomic_uintptr_t;
-
-DECLARE_REAL(SIZE_T, strlen, const char *s)
-DECLARE_REAL(SIZE_T, strnlen, const char *s, SIZE_T maxlen)
-DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
-DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
-
-// True if this is a nested interceptor.
-static THREADLOCAL int in_interceptor_scope;
-
-void __msan_scoped_disable_interceptor_checks() { ++in_interceptor_scope; }
-void __msan_scoped_enable_interceptor_checks() { --in_interceptor_scope; }
-
-struct InterceptorScope {
-  InterceptorScope() { ++in_interceptor_scope; }
-  ~InterceptorScope() { --in_interceptor_scope; }
-};
-
-bool IsInInterceptorScope() {
-  return in_interceptor_scope;
-}
-
-static uptr allocated_for_dlsym;
-static const uptr kDlsymAllocPoolSize = 1024;
-static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize];
-
-static bool IsInDlsymAllocPool(const void *ptr) {
-  uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
-  return off < sizeof(alloc_memory_for_dlsym);
-}
-
-static void *AllocateFromLocalPool(uptr size_in_bytes) {
-  uptr size_in_words = RoundUpTo(size_in_bytes, kWordSize) / kWordSize;
-  void *mem = (void *)&alloc_memory_for_dlsym[allocated_for_dlsym];
-  allocated_for_dlsym += size_in_words;
-  CHECK_LT(allocated_for_dlsym, kDlsymAllocPoolSize);
-  return mem;
-}
-
-#define ENSURE_MSAN_INITED() do { \
-  CHECK(!msan_init_is_running); \
-  if (!msan_inited) { \
-    __msan_init(); \
-  } \
-} while (0)
-
-// Check that [x, x+n) range is unpoisoned.
-#define CHECK_UNPOISONED_0(x, n)                                  \
-  do {                                                            \
-    sptr __offset = __msan_test_shadow(x, n);                     \
-    if (__msan::IsInSymbolizer()) break;                          \
-    if (__offset >= 0 && __msan::flags()->report_umrs) {          \
-      GET_CALLER_PC_BP_SP;                                        \
-      (void)sp;                                                   \
-      ReportUMRInsideAddressRange(__func__, x, n, __offset);      \
-      __msan::PrintWarningWithOrigin(                             \
-          pc, bp, __msan_get_origin((const char *)x + __offset)); \
-      if (__msan::flags()->halt_on_error) {                       \
-        Printf("Exiting\n");                                      \
-        Die();                                                    \
-      }                                                           \
-    }                                                             \
-  } while (0)
-
-// Check that [x, x+n) range is unpoisoned unless we are in a nested
-// interceptor.
-#define CHECK_UNPOISONED(x, n)                             \
-  do {                                                     \
-    if (!IsInInterceptorScope()) CHECK_UNPOISONED_0(x, n); \
-  } while (0)
-
-#define CHECK_UNPOISONED_STRING_OF_LEN(x, len, n)               \
-  CHECK_UNPOISONED((x),                                         \
-    common_flags()->strict_string_checks ? (len) + 1 : (n) )
-
-#define CHECK_UNPOISONED_STRING(x, n)                           \
-    CHECK_UNPOISONED_STRING_OF_LEN((x), internal_strlen(x), (n))
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(SIZE_T, fread_unlocked, void *ptr, SIZE_T size, SIZE_T nmemb,
-            void *file) {
-  ENSURE_MSAN_INITED();
-  SIZE_T res = REAL(fread_unlocked)(ptr, size, nmemb, file);
-  if (res > 0)
-    __msan_unpoison(ptr, res *size);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_FREAD_UNLOCKED INTERCEPT_FUNCTION(fread_unlocked)
-#else
-#define MSAN_MAYBE_INTERCEPT_FREAD_UNLOCKED
-#endif
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(void *, mempcpy, void *dest, const void *src, SIZE_T n) {
-  return (char *)__msan_memcpy(dest, src, n) + n;
-}
-#define MSAN_MAYBE_INTERCEPT_MEMPCPY INTERCEPT_FUNCTION(mempcpy)
-#else
-#define MSAN_MAYBE_INTERCEPT_MEMPCPY
-#endif
-
-INTERCEPTOR(void *, memccpy, void *dest, const void *src, int c, SIZE_T n) {
-  ENSURE_MSAN_INITED();
-  void *res = REAL(memccpy)(dest, src, c, n);
-  CHECK(!res || (res >= dest && res <= (char *)dest + n));
-  SIZE_T sz = res ? (char *)res - (char *)dest : n;
-  CHECK_UNPOISONED(src, sz);
-  __msan_unpoison(dest, sz);
-  return res;
-}
-
-INTERCEPTOR(void *, bcopy, const void *src, void *dest, SIZE_T n) {
-  return __msan_memmove(dest, src, n);
-}
-
-INTERCEPTOR(int, posix_memalign, void **memptr, SIZE_T alignment, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  CHECK_NE(memptr, 0);
-  int res = msan_posix_memalign(memptr, alignment, size, &stack);
-  if (!res)
-    __msan_unpoison(memptr, sizeof(*memptr));
-  return res;
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(void *, memalign, SIZE_T alignment, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  return msan_memalign(alignment, size, &stack);
-}
-#define MSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)
-#else
-#define MSAN_MAYBE_INTERCEPT_MEMALIGN
-#endif
-
-INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  return msan_aligned_alloc(alignment, size, &stack);
-}
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(void *, __libc_memalign, SIZE_T alignment, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  void *ptr = msan_memalign(alignment, size, &stack);
-  if (ptr)
-    DTLS_on_libc_memalign(ptr, size);
-  return ptr;
-}
-#define MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
-#else
-#define MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN
-#endif
-
-INTERCEPTOR(void *, valloc, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  return msan_valloc(size, &stack);
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(void *, pvalloc, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  return msan_pvalloc(size, &stack);
-}
-#define MSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
-#else
-#define MSAN_MAYBE_INTERCEPT_PVALLOC
-#endif
-
-INTERCEPTOR(void, free, void *ptr) {
-  GET_MALLOC_STACK_TRACE;
-  if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
-  MsanDeallocate(&stack, ptr);
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(void, cfree, void *ptr) {
-  GET_MALLOC_STACK_TRACE;
-  if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
-  MsanDeallocate(&stack, ptr);
-}
-#define MSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree)
-#else
-#define MSAN_MAYBE_INTERCEPT_CFREE
-#endif
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
-  return __sanitizer_get_allocated_size(ptr);
-}
-#define MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE \
-  INTERCEPT_FUNCTION(malloc_usable_size)
-#else
-#define MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-// This function actually returns a struct by value, but we can't unpoison a
-// temporary! The following is equivalent on all supported platforms but
-// aarch64 (which uses a different register for sret value).  We have a test
-// to confirm that.
-INTERCEPTOR(void, mallinfo, __sanitizer_struct_mallinfo *sret) {
-#ifdef __aarch64__
-  uptr r8;
-  asm volatile("mov %0,x8" : "=r" (r8));
-  sret = reinterpret_cast<__sanitizer_struct_mallinfo*>(r8);
-#endif
-  REAL(memset)(sret, 0, sizeof(*sret));
-  __msan_unpoison(sret, sizeof(*sret));
-}
-#define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
-#else
-#define MSAN_MAYBE_INTERCEPT_MALLINFO
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, mallopt, int cmd, int value) {
-  return 0;
-}
-#define MSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt)
-#else
-#define MSAN_MAYBE_INTERCEPT_MALLOPT
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(void, malloc_stats, void) {
-  // FIXME: implement, but don't call REAL(malloc_stats)!
-}
-#define MSAN_MAYBE_INTERCEPT_MALLOC_STATS INTERCEPT_FUNCTION(malloc_stats)
-#else
-#define MSAN_MAYBE_INTERCEPT_MALLOC_STATS
-#endif
-
-INTERCEPTOR(char *, strcpy, char *dest, const char *src) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T n = REAL(strlen)(src);
-  CHECK_UNPOISONED_STRING(src + n, 0);
-  char *res = REAL(strcpy)(dest, src);  // NOLINT
-  CopyShadowAndOrigin(dest, src, n + 1, &stack);
-  return res;
-}
-
-INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T copy_size = REAL(strnlen)(src, n);
-  if (copy_size < n)
-    copy_size++;  // trailing \0
-  char *res = REAL(strncpy)(dest, src, n);  // NOLINT
-  CopyShadowAndOrigin(dest, src, copy_size, &stack);
-  __msan_unpoison(dest + copy_size, n - copy_size);
-  return res;
-}
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(char *, stpcpy, char *dest, const char *src) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T n = REAL(strlen)(src);
-  CHECK_UNPOISONED_STRING(src + n, 0);
-  char *res = REAL(stpcpy)(dest, src);  // NOLINT
-  CopyShadowAndOrigin(dest, src, n + 1, &stack);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_STPCPY INTERCEPT_FUNCTION(stpcpy)
-#else
-#define MSAN_MAYBE_INTERCEPT_STPCPY
-#endif
-
-INTERCEPTOR(char *, strdup, char *src) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  // On FreeBSD strdup() leverages strlen().
-  InterceptorScope interceptor_scope;
-  SIZE_T n = REAL(strlen)(src);
-  CHECK_UNPOISONED_STRING(src + n, 0);
-  char *res = REAL(strdup)(src);
-  CopyShadowAndOrigin(res, src, n + 1, &stack);
-  return res;
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(char *, __strdup, char *src) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T n = REAL(strlen)(src);
-  CHECK_UNPOISONED_STRING(src + n, 0);
-  char *res = REAL(__strdup)(src);
-  CopyShadowAndOrigin(res, src, n + 1, &stack);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT___STRDUP INTERCEPT_FUNCTION(__strdup)
-#else
-#define MSAN_MAYBE_INTERCEPT___STRDUP
-#endif
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(char *, gcvt, double number, SIZE_T ndigit, char *buf) {
-  ENSURE_MSAN_INITED();
-  char *res = REAL(gcvt)(number, ndigit, buf);
-  SIZE_T n = REAL(strlen)(buf);
-  __msan_unpoison(buf, n + 1);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_GCVT INTERCEPT_FUNCTION(gcvt)
-#else
-#define MSAN_MAYBE_INTERCEPT_GCVT
-#endif
-
-INTERCEPTOR(char *, strcat, char *dest, const char *src) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T src_size = REAL(strlen)(src);
-  SIZE_T dest_size = REAL(strlen)(dest);
-  CHECK_UNPOISONED_STRING(src + src_size, 0);
-  CHECK_UNPOISONED_STRING(dest + dest_size, 0);
-  char *res = REAL(strcat)(dest, src);  // NOLINT
-  CopyShadowAndOrigin(dest + dest_size, src, src_size + 1, &stack);
-  return res;
-}
-
-INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T dest_size = REAL(strlen)(dest);
-  SIZE_T copy_size = REAL(strnlen)(src, n);
-  CHECK_UNPOISONED_STRING(dest + dest_size, 0);
-  char *res = REAL(strncat)(dest, src, n);  // NOLINT
-  CopyShadowAndOrigin(dest + dest_size, src, copy_size, &stack);
-  __msan_unpoison(dest + dest_size + copy_size, 1); // \0
-  return res;
-}
-
-// Hack: always pass nptr and endptr as part of __VA_ARGS_ to avoid having to
-// deal with empty __VA_ARGS__ in the case of INTERCEPTOR_STRTO.
-#define INTERCEPTOR_STRTO_BODY(ret_type, func, ...) \
-  ENSURE_MSAN_INITED();                             \
-  ret_type res = REAL(func)(__VA_ARGS__);           \
-  __msan_unpoison(endptr, sizeof(*endptr));         \
-  return res;
-
-#define INTERCEPTOR_STRTO(ret_type, func, char_type)                       \
-  INTERCEPTOR(ret_type, func, const char_type *nptr, char_type **endptr) { \
-    INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr);                  \
-  }
-
-#define INTERCEPTOR_STRTO_BASE(ret_type, func, char_type)                \
-  INTERCEPTOR(ret_type, func, const char_type *nptr, char_type **endptr, \
-              int base) {                                                \
-    INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr, base);          \
-  }
-
-#define INTERCEPTOR_STRTO_LOC(ret_type, func, char_type)                 \
-  INTERCEPTOR(ret_type, func, const char_type *nptr, char_type **endptr, \
-              void *loc) {                                               \
-    INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr, loc);           \
-  }
-
-#define INTERCEPTOR_STRTO_BASE_LOC(ret_type, func, char_type)            \
-  INTERCEPTOR(ret_type, func, const char_type *nptr, char_type **endptr, \
-              int base, void *loc) {                                     \
-    INTERCEPTOR_STRTO_BODY(ret_type, func, nptr, endptr, base, loc);     \
-  }
-
-#if SANITIZER_NETBSD
-#define INTERCEPTORS_STRTO(ret_type, func, char_type)      \
-  INTERCEPTOR_STRTO(ret_type, func, char_type)             \
-  INTERCEPTOR_STRTO_LOC(ret_type, func##_l, char_type)
-
-#define INTERCEPTORS_STRTO_BASE(ret_type, func, char_type)      \
-  INTERCEPTOR_STRTO_BASE(ret_type, func, char_type)             \
-  INTERCEPTOR_STRTO_BASE_LOC(ret_type, func##_l, char_type)
-
-#else
-#define INTERCEPTORS_STRTO(ret_type, func, char_type)      \
-  INTERCEPTOR_STRTO(ret_type, func, char_type)             \
-  INTERCEPTOR_STRTO_LOC(ret_type, func##_l, char_type)     \
-  INTERCEPTOR_STRTO_LOC(ret_type, __##func##_l, char_type) \
-  INTERCEPTOR_STRTO_LOC(ret_type, __##func##_internal, char_type)
-
-#define INTERCEPTORS_STRTO_BASE(ret_type, func, char_type)      \
-  INTERCEPTOR_STRTO_BASE(ret_type, func, char_type)             \
-  INTERCEPTOR_STRTO_BASE_LOC(ret_type, func##_l, char_type)     \
-  INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_l, char_type) \
-  INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_internal, char_type)
-#endif
-
-INTERCEPTORS_STRTO(double, strtod, char)                     // NOLINT
-INTERCEPTORS_STRTO(float, strtof, char)                      // NOLINT
-INTERCEPTORS_STRTO(long double, strtold, char)               // NOLINT
-INTERCEPTORS_STRTO_BASE(long, strtol, char)                  // NOLINT
-INTERCEPTORS_STRTO_BASE(long long, strtoll, char)            // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long, strtoul, char)        // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long long, strtoull, char)  // NOLINT
-INTERCEPTORS_STRTO_BASE(u64, strtouq, char)                  // NOLINT
-
-INTERCEPTORS_STRTO(double, wcstod, wchar_t)                     // NOLINT
-INTERCEPTORS_STRTO(float, wcstof, wchar_t)                      // NOLINT
-INTERCEPTORS_STRTO(long double, wcstold, wchar_t)               // NOLINT
-INTERCEPTORS_STRTO_BASE(long, wcstol, wchar_t)                  // NOLINT
-INTERCEPTORS_STRTO_BASE(long long, wcstoll, wchar_t)            // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long, wcstoul, wchar_t)        // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long long, wcstoull, wchar_t)  // NOLINT
-
-#if SANITIZER_NETBSD
-#define INTERCEPT_STRTO(func) \
-  INTERCEPT_FUNCTION(func); \
-  INTERCEPT_FUNCTION(func##_l);
-#else
-#define INTERCEPT_STRTO(func) \
-  INTERCEPT_FUNCTION(func); \
-  INTERCEPT_FUNCTION(func##_l); \
-  INTERCEPT_FUNCTION(__##func##_l); \
-  INTERCEPT_FUNCTION(__##func##_internal);
-#endif
-
-
-// FIXME: support *wprintf in common format interceptors.
-INTERCEPTOR(int, vswprintf, void *str, uptr size, void *format, va_list ap) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(vswprintf)(str, size, format, ap);
-  if (res >= 0) {
-    __msan_unpoison(str, 4 * (res + 1));
-  }
-  return res;
-}
-
-INTERCEPTOR(int, swprintf, void *str, uptr size, void *format, ...) {
-  ENSURE_MSAN_INITED();
-  va_list ap;
-  va_start(ap, format);
-  int res = vswprintf(str, size, format, ap);
-  va_end(ap);
-  return res;
-}
-
-#define INTERCEPTOR_STRFTIME_BODY(char_type, ret_type, func, s, ...) \
-  ENSURE_MSAN_INITED();                                              \
-  InterceptorScope interceptor_scope;                                \
-  ret_type res = REAL(func)(s, __VA_ARGS__);                         \
-  if (s) __msan_unpoison(s, sizeof(char_type) * (res + 1));          \
-  return res;
-
-INTERCEPTOR(SIZE_T, strftime, char *s, SIZE_T max, const char *format,
-            __sanitizer_tm *tm) {
-  INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime, s, max, format, tm);
-}
-
-INTERCEPTOR(SIZE_T, strftime_l, char *s, SIZE_T max, const char *format,
-            __sanitizer_tm *tm, void *loc) {
-  INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime_l, s, max, format, tm, loc);
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(SIZE_T, __strftime_l, char *s, SIZE_T max, const char *format,
-            __sanitizer_tm *tm, void *loc) {
-  INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, __strftime_l, s, max, format, tm,
-                            loc);
-}
-#define MSAN_MAYBE_INTERCEPT___STRFTIME_L INTERCEPT_FUNCTION(__strftime_l)
-#else
-#define MSAN_MAYBE_INTERCEPT___STRFTIME_L
-#endif
-
-INTERCEPTOR(SIZE_T, wcsftime, wchar_t *s, SIZE_T max, const wchar_t *format,
-            __sanitizer_tm *tm) {
-  INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, wcsftime, s, max, format, tm);
-}
-
-INTERCEPTOR(SIZE_T, wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
-            __sanitizer_tm *tm, void *loc) {
-  INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, wcsftime_l, s, max, format, tm,
-                            loc);
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(SIZE_T, __wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format,
-            __sanitizer_tm *tm, void *loc) {
-  INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, __wcsftime_l, s, max, format, tm,
-                            loc);
-}
-#define MSAN_MAYBE_INTERCEPT___WCSFTIME_L INTERCEPT_FUNCTION(__wcsftime_l)
-#else
-#define MSAN_MAYBE_INTERCEPT___WCSFTIME_L
-#endif
-
-INTERCEPTOR(int, mbtowc, wchar_t *dest, const char *src, SIZE_T n) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(mbtowc)(dest, src, n);
-  if (res != -1 && dest) __msan_unpoison(dest, sizeof(wchar_t));
-  return res;
-}
-
-INTERCEPTOR(SIZE_T, mbrtowc, wchar_t *dest, const char *src, SIZE_T n,
-            void *ps) {
-  ENSURE_MSAN_INITED();
-  SIZE_T res = REAL(mbrtowc)(dest, src, n, ps);
-  if (res != (SIZE_T)-1 && dest) __msan_unpoison(dest, sizeof(wchar_t));
-  return res;
-}
-
-// wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, SIZE_T n);
-INTERCEPTOR(wchar_t *, wmemcpy, wchar_t *dest, const wchar_t *src, SIZE_T n) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  wchar_t *res = REAL(wmemcpy)(dest, src, n);
-  CopyShadowAndOrigin(dest, src, n * sizeof(wchar_t), &stack);
-  return res;
-}
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(wchar_t *, wmempcpy, wchar_t *dest, const wchar_t *src, SIZE_T n) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  wchar_t *res = REAL(wmempcpy)(dest, src, n);
-  CopyShadowAndOrigin(dest, src, n * sizeof(wchar_t), &stack);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_WMEMPCPY INTERCEPT_FUNCTION(wmempcpy)
-#else
-#define MSAN_MAYBE_INTERCEPT_WMEMPCPY
-#endif
-
-INTERCEPTOR(wchar_t *, wmemset, wchar_t *s, wchar_t c, SIZE_T n) {
-  CHECK(MEM_IS_APP(s));
-  ENSURE_MSAN_INITED();
-  wchar_t *res = REAL(wmemset)(s, c, n);
-  __msan_unpoison(s, n * sizeof(wchar_t));
-  return res;
-}
-
-INTERCEPTOR(wchar_t *, wmemmove, wchar_t *dest, const wchar_t *src, SIZE_T n) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  wchar_t *res = REAL(wmemmove)(dest, src, n);
-  MoveShadowAndOrigin(dest, src, n * sizeof(wchar_t), &stack);
-  return res;
-}
-
-INTERCEPTOR(int, wcscmp, const wchar_t *s1, const wchar_t *s2) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(wcscmp)(s1, s2);
-  return res;
-}
-
-INTERCEPTOR(int, gettimeofday, void *tv, void *tz) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(gettimeofday)(tv, tz);
-  if (tv)
-    __msan_unpoison(tv, 16);
-  if (tz)
-    __msan_unpoison(tz, 8);
-  return res;
-}
-
-#if !SANITIZER_NETBSD
-INTERCEPTOR(char *, fcvt, double x, int a, int *b, int *c) {
-  ENSURE_MSAN_INITED();
-  char *res = REAL(fcvt)(x, a, b, c);
-  __msan_unpoison(b, sizeof(*b));
-  __msan_unpoison(c, sizeof(*c));
-  if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_FCVT INTERCEPT_FUNCTION(fcvt)
-#else
-#define MSAN_MAYBE_INTERCEPT_FCVT
-#endif
-
-INTERCEPTOR(char *, getenv, char *name) {
-  if (msan_init_is_running)
-    return REAL(getenv)(name);
-  ENSURE_MSAN_INITED();
-  char *res = REAL(getenv)(name);
-  if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
-  return res;
-}
-
-extern char **environ;
-
-static void UnpoisonEnviron() {
-  char **envp = environ;
-  for (; *envp; ++envp) {
-    __msan_unpoison(envp, sizeof(*envp));
-    __msan_unpoison(*envp, REAL(strlen)(*envp) + 1);
-  }
-  // Trailing NULL pointer.
-  __msan_unpoison(envp, sizeof(*envp));
-}
-
-INTERCEPTOR(int, setenv, const char *name, const char *value, int overwrite) {
-  ENSURE_MSAN_INITED();
-  CHECK_UNPOISONED_STRING(name, 0);
-  int res = REAL(setenv)(name, value, overwrite);
-  if (!res) UnpoisonEnviron();
-  return res;
-}
-
-INTERCEPTOR(int, putenv, char *string) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(putenv)(string);
-  if (!res) UnpoisonEnviron();
-  return res;
-}
-
-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
-INTERCEPTOR(int, fstat, int fd, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(fstat)(fd, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_FSTAT INTERCEPT_FUNCTION(fstat)
-#else
-#define MSAN_MAYBE_INTERCEPT_FSTAT
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(__fxstat)(magic, fd, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT___FXSTAT INTERCEPT_FUNCTION(__fxstat)
-#else
-#define MSAN_MAYBE_INTERCEPT___FXSTAT
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(__fxstat64)(magic, fd, buf);
-  if (!res)
-    __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT___FXSTAT64 INTERCEPT_FUNCTION(__fxstat64)
-#else
-#define MSAN_MAYBE_INTERCEPT___FXSTAT64
-#endif
-
-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
-INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(fstatat)(fd, pathname, buf, flags);
-  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(fstatat)
-#else
-INTERCEPTOR(int, __fxstatat, int magic, int fd, char *pathname, void *buf,
-            int flags) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(__fxstatat)(magic, fd, pathname, buf, flags);
-  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat_sz);
-  return res;
-}
-# define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat)
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf,
-            int flags) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(__fxstatat64)(magic, fd, pathname, buf, flags);
-  if (!res) __msan_unpoison(buf, __sanitizer::struct_stat64_sz);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT___FXSTATAT64 INTERCEPT_FUNCTION(__fxstatat64)
-#else
-#define MSAN_MAYBE_INTERCEPT___FXSTATAT64
-#endif
-
-INTERCEPTOR(int, pipe, int pipefd[2]) {
-  if (msan_init_is_running)
-    return REAL(pipe)(pipefd);
-  ENSURE_MSAN_INITED();
-  int res = REAL(pipe)(pipefd);
-  if (!res)
-    __msan_unpoison(pipefd, sizeof(int[2]));
-  return res;
-}
-
-INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(pipe2)(pipefd, flags);
-  if (!res)
-    __msan_unpoison(pipefd, sizeof(int[2]));
-  return res;
-}
-
-INTERCEPTOR(int, socketpair, int domain, int type, int protocol, int sv[2]) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(socketpair)(domain, type, protocol, sv);
-  if (!res)
-    __msan_unpoison(sv, sizeof(int[2]));
-  return res;
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) {
-  ENSURE_MSAN_INITED();
-  char *res = REAL(fgets_unlocked)(s, size, stream);
-  if (res)
-    __msan_unpoison(s, REAL(strlen)(s) + 1);
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED INTERCEPT_FUNCTION(fgets_unlocked)
-#else
-#define MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED
-#endif
-
-INTERCEPTOR(int, getrlimit, int resource, void *rlim) {
-  if (msan_init_is_running)
-    return REAL(getrlimit)(resource, rlim);
-  ENSURE_MSAN_INITED();
-  int res = REAL(getrlimit)(resource, rlim);
-  if (!res)
-    __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz);
-  return res;
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
-  if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim);
-  ENSURE_MSAN_INITED();
-  int res = REAL(getrlimit64)(resource, rlim);
-  if (!res) __msan_unpoison(rlim, __sanitizer::struct_rlimit64_sz);
-  return res;
-}
-
-INTERCEPTOR(int, prlimit, int pid, int resource, void *new_rlimit,
-            void *old_rlimit) {
-  if (msan_init_is_running)
-    return REAL(prlimit)(pid, resource, new_rlimit, old_rlimit);
-  ENSURE_MSAN_INITED();
-  CHECK_UNPOISONED(new_rlimit, __sanitizer::struct_rlimit_sz);
-  int res = REAL(prlimit)(pid, resource, new_rlimit, old_rlimit);
-  if (!res) __msan_unpoison(old_rlimit, __sanitizer::struct_rlimit_sz);
-  return res;
-}
-
-INTERCEPTOR(int, prlimit64, int pid, int resource, void *new_rlimit,
-            void *old_rlimit) {
-  if (msan_init_is_running)
-    return REAL(prlimit64)(pid, resource, new_rlimit, old_rlimit);
-  ENSURE_MSAN_INITED();
-  CHECK_UNPOISONED(new_rlimit, __sanitizer::struct_rlimit64_sz);
-  int res = REAL(prlimit64)(pid, resource, new_rlimit, old_rlimit);
-  if (!res) __msan_unpoison(old_rlimit, __sanitizer::struct_rlimit64_sz);
-  return res;
-}
-
-#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64)
-#define MSAN_MAYBE_INTERCEPT_PRLIMIT INTERCEPT_FUNCTION(prlimit)
-#define MSAN_MAYBE_INTERCEPT_PRLIMIT64 INTERCEPT_FUNCTION(prlimit64)
-#else
-#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64
-#define MSAN_MAYBE_INTERCEPT_PRLIMIT
-#define MSAN_MAYBE_INTERCEPT_PRLIMIT64
-#endif
-
-#if SANITIZER_FREEBSD
-// FreeBSD's <sys/utsname.h> define uname() as
-// static __inline int uname(struct utsname *name) {
-//   return __xuname(SYS_NMLN, (void*)name);
-// }
-INTERCEPTOR(int, __xuname, int size, void *utsname) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(__xuname)(size, utsname);
-  if (!res)
-    __msan_unpoison(utsname, __sanitizer::struct_utsname_sz);
-  return res;
-}
-#define MSAN_INTERCEPT_UNAME INTERCEPT_FUNCTION(__xuname)
-#else
-INTERCEPTOR(int, uname, struct utsname *utsname) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(uname)(utsname);
-  if (!res)
-    __msan_unpoison(utsname, __sanitizer::struct_utsname_sz);
-  return res;
-}
-#define MSAN_INTERCEPT_UNAME INTERCEPT_FUNCTION(uname)
-#endif
-
-INTERCEPTOR(int, gethostname, char *name, SIZE_T len) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(gethostname)(name, len);
-  if (!res) {
-    SIZE_T real_len = REAL(strnlen)(name, len);
-    if (real_len < len)
-      ++real_len;
-    __msan_unpoison(name, real_len);
-  }
-  return res;
-}
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents,
-    int timeout) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(epoll_wait)(epfd, events, maxevents, timeout);
-  if (res > 0) {
-    __msan_unpoison(events, __sanitizer::struct_epoll_event_sz * res);
-  }
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_EPOLL_WAIT INTERCEPT_FUNCTION(epoll_wait)
-#else
-#define MSAN_MAYBE_INTERCEPT_EPOLL_WAIT
-#endif
-
-#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents,
-    int timeout, void *sigmask) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(epoll_pwait)(epfd, events, maxevents, timeout, sigmask);
-  if (res > 0) {
-    __msan_unpoison(events, __sanitizer::struct_epoll_event_sz * res);
-  }
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT INTERCEPT_FUNCTION(epoll_pwait)
-#else
-#define MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT
-#endif
-
-INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  if (UNLIKELY(!msan_inited))
-    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
-    return AllocateFromLocalPool(nmemb * size);
-  return msan_calloc(nmemb, size, &stack);
-}
-
-INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
-    uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
-    uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
-    void *new_ptr;
-    if (UNLIKELY(!msan_inited)) {
-      new_ptr = AllocateFromLocalPool(copy_size);
-    } else {
-      copy_size = size;
-      new_ptr = msan_malloc(copy_size, &stack);
-    }
-    internal_memcpy(new_ptr, ptr, copy_size);
-    return new_ptr;
-  }
-  return msan_realloc(ptr, size, &stack);
-}
-
-INTERCEPTOR(void *, reallocarray, void *ptr, SIZE_T nmemb, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  return msan_reallocarray(ptr, nmemb, size, &stack);
-}
-
-INTERCEPTOR(void *, malloc, SIZE_T size) {
-  GET_MALLOC_STACK_TRACE;
-  if (UNLIKELY(!msan_inited))
-    // Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym.
-    return AllocateFromLocalPool(size);
-  return msan_malloc(size, &stack);
-}
-
-void __msan_allocated_memory(const void *data, uptr size) {
-  GET_MALLOC_STACK_TRACE;
-  if (flags()->poison_in_malloc) {
-    stack.tag = STACK_TRACE_TAG_POISON;
-    PoisonMemory(data, size, &stack);
-  }
-}
-
-void __msan_copy_shadow(void *dest, const void *src, uptr n) {
-  GET_STORE_STACK_TRACE;
-  MoveShadowAndOrigin(dest, src, n, &stack);
-}
-
-void __sanitizer_dtor_callback(const void *data, uptr size) {
-  GET_MALLOC_STACK_TRACE;
-  if (flags()->poison_in_dtor) {
-    stack.tag = STACK_TRACE_TAG_POISON;
-    PoisonMemory(data, size, &stack);
-  }
-}
-
-template <class Mmap>
-static void *mmap_interceptor(Mmap real_mmap, void *addr, SIZE_T length,
-                              int prot, int flags, int fd, OFF64_T offset) {
-  if (addr && !MEM_IS_APP(addr)) {
-    if (flags & map_fixed) {
-      errno = errno_EINVAL;
-      return (void *)-1;
-    } else {
-      addr = nullptr;
-    }
-  }
-  void *res = real_mmap(addr, length, prot, flags, fd, offset);
-  if (res != (void *)-1) __msan_unpoison(res, RoundUpTo(length, GetPageSize()));
-  return res;
-}
-
-INTERCEPTOR(int, getrusage, int who, void *usage) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(getrusage)(who, usage);
-  if (res == 0) {
-    __msan_unpoison(usage, __sanitizer::struct_rusage_sz);
-  }
-  return res;
-}
-
-class SignalHandlerScope {
- public:
-  SignalHandlerScope() {
-    if (MsanThread *t = GetCurrentThread())
-      t->EnterSignalHandler();
-  }
-  ~SignalHandlerScope() {
-    if (MsanThread *t = GetCurrentThread())
-      t->LeaveSignalHandler();
-  }
-};
-
-// sigactions_mu guarantees atomicity of sigaction() and signal() calls.
-// Access to sigactions[] is gone with relaxed atomics to avoid data race with
-// the signal handler.
-const int kMaxSignals = 1024;
-static atomic_uintptr_t sigactions[kMaxSignals];
-static StaticSpinMutex sigactions_mu;
-
-static void SignalHandler(int signo) {
-  SignalHandlerScope signal_handler_scope;
-  ScopedThreadLocalStateBackup stlsb;
-  UnpoisonParam(1);
-
-  typedef void (*signal_cb)(int x);
-  signal_cb cb =
-      (signal_cb)atomic_load(&sigactions[signo], memory_order_relaxed);
-  cb(signo);
-}
-
-static void SignalAction(int signo, void *si, void *uc) {
-  SignalHandlerScope signal_handler_scope;
-  ScopedThreadLocalStateBackup stlsb;
-  UnpoisonParam(3);
-  __msan_unpoison(si, sizeof(__sanitizer_sigaction));
-  __msan_unpoison(uc, __sanitizer::ucontext_t_sz);
-
-  typedef void (*sigaction_cb)(int, void *, void *);
-  sigaction_cb cb =
-      (sigaction_cb)atomic_load(&sigactions[signo], memory_order_relaxed);
-  cb(signo, si, uc);
-}
-
-static void read_sigaction(const __sanitizer_sigaction *act) {
-  CHECK_UNPOISONED(&act->sa_flags, sizeof(act->sa_flags));
-  if (act->sa_flags & __sanitizer::sa_siginfo)
-    CHECK_UNPOISONED(&act->sigaction, sizeof(act->sigaction));
-  else
-    CHECK_UNPOISONED(&act->handler, sizeof(act->handler));
-  CHECK_UNPOISONED(&act->sa_mask, sizeof(act->sa_mask));
-}
-
-extern "C" int pthread_attr_init(void *attr);
-extern "C" int pthread_attr_destroy(void *attr);
-
-static void *MsanThreadStartFunc(void *arg) {
-  MsanThread *t = (MsanThread *)arg;
-  SetCurrentThread(t);
-  return t->ThreadStart();
-}
-
-INTERCEPTOR(int, pthread_create, void *th, void *attr, void *(*callback)(void*),
-            void * param) {
-  ENSURE_MSAN_INITED(); // for GetTlsSize()
-  __sanitizer_pthread_attr_t myattr;
-  if (!attr) {
-    pthread_attr_init(&myattr);
-    attr = &myattr;
-  }
-
-  AdjustStackSize(attr);
-
-  MsanThread *t = MsanThread::Create(callback, param);
-
-  int res = REAL(pthread_create)(th, attr, MsanThreadStartFunc, t);
-
-  if (attr == &myattr)
-    pthread_attr_destroy(&myattr);
-  if (!res) {
-    __msan_unpoison(th, __sanitizer::pthread_t_sz);
-  }
-  return res;
-}
-
-INTERCEPTOR(int, pthread_key_create, __sanitizer_pthread_key_t *key,
-            void (*dtor)(void *value)) {
-  if (msan_init_is_running) return REAL(pthread_key_create)(key, dtor);
-  ENSURE_MSAN_INITED();
-  int res = REAL(pthread_key_create)(key, dtor);
-  if (!res && key)
-    __msan_unpoison(key, sizeof(*key));
-  return res;
-}
-
-#if SANITIZER_NETBSD
-INTERCEPTOR(void, __libc_thr_keycreate, void *m, void (*dtor)(void *value)) \
-  ALIAS(WRAPPER_NAME(pthread_key_create));
-#endif
-
-INTERCEPTOR(int, pthread_join, void *th, void **retval) {
-  ENSURE_MSAN_INITED();
-  int res = REAL(pthread_join)(th, retval);
-  if (!res && retval)
-    __msan_unpoison(retval, sizeof(*retval));
-  return res;
-}
-
-extern char *tzname[2];
-
-INTERCEPTOR(void, tzset, int fake) {
-  ENSURE_MSAN_INITED();
-  InterceptorScope interceptor_scope;
-  REAL(tzset)(fake);
-  if (tzname[0])
-    __msan_unpoison(tzname[0], REAL(strlen)(tzname[0]) + 1);
-  if (tzname[1])
-    __msan_unpoison(tzname[1], REAL(strlen)(tzname[1]) + 1);
-  return;
-}
-
-struct MSanAtExitRecord {
-  void (*func)(void *arg);
-  void *arg;
-};
-
-struct InterceptorContext {
-  BlockingMutex atexit_mu;
-  Vector<struct MSanAtExitRecord *> AtExitStack;
-
-  InterceptorContext()
-      : AtExitStack() {
-  }
-};
-
-static ALIGNED(64) char interceptor_placeholder[sizeof(InterceptorContext)];
-InterceptorContext *interceptor_ctx() {
-  return reinterpret_cast<InterceptorContext*>(&interceptor_placeholder[0]);
-}
-
-void MSanAtExitWrapper() {
-  MSanAtExitRecord *r;
-  {
-    BlockingMutexLock l(&interceptor_ctx()->atexit_mu);
-
-    uptr element = interceptor_ctx()->AtExitStack.Size() - 1;
-    r = interceptor_ctx()->AtExitStack[element];
-    interceptor_ctx()->AtExitStack.PopBack();
-  }
-
-  UnpoisonParam(1);
-  ((void(*)())r->func)();
-  InternalFree(r);
-}
-
-void MSanCxaAtExitWrapper(void *arg) {
-  UnpoisonParam(1);
-  MSanAtExitRecord *r = (MSanAtExitRecord *)arg;
-  // libc before 2.27 had race which caused occasional double handler execution
-  // https://sourceware.org/ml/libc-alpha/2017-08/msg01204.html
-  if (!r->func)
-    return;
-  r->func(r->arg);
-  r->func = nullptr;
-}
-
-static int setup_at_exit_wrapper(void(*f)(), void *arg, void *dso);
-
-// Unpoison argument shadow for C++ module destructors.
-INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
-            void *dso_handle) {
-  if (msan_init_is_running) return REAL(__cxa_atexit)(func, arg, dso_handle);
-  return setup_at_exit_wrapper((void(*)())func, arg, dso_handle);
-}
-
-// Unpoison argument shadow for C++ module destructors.
-INTERCEPTOR(int, atexit, void (*func)()) {
-  // Avoid calling real atexit as it is unrechable on at least on Linux.
-  if (msan_init_is_running)
-    return REAL(__cxa_atexit)((void (*)(void *a))func, 0, 0);
-  return setup_at_exit_wrapper((void(*)())func, 0, 0);
-}
-
-static int setup_at_exit_wrapper(void(*f)(), void *arg, void *dso) {
-  ENSURE_MSAN_INITED();
-  MSanAtExitRecord *r =
-      (MSanAtExitRecord *)InternalAlloc(sizeof(MSanAtExitRecord));
-  r->func = (void(*)(void *a))f;
-  r->arg = arg;
-  int res;
-  if (!dso) {
-    // NetBSD does not preserve the 2nd argument if dso is equal to 0
-    // Store ctx in a local stack-like structure
-
-    BlockingMutexLock l(&interceptor_ctx()->atexit_mu);
-
-    res = REAL(__cxa_atexit)((void (*)(void *a))MSanAtExitWrapper, 0, 0);
-    if (!res) {
-      interceptor_ctx()->AtExitStack.PushBack(r);
-    }
-  } else {
-    res = REAL(__cxa_atexit)(MSanCxaAtExitWrapper, r, dso);
-  }
-  return res;
-}
-
-static void BeforeFork() {
-  StackDepotLockAll();
-  ChainedOriginDepotLockAll();
-}
-
-static void AfterFork() {
-  ChainedOriginDepotUnlockAll();
-  StackDepotUnlockAll();
-}
-
-INTERCEPTOR(int, fork, void) {
-  ENSURE_MSAN_INITED();
-  BeforeFork();
-  int pid = REAL(fork)();
-  AfterFork();
-  return pid;
-}
-
-// NetBSD ships with openpty(3) in -lutil, that needs to be prebuilt explicitly
-// with MSan.
-#if SANITIZER_LINUX
-INTERCEPTOR(int, openpty, int *aparent, int *aworker, char *name,
-            const void *termp, const void *winp) {
-  ENSURE_MSAN_INITED();
-  InterceptorScope interceptor_scope;
-  int res = REAL(openpty)(aparent, aworker, name, termp, winp);
-  if (!res) {
-    __msan_unpoison(aparent, sizeof(*aparent));
-    __msan_unpoison(aworker, sizeof(*aworker));
-  }
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_OPENPTY INTERCEPT_FUNCTION(openpty)
-#else
-#define MSAN_MAYBE_INTERCEPT_OPENPTY
-#endif
-
-// NetBSD ships with forkpty(3) in -lutil, that needs to be prebuilt explicitly
-// with MSan.
-#if SANITIZER_LINUX
-INTERCEPTOR(int, forkpty, int *aparent, char *name, const void *termp,
-            const void *winp) {
-  ENSURE_MSAN_INITED();
-  InterceptorScope interceptor_scope;
-  int res = REAL(forkpty)(aparent, name, termp, winp);
-  if (res != -1)
-    __msan_unpoison(aparent, sizeof(*aparent));
-  return res;
-}
-#define MSAN_MAYBE_INTERCEPT_FORKPTY INTERCEPT_FUNCTION(forkpty)
-#else
-#define MSAN_MAYBE_INTERCEPT_FORKPTY
-#endif
-
-struct MSanInterceptorContext {
-  bool in_interceptor_scope;
-};
-
-namespace __msan {
-
-int OnExit() {
-  // FIXME: ask frontend whether we need to return failure.
-  return 0;
-}
-
-} // namespace __msan
-
-// A version of CHECK_UNPOISONED using a saved scope value. Used in common
-// interceptors.
-#define CHECK_UNPOISONED_CTX(ctx, x, n)                         \
-  do {                                                          \
-    if (!((MSanInterceptorContext *)ctx)->in_interceptor_scope) \
-      CHECK_UNPOISONED_0(x, n);                                 \
-  } while (0)
-
-#define MSAN_INTERCEPT_FUNC(name)                                        \
-  do {                                                                   \
-    if (!INTERCEPT_FUNCTION(name))                                       \
-      VReport(1, "MemorySanitizer: failed to intercept '%s'\n'", #name); \
-  } while (0)
-
-#define MSAN_INTERCEPT_FUNC_VER(name, ver)                                 \
-  do {                                                                     \
-    if (!INTERCEPT_FUNCTION_VER(name, ver))                                \
-      VReport(1, "MemorySanitizer: failed to intercept '%s@@%s'\n", #name, \
-              #ver);                                                       \
-  } while (0)
-
-#define COMMON_INTERCEPT_FUNCTION(name) MSAN_INTERCEPT_FUNC(name)
-#define COMMON_INTERCEPT_FUNCTION_VER(name, ver)                          \
-  MSAN_INTERCEPT_FUNC_VER(name, ver)
-#define COMMON_INTERCEPTOR_UNPOISON_PARAM(count)  \
-  UnpoisonParam(count)
-#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \
-  __msan_unpoison(ptr, size)
-#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
-  CHECK_UNPOISONED_CTX(ctx, ptr, size)
-#define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ptr, size) \
-  __msan_unpoison(ptr, size)
-#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                  \
-  if (msan_init_is_running) return REAL(func)(__VA_ARGS__);       \
-  ENSURE_MSAN_INITED();                                           \
-  MSanInterceptorContext msan_ctx = {IsInInterceptorScope()};     \
-  ctx = (void *)&msan_ctx;                                        \
-  (void)ctx;                                                      \
-  InterceptorScope interceptor_scope;                             \
-  __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */
-#define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \
-  do {                                            \
-  } while (false)
-#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
-  do {                                         \
-  } while (false)
-#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
-  do {                                         \
-  } while (false)
-#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
-  do {                                                      \
-  } while (false)
-#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) \
-  do {                                                \
-  } while (false)  // FIXME
-#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
-  do {                                                         \
-  } while (false)  // FIXME
-#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
-#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
-#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle)                    \
-  do {                                                                         \
-    link_map *map = GET_LINK_MAP_BY_DLOPEN_HANDLE((handle));                   \
-    if (filename && map)                                                       \
-      ForEachMappedRegion(map, __msan_unpoison);                               \
-  } while (false)
-
-#define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end)                           \
-  if (MsanThread *t = GetCurrentThread()) {                                    \
-    *begin = t->tls_begin();                                                   \
-    *end = t->tls_end();                                                       \
-  } else {                                                                     \
-    *begin = *end = 0;                                                         \
-  }
-
-#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \
-  {                                                         \
-    (void)ctx;                                              \
-    return __msan_memset(block, c, size);                   \
-  }
-#define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size) \
-  {                                                          \
-    (void)ctx;                                               \
-    return __msan_memmove(to, from, size);                   \
-  }
-#define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size) \
-  {                                                         \
-    (void)ctx;                                              \
-    return __msan_memcpy(to, from, size);                   \
-  }
-
-#define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) \
-  do {                                                      \
-    GET_STORE_STACK_TRACE;                                  \
-    CopyShadowAndOrigin(to, from, size, &stack);            \
-    __msan_unpoison(to + size, 1);                          \
-  } while (false)
-
-#define COMMON_INTERCEPTOR_MMAP_IMPL(ctx, mmap, addr, length, prot, flags, fd, \
-                                     offset)                                   \
-  do {                                                                         \
-    return mmap_interceptor(REAL(mmap), addr, sz, prot, flags, fd, off);       \
-  } while (false)
-
-#include "sanitizer_common/sanitizer_platform_interceptors.h"
-#include "sanitizer_common/sanitizer_common_interceptors.inc"
-
-static uptr signal_impl(int signo, uptr cb);
-static int sigaction_impl(int signo, const __sanitizer_sigaction *act,
-                          __sanitizer_sigaction *oldact);
-
-#define SIGNAL_INTERCEPTOR_SIGACTION_IMPL(signo, act, oldact) \
-  { return sigaction_impl(signo, act, oldact); }
-
-#define SIGNAL_INTERCEPTOR_SIGNAL_IMPL(func, signo, handler) \
-  {                                                          \
-    handler = signal_impl(signo, handler);                   \
-    InterceptorScope interceptor_scope;                      \
-    return REAL(func)(signo, handler);                       \
-  }
-
-#include "sanitizer_common/sanitizer_signal_interceptors.inc"
-
-static int sigaction_impl(int signo, const __sanitizer_sigaction *act,
-                          __sanitizer_sigaction *oldact) {
-  ENSURE_MSAN_INITED();
-  if (act) read_sigaction(act);
-  int res;
-  if (flags()->wrap_signals) {
-    SpinMutexLock lock(&sigactions_mu);
-    CHECK_LT(signo, kMaxSignals);
-    uptr old_cb = atomic_load(&sigactions[signo], memory_order_relaxed);
-    __sanitizer_sigaction new_act;
-    __sanitizer_sigaction *pnew_act = act ? &new_act : nullptr;
-    if (act) {
-      REAL(memcpy)(pnew_act, act, sizeof(__sanitizer_sigaction));
-      uptr cb = (uptr)pnew_act->sigaction;
-      uptr new_cb = (pnew_act->sa_flags & __sanitizer::sa_siginfo)
-                        ? (uptr)SignalAction
-                        : (uptr)SignalHandler;
-      if (cb != __sanitizer::sig_ign && cb != __sanitizer::sig_dfl) {
-        atomic_store(&sigactions[signo], cb, memory_order_relaxed);
-        pnew_act->sigaction = (decltype(pnew_act->sigaction))new_cb;
-      }
-    }
-    res = REAL(SIGACTION_SYMNAME)(signo, pnew_act, oldact);
-    if (res == 0 && oldact) {
-      uptr cb = (uptr)oldact->sigaction;
-      if (cb == (uptr)SignalAction || cb == (uptr)SignalHandler) {
-        oldact->sigaction = (decltype(oldact->sigaction))old_cb;
-      }
-    }
-  } else {
-    res = REAL(SIGACTION_SYMNAME)(signo, act, oldact);
-  }
-
-  if (res == 0 && oldact) {
-    __msan_unpoison(oldact, sizeof(__sanitizer_sigaction));
-  }
-  return res;
-}
-
-static uptr signal_impl(int signo, uptr cb) {
-  ENSURE_MSAN_INITED();
-  if (flags()->wrap_signals) {
-    CHECK_LT(signo, kMaxSignals);
-    SpinMutexLock lock(&sigactions_mu);
-    if (cb != __sanitizer::sig_ign && cb != __sanitizer::sig_dfl) {
-      atomic_store(&sigactions[signo], cb, memory_order_relaxed);
-      cb = (uptr)&SignalHandler;
-    }
-  }
-  return cb;
-}
-
-#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) CHECK_UNPOISONED(p, s)
-#define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) \
-  do {                                       \
-  } while (false)
-#define COMMON_SYSCALL_POST_READ_RANGE(p, s) \
-  do {                                       \
-  } while (false)
-#define COMMON_SYSCALL_POST_WRITE_RANGE(p, s) __msan_unpoison(p, s)
-#include "sanitizer_common/sanitizer_common_syscalls.inc"
-#include "sanitizer_common/sanitizer_syscalls_netbsd.inc"
-
-struct dlinfo {
-  char *dli_fname;
-  void *dli_fbase;
-  char *dli_sname;
-  void *dli_saddr;
-};
-
-INTERCEPTOR(int, dladdr, void *addr, dlinfo *info) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, dladdr, addr, info);
-  int res = REAL(dladdr)(addr, info);
-  if (res != 0) {
-    __msan_unpoison(info, sizeof(*info));
-    if (info->dli_fname)
-      __msan_unpoison(info->dli_fname, REAL(strlen)(info->dli_fname) + 1);
-    if (info->dli_sname)
-      __msan_unpoison(info->dli_sname, REAL(strlen)(info->dli_sname) + 1);
-  }
-  return res;
-}
-
-INTERCEPTOR(char *, dlerror, int fake) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, dlerror, fake);
-  char *res = REAL(dlerror)(fake);
-  if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
-  return res;
-}
-
-typedef int (*dl_iterate_phdr_cb)(__sanitizer_dl_phdr_info *info, SIZE_T size,
-                                  void *data);
-struct dl_iterate_phdr_data {
-  dl_iterate_phdr_cb callback;
-  void *data;
-};
-
-static int msan_dl_iterate_phdr_cb(__sanitizer_dl_phdr_info *info, SIZE_T size,
-                                   void *data) {
-  if (info) {
-    __msan_unpoison(info, size);
-    if (info->dlpi_phdr && info->dlpi_phnum)
-      __msan_unpoison(info->dlpi_phdr, struct_ElfW_Phdr_sz * info->dlpi_phnum);
-    if (info->dlpi_name)
-      __msan_unpoison(info->dlpi_name, REAL(strlen)(info->dlpi_name) + 1);
-  }
-  dl_iterate_phdr_data *cbdata = (dl_iterate_phdr_data *)data;
-  UnpoisonParam(3);
-  return cbdata->callback(info, size, cbdata->data);
-}
-
-INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
-  ENSURE_MSAN_INITED();
-  void *p = REAL(shmat)(shmid, shmaddr, shmflg);
-  if (p != (void *)-1) {
-    __sanitizer_shmid_ds ds;
-    int res = REAL(shmctl)(shmid, shmctl_ipc_stat, &ds);
-    if (!res) {
-      __msan_unpoison(p, ds.shm_segsz);
-    }
-  }
-  return p;
-}
-
-INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
-  void *ctx;
-  COMMON_INTERCEPTOR_ENTER(ctx, dl_iterate_phdr, callback, data);
-  dl_iterate_phdr_data cbdata;
-  cbdata.callback = callback;
-  cbdata.data = data;
-  int res = REAL(dl_iterate_phdr)(msan_dl_iterate_phdr_cb, (void *)&cbdata);
-  return res;
-}
-
-// wchar_t *wcschr(const wchar_t *wcs, wchar_t wc);
-INTERCEPTOR(wchar_t *, wcschr, void *s, wchar_t wc, void *ps) {
-  ENSURE_MSAN_INITED();
-  wchar_t *res = REAL(wcschr)(s, wc, ps);
-  return res;
-}
-
-// wchar_t *wcscpy(wchar_t *dest, const wchar_t *src);
-INTERCEPTOR(wchar_t *, wcscpy, wchar_t *dest, const wchar_t *src) {
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  wchar_t *res = REAL(wcscpy)(dest, src);
-  CopyShadowAndOrigin(dest, src, sizeof(wchar_t) * (REAL(wcslen)(src) + 1),
-                      &stack);
-  return res;
-}
-
-INTERCEPTOR(wchar_t *, wcsncpy, wchar_t *dest, const wchar_t *src,
-            SIZE_T n) {  // NOLINT
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  SIZE_T copy_size = REAL(wcsnlen)(src, n);
-  if (copy_size < n) copy_size++;           // trailing \0
-  wchar_t *res = REAL(wcsncpy)(dest, src, n);  // NOLINT
-  CopyShadowAndOrigin(dest, src, copy_size * sizeof(wchar_t), &stack);
-  __msan_unpoison(dest + copy_size, (n - copy_size) * sizeof(wchar_t));
-  return res;
-}
-
-// These interface functions reside here so that they can use
-// REAL(memset), etc.
-void __msan_unpoison(const void *a, uptr size) {
-  if (!MEM_IS_APP(a)) return;
-  SetShadow(a, size, 0);
-}
-
-void __msan_poison(const void *a, uptr size) {
-  if (!MEM_IS_APP(a)) return;
-  SetShadow(a, size, __msan::flags()->poison_heap_with_zeroes ? 0 : -1);
-}
-
-void __msan_poison_stack(void *a, uptr size) {
-  if (!MEM_IS_APP(a)) return;
-  SetShadow(a, size, __msan::flags()->poison_stack_with_zeroes ? 0 : -1);
-}
-
-void __msan_unpoison_param(uptr n) { UnpoisonParam(n); }
-
-void __msan_clear_and_unpoison(void *a, uptr size) {
-  REAL(memset)(a, 0, size);
-  SetShadow(a, size, 0);
-}
-
-void *__msan_memcpy(void *dest, const void *src, SIZE_T n) {
-  if (!msan_inited) return internal_memcpy(dest, src, n);
-  if (msan_init_is_running || __msan::IsInSymbolizer())
-    return REAL(memcpy)(dest, src, n);
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  void *res = REAL(memcpy)(dest, src, n);
-  CopyShadowAndOrigin(dest, src, n, &stack);
-  return res;
-}
-
-void *__msan_memset(void *s, int c, SIZE_T n) {
-  if (!msan_inited) return internal_memset(s, c, n);
-  if (msan_init_is_running) return REAL(memset)(s, c, n);
-  ENSURE_MSAN_INITED();
-  void *res = REAL(memset)(s, c, n);
-  __msan_unpoison(s, n);
-  return res;
-}
-
-void *__msan_memmove(void *dest, const void *src, SIZE_T n) {
-  if (!msan_inited) return internal_memmove(dest, src, n);
-  if (msan_init_is_running) return REAL(memmove)(dest, src, n);
-  ENSURE_MSAN_INITED();
-  GET_STORE_STACK_TRACE;
-  void *res = REAL(memmove)(dest, src, n);
-  MoveShadowAndOrigin(dest, src, n, &stack);
-  return res;
-}
-
-void __msan_unpoison_string(const char* s) {
-  if (!MEM_IS_APP(s)) return;
-  __msan_unpoison(s, REAL(strlen)(s) + 1);
-}
-
-namespace __msan {
-
-void InitializeInterceptors() {
-  static int inited = 0;
-  CHECK_EQ(inited, 0);
-
-  new(interceptor_ctx()) InterceptorContext();
-
-  InitializeCommonInterceptors();
-  InitializeSignalInterceptors();
-
-  INTERCEPT_FUNCTION(posix_memalign);
-  MSAN_MAYBE_INTERCEPT_MEMALIGN;
-  MSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN;
-  INTERCEPT_FUNCTION(valloc);
-  MSAN_MAYBE_INTERCEPT_PVALLOC;
-  INTERCEPT_FUNCTION(malloc);
-  INTERCEPT_FUNCTION(calloc);
-  INTERCEPT_FUNCTION(realloc);
-  INTERCEPT_FUNCTION(reallocarray);
-  INTERCEPT_FUNCTION(free);
-  MSAN_MAYBE_INTERCEPT_CFREE;
-  MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
-  MSAN_MAYBE_INTERCEPT_MALLINFO;
-  MSAN_MAYBE_INTERCEPT_MALLOPT;
-  MSAN_MAYBE_INTERCEPT_MALLOC_STATS;
-  INTERCEPT_FUNCTION(fread);
-  MSAN_MAYBE_INTERCEPT_FREAD_UNLOCKED;
-  INTERCEPT_FUNCTION(memccpy);
-  MSAN_MAYBE_INTERCEPT_MEMPCPY;
-  INTERCEPT_FUNCTION(bcopy);
-  INTERCEPT_FUNCTION(wmemset);
-  INTERCEPT_FUNCTION(wmemcpy);
-  MSAN_MAYBE_INTERCEPT_WMEMPCPY;
-  INTERCEPT_FUNCTION(wmemmove);
-  INTERCEPT_FUNCTION(strcpy);  // NOLINT
-  MSAN_MAYBE_INTERCEPT_STPCPY;  // NOLINT
-  INTERCEPT_FUNCTION(strdup);
-  MSAN_MAYBE_INTERCEPT___STRDUP;
-  INTERCEPT_FUNCTION(strncpy);  // NOLINT
-  MSAN_MAYBE_INTERCEPT_GCVT;
-  INTERCEPT_FUNCTION(strcat);  // NOLINT
-  INTERCEPT_FUNCTION(strncat);  // NOLINT
-  INTERCEPT_STRTO(strtod);
-  INTERCEPT_STRTO(strtof);
-  INTERCEPT_STRTO(strtold);
-  INTERCEPT_STRTO(strtol);
-  INTERCEPT_STRTO(strtoul);
-  INTERCEPT_STRTO(strtoll);
-  INTERCEPT_STRTO(strtoull);
-  INTERCEPT_STRTO(strtouq);
-  INTERCEPT_STRTO(wcstod);
-  INTERCEPT_STRTO(wcstof);
-  INTERCEPT_STRTO(wcstold);
-  INTERCEPT_STRTO(wcstol);
-  INTERCEPT_STRTO(wcstoul);
-  INTERCEPT_STRTO(wcstoll);
-  INTERCEPT_STRTO(wcstoull);
-#ifdef SANITIZER_NLDBL_VERSION
-  INTERCEPT_FUNCTION_VER(vswprintf, SANITIZER_NLDBL_VERSION);
-  INTERCEPT_FUNCTION_VER(swprintf, SANITIZER_NLDBL_VERSION);
-#else
-  INTERCEPT_FUNCTION(vswprintf);
-  INTERCEPT_FUNCTION(swprintf);
-#endif
-  INTERCEPT_FUNCTION(strftime);
-  INTERCEPT_FUNCTION(strftime_l);
-  MSAN_MAYBE_INTERCEPT___STRFTIME_L;
-  INTERCEPT_FUNCTION(wcsftime);
-  INTERCEPT_FUNCTION(wcsftime_l);
-  MSAN_MAYBE_INTERCEPT___WCSFTIME_L;
-  INTERCEPT_FUNCTION(mbtowc);
-  INTERCEPT_FUNCTION(mbrtowc);
-  INTERCEPT_FUNCTION(wcslen);
-  INTERCEPT_FUNCTION(wcsnlen);
-  INTERCEPT_FUNCTION(wcschr);
-  INTERCEPT_FUNCTION(wcscpy);
-  INTERCEPT_FUNCTION(wcsncpy);
-  INTERCEPT_FUNCTION(wcscmp);
-  INTERCEPT_FUNCTION(getenv);
-  INTERCEPT_FUNCTION(setenv);
-  INTERCEPT_FUNCTION(putenv);
-  INTERCEPT_FUNCTION(gettimeofday);
-  MSAN_MAYBE_INTERCEPT_FCVT;
-  MSAN_MAYBE_INTERCEPT_FSTAT;
-  MSAN_MAYBE_INTERCEPT___FXSTAT;
-  MSAN_INTERCEPT_FSTATAT;
-  MSAN_MAYBE_INTERCEPT___FXSTAT64;
-  MSAN_MAYBE_INTERCEPT___FXSTATAT64;
-  INTERCEPT_FUNCTION(pipe);
-  INTERCEPT_FUNCTION(pipe2);
-  INTERCEPT_FUNCTION(socketpair);
-  MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED;
-  INTERCEPT_FUNCTION(getrlimit);
-  MSAN_MAYBE_INTERCEPT_GETRLIMIT64;
-  MSAN_MAYBE_INTERCEPT_PRLIMIT;
-  MSAN_MAYBE_INTERCEPT_PRLIMIT64;
-  MSAN_INTERCEPT_UNAME;
-  INTERCEPT_FUNCTION(gethostname);
-  MSAN_MAYBE_INTERCEPT_EPOLL_WAIT;
-  MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT;
-  INTERCEPT_FUNCTION(dladdr);
-  INTERCEPT_FUNCTION(dlerror);
-  INTERCEPT_FUNCTION(dl_iterate_phdr);
-  INTERCEPT_FUNCTION(getrusage);
-#if defined(__mips__)
-  INTERCEPT_FUNCTION_VER(pthread_create, "GLIBC_2.2");
-#else
-  INTERCEPT_FUNCTION(pthread_create);
-#endif
-  INTERCEPT_FUNCTION(pthread_key_create);
-
-#if SANITIZER_NETBSD
-  INTERCEPT_FUNCTION(__libc_thr_keycreate);
-#endif
-
-  INTERCEPT_FUNCTION(pthread_join);
-  INTERCEPT_FUNCTION(tzset);
-  INTERCEPT_FUNCTION(atexit);
-  INTERCEPT_FUNCTION(__cxa_atexit);
-  INTERCEPT_FUNCTION(shmat);
-  INTERCEPT_FUNCTION(fork);
-  MSAN_MAYBE_INTERCEPT_OPENPTY;
-  MSAN_MAYBE_INTERCEPT_FORKPTY;
-
-  inited = 1;
-}
-} // namespace __msan

Copied: compiler-rt/trunk/lib/msan/msan_interceptors.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_interceptors.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cpp?p2=compiler-rt/trunk/lib/msan/msan_interceptors.cpp&p1=compiler-rt/trunk/lib/msan/msan_interceptors.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_interceptors.cc ----------------------------------------------===//
+//===-- msan_interceptors.cpp ---------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_linux.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_linux.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_linux.cc (removed)
@@ -1,262 +0,0 @@
-//===-- msan_linux.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// Linux-, NetBSD- and FreeBSD-specific code.
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
-
-#include "msan.h"
-#include "msan_report.h"
-#include "msan_thread.h"
-
-#include <elf.h>
-#include <link.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-#include <unwind.h>
-#include <execinfo.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_procmaps.h"
-
-namespace __msan {
-
-void ReportMapRange(const char *descr, uptr beg, uptr size) {
-  if (size > 0) {
-    uptr end = beg + size - 1;
-    VPrintf(1, "%s : %p - %p\n", descr, beg, end);
-  }
-}
-
-static bool CheckMemoryRangeAvailability(uptr beg, uptr size) {
-  if (size > 0) {
-    uptr end = beg + size - 1;
-    if (!MemoryRangeIsAvailable(beg, end)) {
-      Printf("FATAL: Memory range %p - %p is not available.\n", beg, end);
-      return false;
-    }
-  }
-  return true;
-}
-
-static bool ProtectMemoryRange(uptr beg, uptr size, const char *name) {
-  if (size > 0) {
-    void *addr = MmapFixedNoAccess(beg, size, name);
-    if (beg == 0 && addr) {
-      // Depending on the kernel configuration, we may not be able to protect
-      // the page at address zero.
-      uptr gap = 16 * GetPageSizeCached();
-      beg += gap;
-      size -= gap;
-      addr = MmapFixedNoAccess(beg, size, name);
-    }
-    if ((uptr)addr != beg) {
-      uptr end = beg + size - 1;
-      Printf("FATAL: Cannot protect memory range %p - %p (%s).\n", beg, end,
-             name);
-      return false;
-    }
-  }
-  return true;
-}
-
-static void CheckMemoryLayoutSanity() {
-  uptr prev_end = 0;
-  for (unsigned i = 0; i < kMemoryLayoutSize; ++i) {
-    uptr start = kMemoryLayout[i].start;
-    uptr end = kMemoryLayout[i].end;
-    MappingDesc::Type type = kMemoryLayout[i].type;
-    CHECK_LT(start, end);
-    CHECK_EQ(prev_end, start);
-    CHECK(addr_is_type(start, type));
-    CHECK(addr_is_type((start + end) / 2, type));
-    CHECK(addr_is_type(end - 1, type));
-    if (type == MappingDesc::APP) {
-      uptr addr = start;
-      CHECK(MEM_IS_SHADOW(MEM_TO_SHADOW(addr)));
-      CHECK(MEM_IS_ORIGIN(MEM_TO_ORIGIN(addr)));
-      CHECK_EQ(MEM_TO_ORIGIN(addr), SHADOW_TO_ORIGIN(MEM_TO_SHADOW(addr)));
-
-      addr = (start + end) / 2;
-      CHECK(MEM_IS_SHADOW(MEM_TO_SHADOW(addr)));
-      CHECK(MEM_IS_ORIGIN(MEM_TO_ORIGIN(addr)));
-      CHECK_EQ(MEM_TO_ORIGIN(addr), SHADOW_TO_ORIGIN(MEM_TO_SHADOW(addr)));
-
-      addr = end - 1;
-      CHECK(MEM_IS_SHADOW(MEM_TO_SHADOW(addr)));
-      CHECK(MEM_IS_ORIGIN(MEM_TO_ORIGIN(addr)));
-      CHECK_EQ(MEM_TO_ORIGIN(addr), SHADOW_TO_ORIGIN(MEM_TO_SHADOW(addr)));
-    }
-    prev_end = end;
-  }
-}
-
-bool InitShadow(bool init_origins) {
-  // Let user know mapping parameters first.
-  VPrintf(1, "__msan_init %p\n", &__msan_init);
-  for (unsigned i = 0; i < kMemoryLayoutSize; ++i)
-    VPrintf(1, "%s: %zx - %zx\n", kMemoryLayout[i].name, kMemoryLayout[i].start,
-            kMemoryLayout[i].end - 1);
-
-  CheckMemoryLayoutSanity();
-
-  if (!MEM_IS_APP(&__msan_init)) {
-    Printf("FATAL: Code %p is out of application range. Non-PIE build?\n",
-           (uptr)&__msan_init);
-    return false;
-  }
-
-  const uptr maxVirtualAddress = GetMaxUserVirtualAddress();
-
-  for (unsigned i = 0; i < kMemoryLayoutSize; ++i) {
-    uptr start = kMemoryLayout[i].start;
-    uptr end = kMemoryLayout[i].end;
-    uptr size= end - start;
-    MappingDesc::Type type = kMemoryLayout[i].type;
-
-    // Check if the segment should be mapped based on platform constraints.
-    if (start >= maxVirtualAddress)
-      continue;
-
-    bool map = type == MappingDesc::SHADOW ||
-               (init_origins && type == MappingDesc::ORIGIN);
-    bool protect = type == MappingDesc::INVALID ||
-                   (!init_origins && type == MappingDesc::ORIGIN);
-    CHECK(!(map && protect));
-    if (!map && !protect)
-      CHECK(type == MappingDesc::APP);
-    if (map) {
-      if (!CheckMemoryRangeAvailability(start, size))
-        return false;
-      if (!MmapFixedNoReserve(start, size, kMemoryLayout[i].name))
-        return false;
-      if (common_flags()->use_madv_dontdump)
-        DontDumpShadowMemory(start, size);
-    }
-    if (protect) {
-      if (!CheckMemoryRangeAvailability(start, size))
-        return false;
-      if (!ProtectMemoryRange(start, size, kMemoryLayout[i].name))
-        return false;
-    }
-  }
-
-  return true;
-}
-
-static void MsanAtExit(void) {
-  if (flags()->print_stats && (flags()->atexit || msan_report_count > 0))
-    ReportStats();
-  if (msan_report_count > 0) {
-    ReportAtExitStatistics();
-    if (common_flags()->exitcode)
-      internal__exit(common_flags()->exitcode);
-  }
-}
-
-void InstallAtExitHandler() {
-  atexit(MsanAtExit);
-}
-
-// ---------------------- TSD ---------------- {{{1
-
-#if SANITIZER_NETBSD
-// Thread Static Data cannot be used in early init on NetBSD.
-// Reuse the MSan TSD API for compatibility with existing code
-// with an alternative implementation.
-
-static void (*tsd_destructor)(void *tsd) = nullptr;
-
-struct tsd_key {
-  tsd_key() : key(nullptr) {}
-  ~tsd_key() {
-    CHECK(tsd_destructor);
-    if (key)
-      (*tsd_destructor)(key);
-  }
-  MsanThread *key;
-};
-
-static thread_local struct tsd_key key;
-
-void MsanTSDInit(void (*destructor)(void *tsd)) {
-  CHECK(!tsd_destructor);
-  tsd_destructor = destructor;
-}
-
-MsanThread *GetCurrentThread() {
-  CHECK(tsd_destructor);
-  return key.key;
-}
-
-void SetCurrentThread(MsanThread *tsd) {
-  CHECK(tsd_destructor);
-  CHECK(tsd);
-  CHECK(!key.key);
-  key.key = tsd;
-}
-
-void MsanTSDDtor(void *tsd) {
-  CHECK(tsd_destructor);
-  CHECK_EQ(key.key, tsd);
-  key.key = nullptr;
-  // Make sure that signal handler can not see a stale current thread pointer.
-  atomic_signal_fence(memory_order_seq_cst);
-  MsanThread::TSDDtor(tsd);
-}
-#else
-static pthread_key_t tsd_key;
-static bool tsd_key_inited = false;
-
-void MsanTSDInit(void (*destructor)(void *tsd)) {
-  CHECK(!tsd_key_inited);
-  tsd_key_inited = true;
-  CHECK_EQ(0, pthread_key_create(&tsd_key, destructor));
-}
-
-static THREADLOCAL MsanThread* msan_current_thread;
-
-MsanThread *GetCurrentThread() {
-  return msan_current_thread;
-}
-
-void SetCurrentThread(MsanThread *t) {
-  // Make sure we do not reset the current MsanThread.
-  CHECK_EQ(0, msan_current_thread);
-  msan_current_thread = t;
-  // Make sure that MsanTSDDtor gets called at the end.
-  CHECK(tsd_key_inited);
-  pthread_setspecific(tsd_key, (void *)t);
-}
-
-void MsanTSDDtor(void *tsd) {
-  MsanThread *t = (MsanThread*)tsd;
-  if (t->destructor_iterations_ > 1) {
-    t->destructor_iterations_--;
-    CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
-    return;
-  }
-  msan_current_thread = nullptr;
-  // Make sure that signal handler can not see a stale current thread pointer.
-  atomic_signal_fence(memory_order_seq_cst);
-  MsanThread::TSDDtor(tsd);
-}
-#endif
-
-} // namespace __msan
-
-#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD

Copied: compiler-rt/trunk/lib/msan/msan_linux.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_linux.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_linux.cpp?p2=compiler-rt/trunk/lib/msan/msan_linux.cpp&p1=compiler-rt/trunk/lib/msan/msan_linux.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_linux.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_linux.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_linux.cc -----------------------------------------------------===//
+//===-- msan_linux.cpp ----------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_new_delete.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_new_delete.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_new_delete.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_new_delete.cc (removed)
@@ -1,108 +0,0 @@
-//===-- msan_new_delete.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// Interceptors for operators new and delete.
-//===----------------------------------------------------------------------===//
-
-#include "msan.h"
-#include "interception/interception.h"
-#include "sanitizer_common/sanitizer_allocator.h"
-#include "sanitizer_common/sanitizer_allocator_report.h"
-
-#if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
-
-#include <stddef.h>
-
-using namespace __msan;  // NOLINT
-
-// Fake std::nothrow_t and std::align_val_t to avoid including <new>.
-namespace std {
-  struct nothrow_t {};
-  enum class align_val_t: size_t {};
-}  // namespace std
-
-
-// TODO(alekseys): throw std::bad_alloc instead of dying on OOM.
-#define OPERATOR_NEW_BODY(nothrow) \
-  GET_MALLOC_STACK_TRACE; \
-  void *res = msan_malloc(size, &stack);\
-  if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
-  return res
-#define OPERATOR_NEW_BODY_ALIGN(nothrow) \
-  GET_MALLOC_STACK_TRACE;\
-  void *res = msan_memalign((uptr)align, size, &stack);\
-  if (!nothrow && UNLIKELY(!res)) ReportOutOfMemory(size, &stack);\
-  return res;
-
-INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size, std::nothrow_t const&) {
-  OPERATOR_NEW_BODY(true /*nothrow*/);
-}
-INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size, std::nothrow_t const&) {
-  OPERATOR_NEW_BODY(true /*nothrow*/);
-}
-INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size, std::align_val_t align)
-{ OPERATOR_NEW_BODY_ALIGN(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size, std::align_val_t align)
-{ OPERATOR_NEW_BODY_ALIGN(false /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size, std::align_val_t align, std::nothrow_t const&)
-{ OPERATOR_NEW_BODY_ALIGN(true /*nothrow*/); }
-INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size, std::align_val_t align, std::nothrow_t const&)
-{ OPERATOR_NEW_BODY_ALIGN(true /*nothrow*/); }
-
-#define OPERATOR_DELETE_BODY \
-  GET_MALLOC_STACK_TRACE; \
-  if (ptr) MsanDeallocate(&stack, ptr)
-
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr, std::nothrow_t const&) {
-  OPERATOR_DELETE_BODY;
-}
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr, size_t size) NOEXCEPT { OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr, size_t size) NOEXCEPT
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr, std::align_val_t align) NOEXCEPT
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr, std::align_val_t align) NOEXCEPT
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr, std::align_val_t align, std::nothrow_t const&)
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr, std::align_val_t align, std::nothrow_t const&)
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete(void *ptr, size_t size, std::align_val_t align) NOEXCEPT
-{ OPERATOR_DELETE_BODY; }
-INTERCEPTOR_ATTRIBUTE
-void operator delete[](void *ptr, size_t size, std::align_val_t align) NOEXCEPT
-{ OPERATOR_DELETE_BODY; }
-
-
-#endif // MSAN_REPLACE_OPERATORS_NEW_AND_DELETE

Copied: compiler-rt/trunk/lib/msan/msan_new_delete.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_new_delete.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_new_delete.cpp?p2=compiler-rt/trunk/lib/msan/msan_new_delete.cpp&p1=compiler-rt/trunk/lib/msan/msan_new_delete.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_new_delete.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_new_delete.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_new_delete.cc ------------------------------------------------===//
+//===-- msan_new_delete.cpp -----------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_poisoning.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_poisoning.cc (removed)
@@ -1,174 +0,0 @@
-//===-- msan_poisoning.cc ---------------------------------------*- C++ -*-===//
-//
-// 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 MemorySanitizer.
-//
-//===----------------------------------------------------------------------===//
-
-#include "msan_poisoning.h"
-
-#include "interception/interception.h"
-#include "msan_origin.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-DECLARE_REAL(void *, memset, void *dest, int c, uptr n)
-DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n)
-DECLARE_REAL(void *, memmove, void *dest, const void *src, uptr n)
-
-namespace __msan {
-
-u32 GetOriginIfPoisoned(uptr addr, uptr size) {
-  unsigned char *s = (unsigned char *)MEM_TO_SHADOW(addr);
-  for (uptr i = 0; i < size; ++i)
-    if (s[i]) return *(u32 *)SHADOW_TO_ORIGIN(((uptr)s + i) & ~3UL);
-  return 0;
-}
-
-void SetOriginIfPoisoned(uptr addr, uptr src_shadow, uptr size,
-                         u32 src_origin) {
-  uptr dst_s = MEM_TO_SHADOW(addr);
-  uptr src_s = src_shadow;
-  uptr src_s_end = src_s + size;
-
-  for (; src_s < src_s_end; ++dst_s, ++src_s)
-    if (*(u8 *)src_s) *(u32 *)SHADOW_TO_ORIGIN(dst_s & ~3UL) = src_origin;
-}
-
-void CopyOrigin(const void *dst, const void *src, uptr size,
-                StackTrace *stack) {
-  if (!MEM_IS_APP(dst) || !MEM_IS_APP(src)) return;
-
-  uptr d = (uptr)dst;
-  uptr beg = d & ~3UL;
-  // Copy left unaligned origin if that memory is poisoned.
-  if (beg < d) {
-    u32 o = GetOriginIfPoisoned((uptr)src, d - beg);
-    if (o) {
-      if (__msan_get_track_origins() > 1) o = ChainOrigin(o, stack);
-      *(u32 *)MEM_TO_ORIGIN(beg) = o;
-    }
-    beg += 4;
-  }
-
-  uptr end = (d + size) & ~3UL;
-  // If both ends fall into the same 4-byte slot, we are done.
-  if (end < beg) return;
-
-  // Copy right unaligned origin if that memory is poisoned.
-  if (end < d + size) {
-    u32 o = GetOriginIfPoisoned((uptr)src + (end - d), (d + size) - end);
-    if (o) {
-      if (__msan_get_track_origins() > 1) o = ChainOrigin(o, stack);
-      *(u32 *)MEM_TO_ORIGIN(end) = o;
-    }
-  }
-
-  if (beg < end) {
-    // Align src up.
-    uptr s = ((uptr)src + 3) & ~3UL;
-    // FIXME: factor out to msan_copy_origin_aligned
-    if (__msan_get_track_origins() > 1) {
-      u32 *src = (u32 *)MEM_TO_ORIGIN(s);
-      u32 *src_s = (u32 *)MEM_TO_SHADOW(s);
-      u32 *src_end = (u32 *)MEM_TO_ORIGIN(s + (end - beg));
-      u32 *dst = (u32 *)MEM_TO_ORIGIN(beg);
-      u32 src_o = 0;
-      u32 dst_o = 0;
-      for (; src < src_end; ++src, ++src_s, ++dst) {
-        if (!*src_s) continue;
-        if (*src != src_o) {
-          src_o = *src;
-          dst_o = ChainOrigin(src_o, stack);
-        }
-        *dst = dst_o;
-      }
-    } else {
-      REAL(memcpy)((void *)MEM_TO_ORIGIN(beg), (void *)MEM_TO_ORIGIN(s),
-                   end - beg);
-    }
-  }
-}
-
-void MoveShadowAndOrigin(const void *dst, const void *src, uptr size,
-                         StackTrace *stack) {
-  if (!MEM_IS_APP(dst)) return;
-  if (!MEM_IS_APP(src)) return;
-  if (src == dst) return;
-  REAL(memmove)((void *)MEM_TO_SHADOW((uptr)dst),
-                (void *)MEM_TO_SHADOW((uptr)src), size);
-  if (__msan_get_track_origins()) CopyOrigin(dst, src, size, stack);
-}
-
-void CopyShadowAndOrigin(const void *dst, const void *src, uptr size,
-                         StackTrace *stack) {
-  if (!MEM_IS_APP(dst)) return;
-  if (!MEM_IS_APP(src)) return;
-  REAL(memcpy)((void *)MEM_TO_SHADOW((uptr)dst),
-               (void *)MEM_TO_SHADOW((uptr)src), size);
-  if (__msan_get_track_origins()) CopyOrigin(dst, src, size, stack);
-}
-
-void CopyMemory(void *dst, const void *src, uptr size, StackTrace *stack) {
-  REAL(memcpy)(dst, src, size);
-  CopyShadowAndOrigin(dst, src, size, stack);
-}
-
-void SetShadow(const void *ptr, uptr size, u8 value) {
-  uptr PageSize = GetPageSizeCached();
-  uptr shadow_beg = MEM_TO_SHADOW(ptr);
-  uptr shadow_end = shadow_beg + size;
-  if (value ||
-      shadow_end - shadow_beg < common_flags()->clear_shadow_mmap_threshold) {
-    REAL(memset)((void *)shadow_beg, value, shadow_end - shadow_beg);
-  } else {
-    uptr page_beg = RoundUpTo(shadow_beg, PageSize);
-    uptr page_end = RoundDownTo(shadow_end, PageSize);
-
-    if (page_beg >= page_end) {
-      REAL(memset)((void *)shadow_beg, 0, shadow_end - shadow_beg);
-    } else {
-      if (page_beg != shadow_beg) {
-        REAL(memset)((void *)shadow_beg, 0, page_beg - shadow_beg);
-      }
-      if (page_end != shadow_end) {
-        REAL(memset)((void *)page_end, 0, shadow_end - page_end);
-      }
-      if (!MmapFixedNoReserve(page_beg, page_end - page_beg))
-        Die();
-    }
-  }
-}
-
-void SetOrigin(const void *dst, uptr size, u32 origin) {
-  // Origin mapping is 4 bytes per 4 bytes of application memory.
-  // Here we extend the range such that its left and right bounds are both
-  // 4 byte aligned.
-  uptr x = MEM_TO_ORIGIN((uptr)dst);
-  uptr beg = x & ~3UL;               // align down.
-  uptr end = (x + size + 3) & ~3UL;  // align up.
-  u64 origin64 = ((u64)origin << 32) | origin;
-  // This is like memset, but the value is 32-bit. We unroll by 2 to write
-  // 64 bits at once. May want to unroll further to get 128-bit stores.
-  if (beg & 7ULL) {
-    *(u32 *)beg = origin;
-    beg += 4;
-  }
-  for (uptr addr = beg; addr < (end & ~7UL); addr += 8) *(u64 *)addr = origin64;
-  if (end & 7ULL) *(u32 *)(end - 4) = origin;
-}
-
-void PoisonMemory(const void *dst, uptr size, StackTrace *stack) {
-  SetShadow(dst, size, (u8)-1);
-
-  if (__msan_get_track_origins()) {
-    Origin o = Origin::CreateHeapOrigin(stack);
-    SetOrigin(dst, size, o.raw_id());
-  }
-}
-
-}  // namespace __msan

Copied: compiler-rt/trunk/lib/msan/msan_poisoning.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_poisoning.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_poisoning.cpp?p2=compiler-rt/trunk/lib/msan/msan_poisoning.cpp&p1=compiler-rt/trunk/lib/msan/msan_poisoning.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_poisoning.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_poisoning.cc ---------------------------------------*- C++ -*-===//
+//===-- msan_poisoning.cpp --------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc (removed)
@@ -1,272 +0,0 @@
-//===-- msan_report.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
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of MemorySanitizer.
-//
-// Error reporting.
-//===----------------------------------------------------------------------===//
-
-#include "msan.h"
-#include "msan_chained_origin_depot.h"
-#include "msan_origin.h"
-#include "msan_report.h"
-#include "sanitizer_common/sanitizer_allocator_internal.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_mutex.h"
-#include "sanitizer_common/sanitizer_report_decorator.h"
-#include "sanitizer_common/sanitizer_stackdepot.h"
-#include "sanitizer_common/sanitizer_symbolizer.h"
-
-using namespace __sanitizer;
-
-namespace __msan {
-
-class Decorator: public __sanitizer::SanitizerCommonDecorator {
- public:
-  Decorator() : SanitizerCommonDecorator() { }
-  const char *Origin() const { return Magenta(); }
-  const char *Name() const { return Green(); }
-};
-
-static void DescribeStackOrigin(const char *so, uptr pc) {
-  Decorator d;
-  char *s = internal_strdup(so);
-  char *sep = internal_strchr(s, '@');
-  CHECK(sep);
-  *sep = '\0';
-  Printf("%s", d.Origin());
-  Printf(
-      "  %sUninitialized value was created by an allocation of '%s%s%s'"
-      " in the stack frame of function '%s%s%s'%s\n",
-      d.Origin(), d.Name(), s, d.Origin(), d.Name(), sep + 1, d.Origin(),
-      d.Default());
-  InternalFree(s);
-
-  if (pc) {
-    // For some reason function address in LLVM IR is 1 less then the address
-    // of the first instruction.
-    pc = StackTrace::GetNextInstructionPc(pc);
-    StackTrace(&pc, 1).Print();
-  }
-}
-
-static void DescribeOrigin(u32 id) {
-  VPrintf(1, "  raw origin id: %d\n", id);
-  Decorator d;
-  Origin o = Origin::FromRawId(id);
-  while (o.isChainedOrigin()) {
-    StackTrace stack;
-    o = o.getNextChainedOrigin(&stack);
-    Printf("  %sUninitialized value was stored to memory at%s\n", d.Origin(),
-           d.Default());
-    stack.Print();
-  }
-  if (o.isStackOrigin()) {
-    uptr pc;
-    const char *so = GetStackOriginDescr(o.getStackId(), &pc);
-    DescribeStackOrigin(so, pc);
-  } else {
-    StackTrace stack = o.getStackTraceForHeapOrigin();
-    switch (stack.tag) {
-      case StackTrace::TAG_ALLOC:
-        Printf("  %sUninitialized value was created by a heap allocation%s\n",
-               d.Origin(), d.Default());
-        break;
-      case StackTrace::TAG_DEALLOC:
-        Printf("  %sUninitialized value was created by a heap deallocation%s\n",
-               d.Origin(), d.Default());
-        break;
-      case STACK_TRACE_TAG_POISON:
-        Printf("  %sMemory was marked as uninitialized%s\n", d.Origin(),
-               d.Default());
-        break;
-      default:
-        Printf("  %sUninitialized value was created%s\n", d.Origin(),
-               d.Default());
-        break;
-    }
-    stack.Print();
-  }
-}
-
-void ReportUMR(StackTrace *stack, u32 origin) {
-  if (!__msan::flags()->report_umrs) return;
-
-  ScopedErrorReportLock l;
-
-  Decorator d;
-  Printf("%s", d.Warning());
-  Report("WARNING: MemorySanitizer: use-of-uninitialized-value\n");
-  Printf("%s", d.Default());
-  stack->Print();
-  if (origin) {
-    DescribeOrigin(origin);
-  }
-  ReportErrorSummary("use-of-uninitialized-value", stack);
-}
-
-void ReportExpectedUMRNotFound(StackTrace *stack) {
-  ScopedErrorReportLock l;
-
-  Printf("WARNING: Expected use of uninitialized value not found\n");
-  stack->Print();
-}
-
-void ReportStats() {
-  ScopedErrorReportLock l;
-
-  if (__msan_get_track_origins() > 0) {
-    StackDepotStats *stack_depot_stats = StackDepotGetStats();
-    // FIXME: we want this at normal exit, too!
-    // FIXME: but only with verbosity=1 or something
-    Printf("Unique heap origins: %zu\n", stack_depot_stats->n_uniq_ids);
-    Printf("Stack depot allocated bytes: %zu\n", stack_depot_stats->allocated);
-
-    StackDepotStats *chained_origin_depot_stats = ChainedOriginDepotGetStats();
-    Printf("Unique origin histories: %zu\n",
-           chained_origin_depot_stats->n_uniq_ids);
-    Printf("History depot allocated bytes: %zu\n",
-           chained_origin_depot_stats->allocated);
-  }
-}
-
-void ReportAtExitStatistics() {
-  ScopedErrorReportLock l;
-
-  if (msan_report_count > 0) {
-    Decorator d;
-    Printf("%s", d.Warning());
-    Printf("MemorySanitizer: %d warnings reported.\n", msan_report_count);
-    Printf("%s", d.Default());
-  }
-}
-
-class OriginSet {
- public:
-  OriginSet() : next_id_(0) {}
-  int insert(u32 o) {
-    // Scan from the end for better locality.
-    for (int i = next_id_ - 1; i >= 0; --i)
-      if (origins_[i] == o) return i;
-    if (next_id_ == kMaxSize_) return OVERFLOW;
-    int id = next_id_++;
-    origins_[id] = o;
-    return id;
-  }
-  int size() { return next_id_; }
-  u32 get(int id) { return origins_[id]; }
-  static char asChar(int id) {
-    switch (id) {
-      case MISSING:
-        return '.';
-      case OVERFLOW:
-        return '*';
-      default:
-        return 'A' + id;
-    }
-  }
-  static const int OVERFLOW = -1;
-  static const int MISSING = -2;
-
- private:
-  static const int kMaxSize_ = 'Z' - 'A' + 1;
-  u32 origins_[kMaxSize_];
-  int next_id_;
-};
-
-void DescribeMemoryRange(const void *x, uptr size) {
-  // Real limits.
-  uptr start = MEM_TO_SHADOW(x);
-  uptr end = start + size;
-  // Scan limits: align start down to 4; align size up to 16.
-  uptr s = start & ~3UL;
-  size = end - s;
-  size = (size + 15) & ~15UL;
-  uptr e = s + size;
-
-  // Single letter names to origin id mapping.
-  OriginSet origin_set;
-
-  uptr pos = 0;  // Offset from aligned start.
-  bool with_origins = __msan_get_track_origins();
-  // True if there is at least 1 poisoned bit in the last 4-byte group.
-  bool last_quad_poisoned;
-  int origin_ids[4];  // Single letter origin ids for the current line.
-
-  Decorator d;
-  Printf("%s", d.Warning());
-  Printf("Shadow map of [%p, %p), %zu bytes:\n", start, end, end - start);
-  Printf("%s", d.Default());
-  while (s < e) {
-    // Line start.
-    if (pos % 16 == 0) {
-      for (int i = 0; i < 4; ++i) origin_ids[i] = -1;
-      Printf("%p:", s);
-    }
-    // Group start.
-    if (pos % 4 == 0) {
-      Printf(" ");
-      last_quad_poisoned = false;
-    }
-    // Print shadow byte.
-    if (s < start || s >= end) {
-      Printf("..");
-    } else {
-      unsigned char v = *(unsigned char *)s;
-      if (v) last_quad_poisoned = true;
-      Printf("%x%x", v >> 4, v & 0xf);
-    }
-    // Group end.
-    if (pos % 4 == 3 && with_origins) {
-      int id = OriginSet::MISSING;
-      if (last_quad_poisoned) {
-        u32 o = *(u32 *)SHADOW_TO_ORIGIN(s - 3);
-        id = origin_set.insert(o);
-      }
-      origin_ids[(pos % 16) / 4] = id;
-    }
-    // Line end.
-    if (pos % 16 == 15) {
-      if (with_origins) {
-        Printf("  |");
-        for (int i = 0; i < 4; ++i) {
-          char c = OriginSet::asChar(origin_ids[i]);
-          Printf("%c", c);
-          if (i != 3) Printf(" ");
-        }
-        Printf("|");
-      }
-      Printf("\n");
-    }
-    size--;
-    s++;
-    pos++;
-  }
-
-  Printf("\n");
-
-  for (int i = 0; i < origin_set.size(); ++i) {
-    u32 o = origin_set.get(i);
-    Printf("Origin %c (origin_id %x):\n", OriginSet::asChar(i), o);
-    DescribeOrigin(o);
-  }
-}
-
-void ReportUMRInsideAddressRange(const char *what, const void *start, uptr size,
-                                 uptr offset) {
-  Decorator d;
-  Printf("%s", d.Warning());
-  Printf("%sUninitialized bytes in %s%s%s at offset %zu inside [%p, %zu)%s\n",
-         d.Warning(), d.Name(), what, d.Warning(), offset, start, size,
-         d.Default());
-  if (__sanitizer::Verbosity())
-    DescribeMemoryRange(start, size);
-}
-
-}  // namespace __msan

Copied: compiler-rt/trunk/lib/msan/msan_report.cpp (from r367561, compiler-rt/trunk/lib/msan/msan_report.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cpp?p2=compiler-rt/trunk/lib/msan/msan_report.cpp&p1=compiler-rt/trunk/lib/msan/msan_report.cc&r1=367561&r2=367562&rev=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cpp Thu Aug  1 07:08:18 2019
@@ -1,4 +1,4 @@
-//===-- msan_report.cc ----------------------------------------------------===//
+//===-- msan_report.cpp ---------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/msan/msan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_thread.cc?rev=367561&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_thread.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_thread.cc (removed)
@@ -1,82 +0,0 @@
-
-#include "msan.h"
-#include "msan_thread.h"
-#include "msan_interface_internal.h"
-
-#include "sanitizer_common/sanitizer_tls_get_addr.h"
-
-namespace __msan {
-
-MsanThread *MsanThread::Create(thread_callback_t start_routine,
-                               void *arg) {
-  uptr PageSize = GetPageSizeCached();
-  uptr size = RoundUpTo(sizeof(MsanThread), PageSize);
-  MsanThread *thread = (MsanThread*)MmapOrDie(size, __func__);
-  thread->start_routine_ = start_routine;
-  thread->arg_ = arg;
-  thread->destructor_iterations_ = GetPthreadDestructorIterations();
-
-  return thread;
-}
-
-void MsanThread::SetThreadStackAndTls() {
-  uptr tls_size = 0;
-  uptr stack_size = 0;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size,
-                       &tls_begin_, &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
-  int local;
-  CHECK(AddrIsInStack((uptr)&local));
-}
-
-void MsanThread::ClearShadowForThreadStackAndTLS() {
-  __msan_unpoison((void *)stack_bottom_, stack_top_ - stack_bottom_);
-  if (tls_begin_ != tls_end_)
-    __msan_unpoison((void *)tls_begin_, tls_end_ - tls_begin_);
-  DTLS *dtls = DTLS_Get();
-  CHECK_NE(dtls, 0);
-  for (uptr i = 0; i < dtls->dtv_size; ++i)
-    __msan_unpoison((void *)(dtls->dtv[i].beg), dtls->dtv[i].size);
-}
-
-void MsanThread::Init() {
-  SetThreadStackAndTls();
-  CHECK(MEM_IS_APP(stack_bottom_));
-  CHECK(MEM_IS_APP(stack_top_ - 1));
-  ClearShadowForThreadStackAndTLS();
-}
-
-void MsanThread::TSDDtor(void *tsd) {
-  MsanThread *t = (MsanThread*)tsd;
-  t->Destroy();
-}
-
-void MsanThread::Destroy() {
-  malloc_storage().CommitBack();
-  // We also clear the shadow on thread destruction because
-  // some code may still be executing in later TSD destructors
-  // and we don't want it to have any poisoned stack.
-  ClearShadowForThreadStackAndTLS();
-  uptr size = RoundUpTo(sizeof(MsanThread), GetPageSizeCached());
-  UnmapOrDie(this, size);
-  DTLS_Destroy();
-}
-
-thread_return_t MsanThread::ThreadStart() {
-  Init();
-
-  if (!start_routine_) {
-    // start_routine_ == 0 if we're on the main thread or on one of the
-    // OS X libdispatch worker threads. But nobody is supposed to call
-    // ThreadStart() for the worker threads.
-    return 0;
-  }
-
-  thread_return_t res = start_routine_(arg_);
-
-  return res;
-}
-
-} // namespace __msan

Modified: compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh?rev=367562&r1=367561&r2=367562&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh (original)
+++ compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh Thu Aug  1 07:08:18 2019
@@ -98,7 +98,7 @@ run_lint ${TSAN_LIT_TEST_LINT_FILTER} ${
 
 # MSan
 MSAN_RTL=${COMPILER_RT}/lib/msan
-run_lint ${MSAN_RTL_LINT_FILTER} ${MSAN_RTL}/*.cc \
+run_lint ${MSAN_RTL_LINT_FILTER} ${MSAN_RTL}/*.cpp \
                                  ${MSAN_RTL}/*.h &
 
 # LSan

Modified: compiler-rt/trunk/test/msan/chained_origin_memcpy.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/chained_origin_memcpy.cc?rev=367562&r1=367561&r2=367562&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/chained_origin_memcpy.cc (original)
+++ compiler-rt/trunk/test/msan/chained_origin_memcpy.cc Thu Aug  1 07:08:18 2019
@@ -46,17 +46,17 @@ int main(int argc, char *argv[]) {
 }
 
 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-// CHECK: {{#0 .* in main .*chained_origin_memcpy.cc:}}[[@LINE-4]]
+// CHECK: {{#0 .* in main .*chained_origin_memcpy.cpp:}}[[@LINE-4]]
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK-FULL-STACK: {{#1 .* in fn_h.*chained_origin_memcpy.cc:}}[[@LINE-15]]
-// CHECK-SHORT-STACK: {{#0 .* in __msan_memcpy.*msan_interceptors.cc:}}
+// CHECK-FULL-STACK: {{#1 .* in fn_h.*chained_origin_memcpy.cpp:}}[[@LINE-15]]
+// CHECK-SHORT-STACK: {{#0 .* in __msan_memcpy.*msan_interceptors.cpp:}}
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK-FULL-STACK: {{#0 .* in fn_g.*chained_origin_memcpy.cc:}}[[@LINE-29]]
-// CHECK-FULL-STACK: {{#1 .* in fn_f.*chained_origin_memcpy.cc:}}[[@LINE-25]]
-// CHECK-SHORT-STACK: {{#0 .* in fn_g.*chained_origin_memcpy.cc:}}[[@LINE-31]]
+// CHECK-FULL-STACK: {{#0 .* in fn_g.*chained_origin_memcpy.cpp:}}[[@LINE-29]]
+// CHECK-FULL-STACK: {{#1 .* in fn_f.*chained_origin_memcpy.cpp:}}[[@LINE-25]]
+// CHECK-SHORT-STACK: {{#0 .* in fn_g.*chained_origin_memcpy.cpp:}}[[@LINE-31]]
 
 // CHECK-Z1: Uninitialized value was created by an allocation of 'z1' in the stack frame of function 'main'
 // CHECK-Z2: Uninitialized value was created by an allocation of 'z2' in the stack frame of function 'main'
-// CHECK: {{#0 .* in main.*chained_origin_memcpy.cc:}}[[@LINE-22]]
+// CHECK: {{#0 .* in main.*chained_origin_memcpy.cpp:}}[[@LINE-22]]

Modified: compiler-rt/trunk/test/msan/msan_copy_shadow.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/msan_copy_shadow.cc?rev=367562&r1=367561&r2=367562&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/msan_copy_shadow.cc (original)
+++ compiler-rt/trunk/test/msan/msan_copy_shadow.cc Thu Aug  1 07:08:18 2019
@@ -26,10 +26,10 @@ int main() {
   assert(__msan_test_shadow(b + 3, 1) == -1);
   __msan_check_mem_is_initialized(b, 4);
   // CHECK: use-of-uninitialized-value
-  // CHECK:   {{in main.*msan_copy_shadow.cc:}}[[@LINE-2]]
+  // CHECK:   {{in main.*msan_copy_shadow.cpp:}}[[@LINE-2]]
   // CHECK: Uninitialized value was stored to memory at
-  // CHECK-FULL-STACK:   {{in main.*msan_copy_shadow.cc:}}[[@LINE-8]]
-  // CHECK-SHORT-STACK:   {{in __msan_copy_shadow .*msan_interceptors.cc:}}
+  // CHECK-FULL-STACK:   {{in main.*msan_copy_shadow.cpp:}}[[@LINE-8]]
+  // CHECK-SHORT-STACK:   {{in __msan_copy_shadow .*msan_interceptors.cpp:}}
   // CHECK: Uninitialized value was created by a heap allocation
-  // CHECK:   {{in main.*msan_copy_shadow.cc:}}[[@LINE-23]]
+  // CHECK:   {{in main.*msan_copy_shadow.cpp:}}[[@LINE-23]]
 }




More information about the llvm-commits mailing list