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