]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/msan/msan.cc
libfdt: Update to 1.4.6, switch to using libfdt for overlay support
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / msan / msan.cc
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   InitializeCommonFlags();
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                    void *context, 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, context, 0, 0, request_fast_unwind);
227   }
228   stack->Unwind(max_s, pc, bp, context, 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 static void OnStackUnwind(const SignalContext &sig, const void *,
373                           BufferedStackTrace *stack) {
374   GetStackTrace(stack, kStackTraceMax, sig.pc, sig.bp, sig.context,
375                 common_flags()->fast_unwind_on_fatal);
376 }
377
378 static void MsanOnDeadlySignal(int signo, void *siginfo, void *context) {
379   HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
380 }
381
382 void __msan_init() {
383   CHECK(!msan_init_is_running);
384   if (msan_inited) return;
385   msan_init_is_running = 1;
386   SanitizerToolName = "MemorySanitizer";
387
388   AvoidCVE_2016_2143();
389   InitTlsSize();
390
391   CacheBinaryName();
392   InitializeFlags();
393
394   __sanitizer_set_report_path(common_flags()->log_path);
395
396   InitializeInterceptors();
397   InstallDeadlySignalHandlers(MsanOnDeadlySignal);
398   InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
399
400   DisableCoreDumperIfNecessary();
401   if (StackSizeIsUnlimited()) {
402     VPrintf(1, "Unlimited stack, doing reexec\n");
403     // A reasonably large stack size. It is bigger than the usual 8Mb, because,
404     // well, the program could have been run with unlimited stack for a reason.
405     SetStackSizeLimitInBytes(32 * 1024 * 1024);
406     ReExec();
407   }
408
409   __msan_clear_on_return();
410   if (__msan_get_track_origins())
411     VPrintf(1, "msan_track_origins\n");
412   if (!InitShadow(__msan_get_track_origins())) {
413     Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n");
414     Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n");
415     Printf("FATAL: Disabling ASLR is known to cause this error.\n");
416     Printf("FATAL: If running under GDB, try "
417            "'set disable-randomization off'.\n");
418     DumpProcessMap();
419     Die();
420   }
421
422   Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
423
424   InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
425
426   MsanTSDInit(MsanTSDDtor);
427
428   MsanAllocatorInit();
429
430   MsanThread *main_thread = MsanThread::Create(nullptr, nullptr);
431   SetCurrentThread(main_thread);
432   main_thread->ThreadStart();
433
434 #if MSAN_CONTAINS_UBSAN
435   __ubsan::InitAsPlugin();
436 #endif
437
438   VPrintf(1, "MemorySanitizer init done\n");
439
440   msan_init_is_running = 0;
441   msan_inited = 1;
442 }
443
444 void __msan_set_keep_going(int keep_going) {
445   flags()->halt_on_error = !keep_going;
446 }
447
448 void __msan_set_expect_umr(int expect_umr) {
449   if (expect_umr) {
450     msan_expected_umr_found = 0;
451   } else if (!msan_expected_umr_found) {
452     GET_CALLER_PC_BP_SP;
453     (void)sp;
454     GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
455     ReportExpectedUMRNotFound(&stack);
456     Die();
457   }
458   msan_expect_umr = expect_umr;
459 }
460
461 void __msan_print_shadow(const void *x, uptr size) {
462   if (!MEM_IS_APP(x)) {
463     Printf("Not a valid application address: %p\n", x);
464     return;
465   }
466
467   DescribeMemoryRange(x, size);
468 }
469
470 void __msan_dump_shadow(const void *x, uptr size) {
471   if (!MEM_IS_APP(x)) {
472     Printf("Not a valid application address: %p\n", x);
473     return;
474   }
475
476   unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
477   for (uptr i = 0; i < size; i++)
478     Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
479   Printf("\n");
480 }
481
482 sptr __msan_test_shadow(const void *x, uptr size) {
483   if (!MEM_IS_APP(x)) return -1;
484   unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
485   for (uptr i = 0; i < size; ++i)
486     if (s[i])
487       return i;
488   return -1;
489 }
490
491 void __msan_check_mem_is_initialized(const void *x, uptr size) {
492   if (!__msan::flags()->report_umrs) return;
493   sptr offset = __msan_test_shadow(x, size);
494   if (offset < 0)
495     return;
496
497   GET_CALLER_PC_BP_SP;
498   (void)sp;
499   ReportUMRInsideAddressRange(__func__, x, size, offset);
500   __msan::PrintWarningWithOrigin(pc, bp,
501                                  __msan_get_origin(((const char *)x) + offset));
502   if (__msan::flags()->halt_on_error) {
503     Printf("Exiting\n");
504     Die();
505   }
506 }
507
508 int __msan_set_poison_in_malloc(int do_poison) {
509   int old = flags()->poison_in_malloc;
510   flags()->poison_in_malloc = do_poison;
511   return old;
512 }
513
514 int __msan_has_dynamic_component() { return false; }
515
516 NOINLINE
517 void __msan_clear_on_return() {
518   __msan_param_tls[0] = 0;
519 }
520
521 void __msan_partial_poison(const void* data, void* shadow, uptr size) {
522   internal_memcpy((void*)MEM_TO_SHADOW((uptr)data), shadow, size);
523 }
524
525 void __msan_load_unpoisoned(const void *src, uptr size, void *dst) {
526   internal_memcpy(dst, src, size);
527   __msan_unpoison(dst, size);
528 }
529
530 void __msan_set_origin(const void *a, uptr size, u32 origin) {
531   if (__msan_get_track_origins()) SetOrigin(a, size, origin);
532 }
533
534 // 'descr' is created at compile time and contains '----' in the beginning.
535 // When we see descr for the first time we replace '----' with a uniq id
536 // and set the origin to (id | (31-th bit)).
537 void __msan_set_alloca_origin(void *a, uptr size, char *descr) {
538   __msan_set_alloca_origin4(a, size, descr, 0);
539 }
540
541 void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) {
542   static const u32 dash = '-';
543   static const u32 first_timer =
544       dash + (dash << 8) + (dash << 16) + (dash << 24);
545   u32 *id_ptr = (u32*)descr;
546   bool print = false;  // internal_strstr(descr + 4, "AllocaTOTest") != 0;
547   u32 id = *id_ptr;
548   if (id == first_timer) {
549     u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
550     CHECK_LT(idx, kNumStackOriginDescrs);
551     StackOriginDescr[idx] = descr + 4;
552 #if SANITIZER_PPC64V1
553     // On PowerPC64 ELFv1, the address of a function actually points to a
554     // three-doubleword data structure with the first field containing
555     // the address of the function's code.
556     if (pc)
557       pc = *reinterpret_cast<uptr*>(pc);
558 #endif
559     StackOriginPC[idx] = pc;
560     id = Origin::CreateStackOrigin(idx).raw_id();
561     *id_ptr = id;
562     if (print)
563       Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc);
564   }
565   if (print)
566     Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
567   __msan_set_origin(a, size, id);
568 }
569
570 u32 __msan_chain_origin(u32 id) {
571   GET_CALLER_PC_BP_SP;
572   (void)sp;
573   GET_STORE_STACK_TRACE_PC_BP(pc, bp);
574   return ChainOrigin(id, &stack);
575 }
576
577 u32 __msan_get_origin(const void *a) {
578   if (!__msan_get_track_origins()) return 0;
579   uptr x = (uptr)a;
580   uptr aligned = x & ~3ULL;
581   uptr origin_ptr = MEM_TO_ORIGIN(aligned);
582   return *(u32*)origin_ptr;
583 }
584
585 int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id) {
586   Origin o = Origin::FromRawId(this_id);
587   while (o.raw_id() != prev_id && o.isChainedOrigin())
588     o = o.getNextChainedOrigin(nullptr);
589   return o.raw_id() == prev_id;
590 }
591
592 u32 __msan_get_umr_origin() {
593   return __msan_origin_tls;
594 }
595
596 u16 __sanitizer_unaligned_load16(const uu16 *p) {
597   *(uu16 *)&__msan_retval_tls[0] = *(uu16 *)MEM_TO_SHADOW((uptr)p);
598   if (__msan_get_track_origins())
599     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
600   return *p;
601 }
602 u32 __sanitizer_unaligned_load32(const uu32 *p) {
603   *(uu32 *)&__msan_retval_tls[0] = *(uu32 *)MEM_TO_SHADOW((uptr)p);
604   if (__msan_get_track_origins())
605     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
606   return *p;
607 }
608 u64 __sanitizer_unaligned_load64(const uu64 *p) {
609   __msan_retval_tls[0] = *(uu64 *)MEM_TO_SHADOW((uptr)p);
610   if (__msan_get_track_origins())
611     __msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
612   return *p;
613 }
614 void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
615   u16 s = *(uu16 *)&__msan_param_tls[1];
616   *(uu16 *)MEM_TO_SHADOW((uptr)p) = s;
617   if (s && __msan_get_track_origins())
618     if (uu32 o = __msan_param_origin_tls[2])
619       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
620   *p = x;
621 }
622 void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
623   u32 s = *(uu32 *)&__msan_param_tls[1];
624   *(uu32 *)MEM_TO_SHADOW((uptr)p) = s;
625   if (s && __msan_get_track_origins())
626     if (uu32 o = __msan_param_origin_tls[2])
627       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
628   *p = x;
629 }
630 void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
631   u64 s = __msan_param_tls[1];
632   *(uu64 *)MEM_TO_SHADOW((uptr)p) = s;
633   if (s && __msan_get_track_origins())
634     if (uu32 o = __msan_param_origin_tls[2])
635       SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
636   *p = x;
637 }
638
639 void __msan_set_death_callback(void (*callback)(void)) {
640   SetUserDieCallback(callback);
641 }
642
643 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
644 extern "C" {
645 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
646 const char* __msan_default_options() { return ""; }
647 }  // extern "C"
648 #endif
649
650 extern "C" {
651 SANITIZER_INTERFACE_ATTRIBUTE
652 void __sanitizer_print_stack_trace() {
653   GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME());
654   stack.Print();
655 }
656 } // extern "C"