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