Home | History | Annotate | Download | only in msan
      1 //===-- msan.cc -----------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of MemorySanitizer.
     11 //
     12 // MemorySanitizer runtime.
     13 //===----------------------------------------------------------------------===//
     14 
     15 #include "msan.h"
     16 #include "msan_chained_origin_depot.h"
     17 #include "msan_origin.h"
     18 #include "msan_thread.h"
     19 #include "msan_poisoning.h"
     20 #include "sanitizer_common/sanitizer_atomic.h"
     21 #include "sanitizer_common/sanitizer_common.h"
     22 #include "sanitizer_common/sanitizer_flags.h"
     23 #include "sanitizer_common/sanitizer_flag_parser.h"
     24 #include "sanitizer_common/sanitizer_libc.h"
     25 #include "sanitizer_common/sanitizer_procmaps.h"
     26 #include "sanitizer_common/sanitizer_stacktrace.h"
     27 #include "sanitizer_common/sanitizer_symbolizer.h"
     28 #include "sanitizer_common/sanitizer_stackdepot.h"
     29 #include "ubsan/ubsan_flags.h"
     30 #include "ubsan/ubsan_init.h"
     31 
     32 // ACHTUNG! No system header includes in this file.
     33 
     34 using namespace __sanitizer;
     35 
     36 // Globals.
     37 static THREADLOCAL int msan_expect_umr = 0;
     38 static THREADLOCAL int msan_expected_umr_found = 0;
     39 
     40 // Function argument shadow. Each argument starts at the next available 8-byte
     41 // aligned address.
     42 SANITIZER_INTERFACE_ATTRIBUTE
     43 THREADLOCAL u64 __msan_param_tls[kMsanParamTlsSize / sizeof(u64)];
     44 
     45 // Function argument origin. Each argument starts at the same offset as the
     46 // corresponding shadow in (__msan_param_tls). Slightly weird, but changing this
     47 // would break compatibility with older prebuilt binaries.
     48 SANITIZER_INTERFACE_ATTRIBUTE
     49 THREADLOCAL u32 __msan_param_origin_tls[kMsanParamTlsSize / sizeof(u32)];
     50 
     51 SANITIZER_INTERFACE_ATTRIBUTE
     52 THREADLOCAL u64 __msan_retval_tls[kMsanRetvalTlsSize / sizeof(u64)];
     53 
     54 SANITIZER_INTERFACE_ATTRIBUTE
     55 THREADLOCAL u32 __msan_retval_origin_tls;
     56 
     57 SANITIZER_INTERFACE_ATTRIBUTE
     58 ALIGNED(16) THREADLOCAL u64 __msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
     59 
     60 SANITIZER_INTERFACE_ATTRIBUTE
     61 THREADLOCAL u64 __msan_va_arg_overflow_size_tls;
     62 
     63 SANITIZER_INTERFACE_ATTRIBUTE
     64 THREADLOCAL u32 __msan_origin_tls;
     65 
     66 static THREADLOCAL int is_in_symbolizer;
     67 
     68 extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_track_origins;
     69 
     70 int __msan_get_track_origins() {
     71   return &__msan_track_origins ? __msan_track_origins : 0;
     72 }
     73 
     74 extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_keep_going;
     75 
     76 namespace __msan {
     77 
     78 void EnterSymbolizer() { ++is_in_symbolizer; }
     79 void ExitSymbolizer()  { --is_in_symbolizer; }
     80 bool IsInSymbolizer() { return is_in_symbolizer; }
     81 
     82 static Flags msan_flags;
     83 
     84 Flags *flags() {
     85   return &msan_flags;
     86 }
     87 
     88 int msan_inited = 0;
     89 bool msan_init_is_running;
     90 
     91 int msan_report_count = 0;
     92 
     93 // Array of stack origins.
     94 // FIXME: make it resizable.
     95 static const uptr kNumStackOriginDescrs = 1024 * 1024;
     96 static const char *StackOriginDescr[kNumStackOriginDescrs];
     97 static uptr StackOriginPC[kNumStackOriginDescrs];
     98 static atomic_uint32_t NumStackOriginDescrs;
     99 
    100 void Flags::SetDefaults() {
    101 #define MSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
    102 #include "msan_flags.inc"
    103 #undef MSAN_FLAG
    104 }
    105 
    106 // keep_going is an old name for halt_on_error,
    107 // and it has inverse meaning.
    108 class FlagHandlerKeepGoing : public FlagHandlerBase {
    109   bool *halt_on_error_;
    110 
    111  public:
    112   explicit FlagHandlerKeepGoing(bool *halt_on_error)
    113       : halt_on_error_(halt_on_error) {}
    114   bool Parse(const char *value) final {
    115     bool tmp;
    116     FlagHandler<bool> h(&tmp);
    117     if (!h.Parse(value)) return false;
    118     *halt_on_error_ = !tmp;
    119     return true;
    120   }
    121 };
    122 
    123 static void RegisterMsanFlags(FlagParser *parser, Flags *f) {
    124 #define MSAN_FLAG(Type, Name, DefaultValue, Description) \
    125   RegisterFlag(parser, #Name, Description, &f->Name);
    126 #include "msan_flags.inc"
    127 #undef MSAN_FLAG
    128 
    129   FlagHandlerKeepGoing *fh_keep_going = new (FlagParser::Alloc)  // NOLINT
    130       FlagHandlerKeepGoing(&f->halt_on_error);
    131   parser->RegisterHandler("keep_going", fh_keep_going,
    132                           "deprecated, use halt_on_error");
    133 }
    134 
    135 static void InitializeFlags() {
    136   SetCommonFlagsDefaults();
    137   {
    138     CommonFlags cf;
    139     cf.CopyFrom(*common_flags());
    140     cf.external_symbolizer_path = GetEnv("MSAN_SYMBOLIZER_PATH");
    141     cf.malloc_context_size = 20;
    142     cf.handle_ioctl = true;
    143     // FIXME: test and enable.
    144     cf.check_printf = false;
    145     cf.intercept_tls_get_addr = true;
    146     cf.exitcode = 77;
    147     OverrideCommonFlags(cf);
    148   }
    149 
    150   Flags *f = flags();
    151   f->SetDefaults();
    152 
    153   FlagParser parser;
    154   RegisterMsanFlags(&parser, f);
    155   RegisterCommonFlags(&parser);
    156 
    157 #if MSAN_CONTAINS_UBSAN
    158   __ubsan::Flags *uf = __ubsan::flags();
    159   uf->SetDefaults();
    160 
    161   FlagParser ubsan_parser;
    162   __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
    163   RegisterCommonFlags(&ubsan_parser);
    164 #endif
    165 
    166   // Override from user-specified string.
    167   if (__msan_default_options)
    168     parser.ParseString(__msan_default_options());
    169 #if MSAN_CONTAINS_UBSAN
    170   const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
    171   ubsan_parser.ParseString(ubsan_default_options);
    172 #endif
    173 
    174   const char *msan_options = GetEnv("MSAN_OPTIONS");
    175   parser.ParseString(msan_options);
    176 #if MSAN_CONTAINS_UBSAN
    177   ubsan_parser.ParseString(GetEnv("UBSAN_OPTIONS"));
    178 #endif
    179   VPrintf(1, "MSAN_OPTIONS: %s\n", msan_options ? msan_options : "<empty>");
    180 
    181   SetVerbosity(common_flags()->verbosity);
    182 
    183   if (Verbosity()) ReportUnrecognizedFlags();
    184 
    185   if (common_flags()->help) parser.PrintFlagDescriptions();
    186 
    187   // Check if deprecated exit_code MSan flag is set.
    188   if (f->exit_code != -1) {
    189     if (Verbosity())
    190       Printf("MSAN_OPTIONS=exit_code is deprecated! "
    191              "Please use MSAN_OPTIONS=exitcode instead.\n");
    192     CommonFlags cf;
    193     cf.CopyFrom(*common_flags());
    194     cf.exitcode = f->exit_code;
    195     OverrideCommonFlags(cf);
    196   }
    197 
    198   // Check flag values:
    199   if (f->origin_history_size < 0 ||
    200       f->origin_history_size > Origin::kMaxDepth) {
    201     Printf(
    202         "Origin history size invalid: %d. Must be 0 (unlimited) or in [1, %d] "
    203         "range.\n",
    204         f->origin_history_size, Origin::kMaxDepth);
    205     Die();
    206   }
    207   // Limiting to kStackDepotMaxUseCount / 2 to avoid overflow in
    208   // StackDepotHandle::inc_use_count_unsafe.
    209   if (f->origin_history_per_stack_limit < 0 ||
    210       f->origin_history_per_stack_limit > kStackDepotMaxUseCount / 2) {
    211     Printf(
    212         "Origin per-stack limit invalid: %d. Must be 0 (unlimited) or in [1, "
    213         "%d] range.\n",
    214         f->origin_history_per_stack_limit, kStackDepotMaxUseCount / 2);
    215     Die();
    216   }
    217   if (f->store_context_size < 1) f->store_context_size = 1;
    218 }
    219 
    220 void GetStackTrace(BufferedStackTrace *stack, uptr max_s, uptr pc, uptr bp,
    221                    bool request_fast_unwind) {
    222   MsanThread *t = GetCurrentThread();
    223   if (!t || !StackTrace::WillUseFastUnwind(request_fast_unwind)) {
    224     // Block reports from our interceptors during _Unwind_Backtrace.
    225     SymbolizerScope sym_scope;
    226     return stack->Unwind(max_s, pc, bp, nullptr, 0, 0, request_fast_unwind);
    227   }
    228   stack->Unwind(max_s, pc, bp, nullptr, t->stack_top(), t->stack_bottom(),
    229                 request_fast_unwind);
    230 }
    231 
    232 void PrintWarning(uptr pc, uptr bp) {
    233   PrintWarningWithOrigin(pc, bp, __msan_origin_tls);
    234 }
    235 
    236 void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) {
    237   if (msan_expect_umr) {
    238     // Printf("Expected UMR\n");
    239     __msan_origin_tls = origin;
    240     msan_expected_umr_found = 1;
    241     return;
    242   }
    243 
    244   ++msan_report_count;
    245 
    246   GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
    247 
    248   u32 report_origin =
    249     (__msan_get_track_origins() && Origin::isValidId(origin)) ? origin : 0;
    250   ReportUMR(&stack, report_origin);
    251 
    252   if (__msan_get_track_origins() && !Origin::isValidId(origin)) {
    253     Printf(
    254         "  ORIGIN: invalid (%x). Might be a bug in MemorySanitizer origin "
    255         "tracking.\n    This could still be a bug in your code, too!\n",
    256         origin);
    257   }
    258 }
    259 
    260 void UnpoisonParam(uptr n) {
    261   internal_memset(__msan_param_tls, 0, n * sizeof(*__msan_param_tls));
    262 }
    263 
    264 // Backup MSan runtime TLS state.
    265 // Implementation must be async-signal-safe.
    266 // Instances of this class may live on the signal handler stack, and data size
    267 // may be an issue.
    268 void ScopedThreadLocalStateBackup::Backup() {
    269   va_arg_overflow_size_tls = __msan_va_arg_overflow_size_tls;
    270 }
    271 
    272 void ScopedThreadLocalStateBackup::Restore() {
    273   // A lame implementation that only keeps essential state and resets the rest.
    274   __msan_va_arg_overflow_size_tls = va_arg_overflow_size_tls;
    275 
    276   internal_memset(__msan_param_tls, 0, sizeof(__msan_param_tls));
    277   internal_memset(__msan_retval_tls, 0, sizeof(__msan_retval_tls));
    278   internal_memset(__msan_va_arg_tls, 0, sizeof(__msan_va_arg_tls));
    279 
    280   if (__msan_get_track_origins()) {
    281     internal_memset(&__msan_retval_origin_tls, 0,
    282                     sizeof(__msan_retval_origin_tls));
    283     internal_memset(__msan_param_origin_tls, 0,
    284                     sizeof(__msan_param_origin_tls));
    285   }
    286 }
    287 
    288 void UnpoisonThreadLocalState() {
    289 }
    290 
    291 const char *GetStackOriginDescr(u32 id, uptr *pc) {
    292   CHECK_LT(id, kNumStackOriginDescrs);
    293   if (pc) *pc = StackOriginPC[id];
    294   return StackOriginDescr[id];
    295 }
    296 
    297 u32 ChainOrigin(u32 id, StackTrace *stack) {
    298   MsanThread *t = GetCurrentThread();
    299   if (t && t->InSignalHandler())
    300     return id;
    301 
    302   Origin o = Origin::FromRawId(id);
    303   stack->tag = StackTrace::TAG_UNKNOWN;
    304   Origin chained = Origin::CreateChainedOrigin(o, stack);
    305   return chained.raw_id();
    306 }
    307 
    308 } // namespace __msan
    309 
    310 // Interface.
    311 
    312 using namespace __msan;
    313 
    314 #define MSAN_MAYBE_WARNING(type, size)              \
    315   void __msan_maybe_warning_##size(type s, u32 o) { \
    316     GET_CALLER_PC_BP_SP;                            \
    317     (void) sp;                                      \
    318     if (UNLIKELY(s)) {                              \
    319       PrintWarningWithOrigin(pc, bp, o);            \
    320       if (__msan::flags()->halt_on_error) {         \
    321         Printf("Exiting\n");                        \
    322         Die();                                      \
    323       }                                             \
    324     }                                               \
    325   }
    326 
    327 MSAN_MAYBE_WARNING(u8, 1)
    328 MSAN_MAYBE_WARNING(u16, 2)
    329 MSAN_MAYBE_WARNING(u32, 4)
    330 MSAN_MAYBE_WARNING(u64, 8)
    331 
    332 #define MSAN_MAYBE_STORE_ORIGIN(type, size)                       \
    333   void __msan_maybe_store_origin_##size(type s, void *p, u32 o) { \
    334     if (UNLIKELY(s)) {                                            \
    335       if (__msan_get_track_origins() > 1) {                       \
    336         GET_CALLER_PC_BP_SP;                                      \
    337         (void) sp;                                                \
    338         GET_STORE_STACK_TRACE_PC_BP(pc, bp);                      \
    339         o = ChainOrigin(o, &stack);                               \
    340       }                                                           \
    341       *(u32 *)MEM_TO_ORIGIN((uptr)p & ~3UL) = o;                  \
    342     }                                                             \
    343   }
    344 
    345 MSAN_MAYBE_STORE_ORIGIN(u8, 1)
    346 MSAN_MAYBE_STORE_ORIGIN(u16, 2)
    347 MSAN_MAYBE_STORE_ORIGIN(u32, 4)
    348 MSAN_MAYBE_STORE_ORIGIN(u64, 8)
    349 
    350 void __msan_warning() {
    351   GET_CALLER_PC_BP_SP;
    352   (void)sp;
    353   PrintWarning(pc, bp);
    354   if (__msan::flags()->halt_on_error) {
    355     if (__msan::flags()->print_stats)
    356       ReportStats();
    357     Printf("Exiting\n");
    358     Die();
    359   }
    360 }
    361 
    362 void __msan_warning_noreturn() {
    363   GET_CALLER_PC_BP_SP;
    364   (void)sp;
    365   PrintWarning(pc, bp);
    366   if (__msan::flags()->print_stats)
    367     ReportStats();
    368   Printf("Exiting\n");
    369   Die();
    370 }
    371 
    372 void __msan_init() {
    373   CHECK(!msan_init_is_running);
    374   if (msan_inited) return;
    375   msan_init_is_running = 1;
    376   SanitizerToolName = "MemorySanitizer";
    377 
    378   InitTlsSize();
    379 
    380   CacheBinaryName();
    381   InitializeFlags();
    382 
    383   __sanitizer_set_report_path(common_flags()->log_path);
    384 
    385   InitializeInterceptors();
    386   InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
    387 
    388   DisableCoreDumperIfNecessary();
    389   if (StackSizeIsUnlimited()) {
    390     VPrintf(1, "Unlimited stack, doing reexec\n");
    391     // A reasonably large stack size. It is bigger than the usual 8Mb, because,
    392     // well, the program could have been run with unlimited stack for a reason.
    393     SetStackSizeLimitInBytes(32 * 1024 * 1024);
    394     ReExec();
    395   }
    396 
    397   __msan_clear_on_return();
    398   if (__msan_get_track_origins())
    399     VPrintf(1, "msan_track_origins\n");
    400   if (!InitShadow(__msan_get_track_origins())) {
    401     Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n");
    402     Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n");
    403     Printf("FATAL: Disabling ASLR is known to cause this error.\n");
    404     Printf("FATAL: If running under GDB, try "
    405            "'set disable-randomization off'.\n");
    406     DumpProcessMap();
    407     Die();
    408   }
    409 
    410   Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
    411 
    412   InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
    413 
    414   MsanTSDInit(MsanTSDDtor);
    415 
    416   MsanAllocatorInit();
    417 
    418   MsanThread *main_thread = MsanThread::Create(nullptr, nullptr);
    419   SetCurrentThread(main_thread);
    420   main_thread->ThreadStart();
    421 
    422 #if MSAN_CONTAINS_UBSAN
    423   __ubsan::InitAsPlugin();
    424 #endif
    425 
    426   VPrintf(1, "MemorySanitizer init done\n");
    427 
    428   msan_init_is_running = 0;
    429   msan_inited = 1;
    430 }
    431 
    432 void __msan_set_keep_going(int keep_going) {
    433   flags()->halt_on_error = !keep_going;
    434 }
    435 
    436 void __msan_set_expect_umr(int expect_umr) {
    437   if (expect_umr) {
    438     msan_expected_umr_found = 0;
    439   } else if (!msan_expected_umr_found) {
    440     GET_CALLER_PC_BP_SP;
    441     (void)sp;
    442     GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
    443     ReportExpectedUMRNotFound(&stack);
    444     Die();
    445   }
    446   msan_expect_umr = expect_umr;
    447 }
    448 
    449 void __msan_print_shadow(const void *x, uptr size) {
    450   if (!MEM_IS_APP(x)) {
    451     Printf("Not a valid application address: %p\n", x);
    452     return;
    453   }
    454 
    455   DescribeMemoryRange(x, size);
    456 }
    457 
    458 void __msan_dump_shadow(const void *x, uptr size) {
    459   if (!MEM_IS_APP(x)) {
    460     Printf("Not a valid application address: %p\n", x);
    461     return;
    462   }
    463 
    464   unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
    465   for (uptr i = 0; i < size; i++) {
    466 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
    467     Printf("%x%x ", s[i] & 0xf, s[i] >> 4);
    468 #else
    469     Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
    470 #endif
    471   }
    472   Printf("\n");
    473 }
    474 
    475 sptr __msan_test_shadow(const void *x, uptr size) {
    476   if (!MEM_IS_APP(x)) return -1;
    477   unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
    478   for (uptr i = 0; i < size; ++i)
    479     if (s[i])
    480       return i;
    481   return -1;
    482 }
    483 
    484 void __msan_check_mem_is_initialized(const void *x, uptr size) {
    485   if (!__msan::flags()->report_umrs) return;
    486   sptr offset = __msan_test_shadow(x, size);
    487   if (offset < 0)
    488     return;
    489 
    490   GET_CALLER_PC_BP_SP;
    491   (void)sp;
    492   ReportUMRInsideAddressRange(__func__, x, size, offset);
    493   __msan::PrintWarningWithOrigin(pc, bp,
    494                                  __msan_get_origin(((const char *)x) + offset));
    495   if (__msan::flags()->halt_on_error) {
    496     Printf("Exiting\n");
    497     Die();
    498   }
    499 }
    500 
    501 int __msan_set_poison_in_malloc(int do_poison) {
    502   int old = flags()->poison_in_malloc;
    503   flags()->poison_in_malloc = do_poison;
    504   return old;
    505 }
    506 
    507 int __msan_has_dynamic_component() { return false; }
    508 
    509 NOINLINE
    510 void __msan_clear_on_return() {
    511   __msan_param_tls[0] = 0;
    512 }
    513 
    514 void __msan_partial_poison(const void* data, void* shadow, uptr size) {
    515   internal_memcpy((void*)MEM_TO_SHADOW((uptr)data), shadow, size);
    516 }
    517 
    518 void __msan_load_unpoisoned(const void *src, uptr size, void *dst) {
    519   internal_memcpy(dst, src, size);
    520   __msan_unpoison(dst, size);
    521 }
    522 
    523 void __msan_set_origin(const void *a, uptr size, u32 origin) {
    524   if (__msan_get_track_origins()) SetOrigin(a, size, origin);
    525 }
    526 
    527 // 'descr' is created at compile time and contains '----' in the beginning.
    528 // When we see descr for the first time we replace '----' with a uniq id
    529 // and set the origin to (id | (31-th bit)).
    530 void __msan_set_alloca_origin(void *a, uptr size, char *descr) {
    531   __msan_set_alloca_origin4(a, size, descr, 0);
    532 }
    533 
    534 void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) {
    535   static const u32 dash = '-';
    536   static const u32 first_timer =
    537       dash + (dash << 8) + (dash << 16) + (dash << 24);
    538   u32 *id_ptr = (u32*)descr;
    539   bool print = false;  // internal_strstr(descr + 4, "AllocaTOTest") != 0;
    540   u32 id = *id_ptr;
    541   if (id == first_timer) {
    542     u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
    543     CHECK_LT(idx, kNumStackOriginDescrs);
    544     StackOriginDescr[idx] = descr + 4;
    545     StackOriginPC[idx] = pc;
    546     id = Origin::CreateStackOrigin(idx).raw_id();
    547     *id_ptr = id;
    548     if (print)
    549       Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc);
    550   }
    551   if (print)
    552     Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
    553   __msan_set_origin(a, size, id);
    554 }
    555 
    556 u32 __msan_chain_origin(u32 id) {
    557   GET_CALLER_PC_BP_SP;
    558   (void)sp;
    559   GET_STORE_STACK_TRACE_PC_BP(pc, bp);
    560   return ChainOrigin(id, &stack);
    561 }
    562 
    563 u32 __msan_get_origin(const void *a) {
    564   if (!__msan_get_track_origins()) return 0;
    565   uptr x = (uptr)a;
    566   uptr aligned = x & ~3ULL;
    567   uptr origin_ptr = MEM_TO_ORIGIN(aligned);
    568   return *(u32*)origin_ptr;
    569 }
    570 
    571 int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id) {
    572   Origin o = Origin::FromRawId(this_id);
    573   while (o.raw_id() != prev_id && o.isChainedOrigin())
    574     o = o.getNextChainedOrigin(nullptr);
    575   return o.raw_id() == prev_id;
    576 }
    577 
    578 u32 __msan_get_umr_origin() {
    579   return __msan_origin_tls;
    580 }
    581 
    582 u16 __sanitizer_unaligned_load16(const uu16 *p) {
    583   __msan_retval_tls[0] = *(uu16 *)MEM_TO_SHADOW((uptr)p);
    584   if (__msan_get_track_origins())
    585     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
    586   return *p;
    587 }
    588 u32 __sanitizer_unaligned_load32(const uu32 *p) {
    589   __msan_retval_tls[0] = *(uu32 *)MEM_TO_SHADOW((uptr)p);
    590   if (__msan_get_track_origins())
    591     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
    592   return *p;
    593 }
    594 u64 __sanitizer_unaligned_load64(const uu64 *p) {
    595   __msan_retval_tls[0] = *(uu64 *)MEM_TO_SHADOW((uptr)p);
    596   if (__msan_get_track_origins())
    597     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
    598   return *p;
    599 }
    600 void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
    601   u16 s = __msan_param_tls[1];
    602   *(uu16 *)MEM_TO_SHADOW((uptr)p) = s;
    603   if (s && __msan_get_track_origins())
    604     if (uu32 o = __msan_param_origin_tls[2])
    605       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
    606   *p = x;
    607 }
    608 void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
    609   u32 s = __msan_param_tls[1];
    610   *(uu32 *)MEM_TO_SHADOW((uptr)p) = s;
    611   if (s && __msan_get_track_origins())
    612     if (uu32 o = __msan_param_origin_tls[2])
    613       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
    614   *p = x;
    615 }
    616 void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
    617   u64 s = __msan_param_tls[1];
    618   *(uu64 *)MEM_TO_SHADOW((uptr)p) = s;
    619   if (s && __msan_get_track_origins())
    620     if (uu32 o = __msan_param_origin_tls[2])
    621       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
    622   *p = x;
    623 }
    624 
    625 void __msan_set_death_callback(void (*callback)(void)) {
    626   SetUserDieCallback(callback);
    627 }
    628 
    629 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
    630 extern "C" {
    631 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
    632 const char* __msan_default_options() { return ""; }
    633 }  // extern "C"
    634 #endif
    635 
    636 extern "C" {
    637 SANITIZER_INTERFACE_ATTRIBUTE
    638 void __sanitizer_print_stack_trace() {
    639   GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME());
    640   stack.Print();
    641 }
    642 } // extern "C"
    643