2019-08-01 22:08:18 +08:00
|
|
|
//===-- msan.cpp ----------------------------------------------------------===//
|
2012-12-11 20:27:27 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-11 20:27:27 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of MemorySanitizer.
|
|
|
|
//
|
|
|
|
// MemorySanitizer runtime.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "msan.h"
|
2014-05-21 17:02:13 +08:00
|
|
|
#include "msan_chained_origin_depot.h"
|
|
|
|
#include "msan_origin.h"
|
2018-06-09 07:31:42 +08:00
|
|
|
#include "msan_report.h"
|
2014-04-04 17:47:41 +08:00
|
|
|
#include "msan_thread.h"
|
2015-01-22 00:42:30 +08:00
|
|
|
#include "msan_poisoning.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
#include "sanitizer_common/sanitizer_atomic.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
2015-01-15 23:13:43 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flag_parser.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
#include "sanitizer_common/sanitizer_procmaps.h"
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
2014-03-18 21:45:19 +08:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2015-04-28 08:56:48 +08:00
|
|
|
#include "ubsan/ubsan_flags.h"
|
|
|
|
#include "ubsan/ubsan_init.h"
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
// ACHTUNG! No system header includes in this file.
|
|
|
|
|
|
|
|
using namespace __sanitizer;
|
|
|
|
|
|
|
|
// Globals.
|
|
|
|
static THREADLOCAL int msan_expect_umr = 0;
|
|
|
|
static THREADLOCAL int msan_expected_umr_found = 0;
|
|
|
|
|
2013-11-19 22:47:56 +08:00
|
|
|
// Function argument shadow. Each argument starts at the next available 8-byte
|
|
|
|
// aligned address.
|
2012-12-11 20:27:27 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2014-10-22 08:12:40 +08:00
|
|
|
THREADLOCAL u64 __msan_param_tls[kMsanParamTlsSize / sizeof(u64)];
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2013-11-19 22:47:56 +08:00
|
|
|
// Function argument origin. Each argument starts at the same offset as the
|
|
|
|
// corresponding shadow in (__msan_param_tls). Slightly weird, but changing this
|
|
|
|
// would break compatibility with older prebuilt binaries.
|
2012-12-11 20:27:27 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2014-10-22 08:12:40 +08:00
|
|
|
THREADLOCAL u32 __msan_param_origin_tls[kMsanParamTlsSize / sizeof(u32)];
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2014-10-22 08:12:40 +08:00
|
|
|
THREADLOCAL u64 __msan_retval_tls[kMsanRetvalTlsSize / sizeof(u64)];
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
THREADLOCAL u32 __msan_retval_origin_tls;
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2015-12-14 22:15:32 +08:00
|
|
|
ALIGNED(16) THREADLOCAL u64 __msan_va_arg_tls[kMsanParamTlsSize / sizeof(u64)];
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2018-09-06 23:14:36 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
ALIGNED(16)
|
|
|
|
THREADLOCAL u32 __msan_va_arg_origin_tls[kMsanParamTlsSize / sizeof(u32)];
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
THREADLOCAL u64 __msan_va_arg_overflow_size_tls;
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
THREADLOCAL u32 __msan_origin_tls;
|
|
|
|
|
2013-09-23 21:26:31 +08:00
|
|
|
static THREADLOCAL int is_in_symbolizer;
|
2013-02-13 15:19:47 +08:00
|
|
|
|
2013-05-31 21:04:07 +08:00
|
|
|
extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_track_origins;
|
2013-05-31 20:04:08 +08:00
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
int __msan_get_track_origins() {
|
2013-05-31 20:04:08 +08:00
|
|
|
return &__msan_track_origins ? __msan_track_origins : 0;
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
2013-06-21 20:37:58 +08:00
|
|
|
extern "C" SANITIZER_WEAK_ATTRIBUTE const int __msan_keep_going;
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
namespace __msan {
|
|
|
|
|
2013-09-23 21:26:31 +08:00
|
|
|
void EnterSymbolizer() { ++is_in_symbolizer; }
|
|
|
|
void ExitSymbolizer() { --is_in_symbolizer; }
|
2013-02-13 15:19:47 +08:00
|
|
|
bool IsInSymbolizer() { return is_in_symbolizer; }
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
static Flags msan_flags;
|
|
|
|
|
|
|
|
Flags *flags() {
|
|
|
|
return &msan_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msan_inited = 0;
|
|
|
|
bool msan_init_is_running;
|
|
|
|
|
2013-01-10 19:17:55 +08:00
|
|
|
int msan_report_count = 0;
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
// Array of stack origins.
|
|
|
|
// FIXME: make it resizable.
|
|
|
|
static const uptr kNumStackOriginDescrs = 1024 * 1024;
|
|
|
|
static const char *StackOriginDescr[kNumStackOriginDescrs];
|
2013-09-13 20:49:13 +08:00
|
|
|
static uptr StackOriginPC[kNumStackOriginDescrs];
|
2012-12-11 20:27:27 +08:00
|
|
|
static atomic_uint32_t NumStackOriginDescrs;
|
|
|
|
|
2015-01-07 08:38:00 +08:00
|
|
|
void Flags::SetDefaults() {
|
|
|
|
#define MSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
|
|
|
|
#include "msan_flags.inc"
|
|
|
|
#undef MSAN_FLAG
|
|
|
|
}
|
2013-08-13 23:33:00 +08:00
|
|
|
|
2015-01-15 23:13:43 +08:00
|
|
|
// keep_going is an old name for halt_on_error,
|
|
|
|
// and it has inverse meaning.
|
2020-11-03 09:33:22 +08:00
|
|
|
class FlagHandlerKeepGoing final : public FlagHandlerBase {
|
2015-01-15 23:13:43 +08:00
|
|
|
bool *halt_on_error_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit FlagHandlerKeepGoing(bool *halt_on_error)
|
|
|
|
: halt_on_error_(halt_on_error) {}
|
2015-02-12 08:36:39 +08:00
|
|
|
bool Parse(const char *value) final {
|
2015-01-15 23:13:43 +08:00
|
|
|
bool tmp;
|
|
|
|
FlagHandler<bool> h(&tmp);
|
|
|
|
if (!h.Parse(value)) return false;
|
|
|
|
*halt_on_error_ = !tmp;
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-29 08:53:38 +08:00
|
|
|
bool Format(char *buffer, uptr size) final {
|
|
|
|
const char *keep_going_str = (*halt_on_error_) ? "false" : "true";
|
|
|
|
return FormatString(buffer, size, keep_going_str);
|
|
|
|
}
|
2015-01-15 23:13:43 +08:00
|
|
|
};
|
2015-01-07 08:38:00 +08:00
|
|
|
|
2015-02-12 08:36:42 +08:00
|
|
|
static void RegisterMsanFlags(FlagParser *parser, Flags *f) {
|
2015-01-15 23:13:43 +08:00
|
|
|
#define MSAN_FLAG(Type, Name, DefaultValue, Description) \
|
|
|
|
RegisterFlag(parser, #Name, Description, &f->Name);
|
2015-01-07 08:38:00 +08:00
|
|
|
#include "msan_flags.inc"
|
|
|
|
#undef MSAN_FLAG
|
2015-01-15 23:13:43 +08:00
|
|
|
|
2019-09-12 07:19:48 +08:00
|
|
|
FlagHandlerKeepGoing *fh_keep_going =
|
|
|
|
new (FlagParser::Alloc) FlagHandlerKeepGoing(&f->halt_on_error);
|
2015-01-15 23:13:43 +08:00
|
|
|
parser->RegisterHandler("keep_going", fh_keep_going,
|
|
|
|
"deprecated, use halt_on_error");
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
2015-02-12 08:36:42 +08:00
|
|
|
static void InitializeFlags() {
|
2014-12-20 05:40:04 +08:00
|
|
|
SetCommonFlagsDefaults();
|
2015-01-03 05:28:37 +08:00
|
|
|
{
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.external_symbolizer_path = GetEnv("MSAN_SYMBOLIZER_PATH");
|
|
|
|
cf.malloc_context_size = 20;
|
|
|
|
cf.handle_ioctl = true;
|
|
|
|
// FIXME: test and enable.
|
|
|
|
cf.check_printf = false;
|
|
|
|
cf.intercept_tls_get_addr = true;
|
|
|
|
OverrideCommonFlags(cf);
|
|
|
|
}
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2015-04-28 08:56:48 +08:00
|
|
|
Flags *f = flags();
|
2015-01-07 08:38:00 +08:00
|
|
|
f->SetDefaults();
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2015-04-28 08:56:48 +08:00
|
|
|
FlagParser parser;
|
|
|
|
RegisterMsanFlags(&parser, f);
|
|
|
|
RegisterCommonFlags(&parser);
|
|
|
|
|
|
|
|
#if MSAN_CONTAINS_UBSAN
|
|
|
|
__ubsan::Flags *uf = __ubsan::flags();
|
|
|
|
uf->SetDefaults();
|
|
|
|
|
|
|
|
FlagParser ubsan_parser;
|
|
|
|
__ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
|
|
|
|
RegisterCommonFlags(&ubsan_parser);
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 15:19:47 +08:00
|
|
|
// Override from user-specified string.
|
2020-09-05 10:19:20 +08:00
|
|
|
parser.ParseString(__msan_default_options());
|
2015-04-28 08:56:48 +08:00
|
|
|
#if MSAN_CONTAINS_UBSAN
|
2020-09-05 10:19:20 +08:00
|
|
|
const char *ubsan_default_options = __ubsan_default_options();
|
2015-04-28 08:56:48 +08:00
|
|
|
ubsan_parser.ParseString(ubsan_default_options);
|
|
|
|
#endif
|
2015-01-15 23:13:43 +08:00
|
|
|
|
2019-06-15 09:37:14 +08:00
|
|
|
parser.ParseStringFromEnv("MSAN_OPTIONS");
|
2015-04-28 08:56:48 +08:00
|
|
|
#if MSAN_CONTAINS_UBSAN
|
2019-06-15 09:37:14 +08:00
|
|
|
ubsan_parser.ParseStringFromEnv("UBSAN_OPTIONS");
|
2015-04-28 08:56:48 +08:00
|
|
|
#endif
|
2014-12-20 05:40:04 +08:00
|
|
|
|
2016-03-19 03:28:07 +08:00
|
|
|
InitializeCommonFlags();
|
2015-01-20 21:21:20 +08:00
|
|
|
|
|
|
|
if (Verbosity()) ReportUnrecognizedFlags();
|
2015-01-19 20:22:57 +08:00
|
|
|
|
2015-01-15 23:13:43 +08:00
|
|
|
if (common_flags()->help) parser.PrintFlagDescriptions();
|
2015-01-07 08:38:00 +08:00
|
|
|
|
2015-08-22 04:49:37 +08:00
|
|
|
// Check if deprecated exit_code MSan flag is set.
|
|
|
|
if (f->exit_code != -1) {
|
|
|
|
if (Verbosity())
|
|
|
|
Printf("MSAN_OPTIONS=exit_code is deprecated! "
|
|
|
|
"Please use MSAN_OPTIONS=exitcode instead.\n");
|
|
|
|
CommonFlags cf;
|
|
|
|
cf.CopyFrom(*common_flags());
|
|
|
|
cf.exitcode = f->exit_code;
|
|
|
|
OverrideCommonFlags(cf);
|
2015-01-07 08:38:00 +08:00
|
|
|
}
|
2015-08-22 04:49:37 +08:00
|
|
|
|
|
|
|
// Check flag values:
|
2015-01-07 08:38:00 +08:00
|
|
|
if (f->origin_history_size < 0 ||
|
|
|
|
f->origin_history_size > Origin::kMaxDepth) {
|
|
|
|
Printf(
|
|
|
|
"Origin history size invalid: %d. Must be 0 (unlimited) or in [1, %d] "
|
|
|
|
"range.\n",
|
|
|
|
f->origin_history_size, Origin::kMaxDepth);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
// Limiting to kStackDepotMaxUseCount / 2 to avoid overflow in
|
|
|
|
// StackDepotHandle::inc_use_count_unsafe.
|
|
|
|
if (f->origin_history_per_stack_limit < 0 ||
|
|
|
|
f->origin_history_per_stack_limit > kStackDepotMaxUseCount / 2) {
|
|
|
|
Printf(
|
|
|
|
"Origin per-stack limit invalid: %d. Must be 0 (unlimited) or in [1, "
|
|
|
|
"%d] range.\n",
|
|
|
|
f->origin_history_per_stack_limit, kStackDepotMaxUseCount / 2);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
if (f->store_context_size < 1) f->store_context_size = 1;
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintWarning(uptr pc, uptr bp) {
|
|
|
|
PrintWarningWithOrigin(pc, bp, __msan_origin_tls);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin) {
|
|
|
|
if (msan_expect_umr) {
|
|
|
|
// Printf("Expected UMR\n");
|
|
|
|
__msan_origin_tls = origin;
|
|
|
|
msan_expected_umr_found = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:17:55 +08:00
|
|
|
++msan_report_count;
|
|
|
|
|
2014-05-26 21:08:08 +08:00
|
|
|
GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
|
2012-12-26 17:32:05 +08:00
|
|
|
|
|
|
|
u32 report_origin =
|
2014-12-03 21:58:40 +08:00
|
|
|
(__msan_get_track_origins() && Origin::isValidId(origin)) ? origin : 0;
|
2012-12-26 17:32:05 +08:00
|
|
|
ReportUMR(&stack, report_origin);
|
|
|
|
|
2014-12-03 21:58:40 +08:00
|
|
|
if (__msan_get_track_origins() && !Origin::isValidId(origin)) {
|
2013-10-24 19:52:48 +08:00
|
|
|
Printf(
|
|
|
|
" ORIGIN: invalid (%x). Might be a bug in MemorySanitizer origin "
|
|
|
|
"tracking.\n This could still be a bug in your code, too!\n",
|
|
|
|
origin);
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:50:56 +08:00
|
|
|
void UnpoisonParam(uptr n) {
|
|
|
|
internal_memset(__msan_param_tls, 0, n * sizeof(*__msan_param_tls));
|
|
|
|
}
|
|
|
|
|
2013-08-27 22:08:15 +08:00
|
|
|
// Backup MSan runtime TLS state.
|
|
|
|
// Implementation must be async-signal-safe.
|
|
|
|
// Instances of this class may live on the signal handler stack, and data size
|
|
|
|
// may be an issue.
|
|
|
|
void ScopedThreadLocalStateBackup::Backup() {
|
|
|
|
va_arg_overflow_size_tls = __msan_va_arg_overflow_size_tls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopedThreadLocalStateBackup::Restore() {
|
|
|
|
// A lame implementation that only keeps essential state and resets the rest.
|
|
|
|
__msan_va_arg_overflow_size_tls = va_arg_overflow_size_tls;
|
|
|
|
|
2013-08-27 20:59:39 +08:00
|
|
|
internal_memset(__msan_param_tls, 0, sizeof(__msan_param_tls));
|
|
|
|
internal_memset(__msan_retval_tls, 0, sizeof(__msan_retval_tls));
|
|
|
|
internal_memset(__msan_va_arg_tls, 0, sizeof(__msan_va_arg_tls));
|
2018-09-06 23:14:36 +08:00
|
|
|
internal_memset(__msan_va_arg_origin_tls, 0,
|
|
|
|
sizeof(__msan_va_arg_origin_tls));
|
2013-08-27 22:08:15 +08:00
|
|
|
|
|
|
|
if (__msan_get_track_origins()) {
|
2014-02-03 15:27:01 +08:00
|
|
|
internal_memset(&__msan_retval_origin_tls, 0,
|
|
|
|
sizeof(__msan_retval_origin_tls));
|
2013-08-28 19:26:09 +08:00
|
|
|
internal_memset(__msan_param_origin_tls, 0,
|
|
|
|
sizeof(__msan_param_origin_tls));
|
2013-08-27 22:08:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnpoisonThreadLocalState() {
|
2013-08-27 20:59:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-21 17:02:13 +08:00
|
|
|
const char *GetStackOriginDescr(u32 id, uptr *pc) {
|
2013-09-13 20:49:13 +08:00
|
|
|
CHECK_LT(id, kNumStackOriginDescrs);
|
|
|
|
if (pc) *pc = StackOriginPC[id];
|
|
|
|
return StackOriginDescr[id];
|
|
|
|
}
|
|
|
|
|
2014-03-18 21:45:19 +08:00
|
|
|
u32 ChainOrigin(u32 id, StackTrace *stack) {
|
2014-05-08 05:23:12 +08:00
|
|
|
MsanThread *t = GetCurrentThread();
|
|
|
|
if (t && t->InSignalHandler())
|
2014-04-23 22:01:57 +08:00
|
|
|
return id;
|
2014-05-21 17:02:13 +08:00
|
|
|
|
2014-12-03 21:58:40 +08:00
|
|
|
Origin o = Origin::FromRawId(id);
|
2015-01-22 21:33:16 +08:00
|
|
|
stack->tag = StackTrace::TAG_UNKNOWN;
|
2014-12-03 21:58:40 +08:00
|
|
|
Origin chained = Origin::CreateChainedOrigin(o, stack);
|
|
|
|
return chained.raw_id();
|
2014-03-18 21:45:19 +08:00
|
|
|
}
|
|
|
|
|
2015-10-01 08:22:21 +08:00
|
|
|
} // namespace __msan
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2019-03-02 06:10:49 +08:00
|
|
|
void __sanitizer::BufferedStackTrace::UnwindImpl(
|
|
|
|
uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
|
2019-02-28 06:16:02 +08:00
|
|
|
using namespace __msan;
|
|
|
|
MsanThread *t = GetCurrentThread();
|
2019-03-02 06:10:49 +08:00
|
|
|
if (!t || !StackTrace::WillUseFastUnwind(request_fast)) {
|
2019-02-28 06:16:02 +08:00
|
|
|
// Block reports from our interceptors during _Unwind_Backtrace.
|
|
|
|
SymbolizerScope sym_scope;
|
2019-03-02 06:10:49 +08:00
|
|
|
return Unwind(max_depth, pc, bp, context, 0, 0, false);
|
2019-02-28 06:16:02 +08:00
|
|
|
}
|
2019-03-02 06:10:49 +08:00
|
|
|
if (StackTrace::WillUseFastUnwind(request_fast))
|
|
|
|
Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(), true);
|
2019-02-28 06:16:02 +08:00
|
|
|
else
|
2019-03-02 06:10:49 +08:00
|
|
|
Unwind(max_depth, pc, 0, context, 0, 0, false);
|
2019-02-28 06:16:02 +08:00
|
|
|
}
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
// Interface.
|
|
|
|
|
|
|
|
using namespace __msan;
|
|
|
|
|
2014-04-18 20:15:24 +08:00
|
|
|
#define MSAN_MAYBE_WARNING(type, size) \
|
|
|
|
void __msan_maybe_warning_##size(type s, u32 o) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
|
|
|
(void) sp; \
|
|
|
|
if (UNLIKELY(s)) { \
|
|
|
|
PrintWarningWithOrigin(pc, bp, o); \
|
|
|
|
if (__msan::flags()->halt_on_error) { \
|
|
|
|
Printf("Exiting\n"); \
|
|
|
|
Die(); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
MSAN_MAYBE_WARNING(u8, 1)
|
|
|
|
MSAN_MAYBE_WARNING(u16, 2)
|
|
|
|
MSAN_MAYBE_WARNING(u32, 4)
|
|
|
|
MSAN_MAYBE_WARNING(u64, 8)
|
|
|
|
|
|
|
|
#define MSAN_MAYBE_STORE_ORIGIN(type, size) \
|
|
|
|
void __msan_maybe_store_origin_##size(type s, void *p, u32 o) { \
|
2014-06-25 22:41:57 +08:00
|
|
|
if (UNLIKELY(s)) { \
|
|
|
|
if (__msan_get_track_origins() > 1) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
|
|
|
(void) sp; \
|
|
|
|
GET_STORE_STACK_TRACE_PC_BP(pc, bp); \
|
|
|
|
o = ChainOrigin(o, &stack); \
|
|
|
|
} \
|
|
|
|
*(u32 *)MEM_TO_ORIGIN((uptr)p & ~3UL) = o; \
|
|
|
|
} \
|
2014-04-18 20:15:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MSAN_MAYBE_STORE_ORIGIN(u8, 1)
|
|
|
|
MSAN_MAYBE_STORE_ORIGIN(u16, 2)
|
|
|
|
MSAN_MAYBE_STORE_ORIGIN(u32, 4)
|
|
|
|
MSAN_MAYBE_STORE_ORIGIN(u64, 8)
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void __msan_warning() {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
PrintWarning(pc, bp);
|
2013-08-13 23:33:00 +08:00
|
|
|
if (__msan::flags()->halt_on_error) {
|
2014-05-21 17:56:28 +08:00
|
|
|
if (__msan::flags()->print_stats)
|
|
|
|
ReportStats();
|
2013-06-21 20:37:58 +08:00
|
|
|
Printf("Exiting\n");
|
|
|
|
Die();
|
|
|
|
}
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __msan_warning_noreturn() {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
PrintWarning(pc, bp);
|
2014-05-21 17:56:28 +08:00
|
|
|
if (__msan::flags()->print_stats)
|
|
|
|
ReportStats();
|
2012-12-11 20:27:27 +08:00
|
|
|
Printf("Exiting\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
[MSAN] Pass Origin by parameter to __msan_warning functions
Summary:
Normally, the Origin is passed over TLS, which seems like it introduces unnecessary overhead. It's in the (extremely) cold path though, so the only overhead is in code size.
But with eager-checks, calls to __msan_warning functions are extremely common, so this becomes a useful optimization.
This can save ~5% code size.
Reviewers: eugenis, vitalybuka
Reviewed By: eugenis, vitalybuka
Subscribers: hiraditya, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D81700
2020-06-16 06:17:00 +08:00
|
|
|
void __msan_warning_with_origin(u32 origin) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
PrintWarningWithOrigin(pc, bp, origin);
|
|
|
|
if (__msan::flags()->halt_on_error) {
|
|
|
|
if (__msan::flags()->print_stats)
|
|
|
|
ReportStats();
|
|
|
|
Printf("Exiting\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __msan_warning_with_origin_noreturn(u32 origin) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
PrintWarningWithOrigin(pc, bp, origin);
|
|
|
|
if (__msan::flags()->print_stats)
|
|
|
|
ReportStats();
|
|
|
|
Printf("Exiting\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2017-11-10 10:06:59 +08:00
|
|
|
static void OnStackUnwind(const SignalContext &sig, const void *,
|
|
|
|
BufferedStackTrace *stack) {
|
2019-10-03 05:20:37 +08:00
|
|
|
stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context,
|
2017-11-10 10:06:59 +08:00
|
|
|
common_flags()->fast_unwind_on_fatal);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MsanOnDeadlySignal(int signo, void *siginfo, void *context) {
|
|
|
|
HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
|
|
|
|
}
|
|
|
|
|
2018-02-27 02:27:24 +08:00
|
|
|
static void MsanCheckFailed(const char *file, int line, const char *cond,
|
|
|
|
u64 v1, u64 v2) {
|
|
|
|
Report("MemorySanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
|
|
|
|
line, cond, (uptr)v1, (uptr)v2);
|
|
|
|
PRINT_CURRENT_STACK_CHECK();
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void __msan_init() {
|
2013-12-13 17:11:14 +08:00
|
|
|
CHECK(!msan_init_is_running);
|
2012-12-11 20:27:27 +08:00
|
|
|
if (msan_inited) return;
|
|
|
|
msan_init_is_running = 1;
|
2013-01-31 22:11:21 +08:00
|
|
|
SanitizerToolName = "MemorySanitizer";
|
2012-12-11 20:27:27 +08:00
|
|
|
|
[sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.
In short, CVE-2016-2143 will crash the machine if a process uses both >4TB
virtual addresses and fork(). ASan, TSan, and MSan will, by necessity, map
a sizable chunk of virtual address space, which is much larger than 4TB.
Even worse, sanitizers will always use fork() for llvm-symbolizer when a bug
is detected. Disable all three by aborting on process initialization if
the running kernel version is not known to contain a fix.
Unfortunately, there's no reliable way to detect the fix without crashing
the kernel. So, we rely on whitelisting - I've included a list of upstream
kernel versions that will work. In case someone uses a distribution kernel
or applied the fix themselves, an override switch is also included.
Differential Revision: http://reviews.llvm.org/D19576
llvm-svn: 267747
2016-04-28 01:42:00 +08:00
|
|
|
AvoidCVE_2016_2143();
|
2013-11-11 19:28:30 +08:00
|
|
|
|
2015-06-04 15:29:43 +08:00
|
|
|
CacheBinaryName();
|
2015-07-22 07:03:13 +08:00
|
|
|
InitializeFlags();
|
2015-09-15 21:22:54 +08:00
|
|
|
|
2018-02-27 02:27:24 +08:00
|
|
|
// Install tool-specific callbacks in sanitizer_common.
|
|
|
|
SetCheckFailedCallback(MsanCheckFailed);
|
|
|
|
|
2013-11-11 19:28:30 +08:00
|
|
|
__sanitizer_set_report_path(common_flags()->log_path);
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
InitializeInterceptors();
|
2019-08-23 05:36:35 +08:00
|
|
|
CheckASLR();
|
2018-06-18 01:31:22 +08:00
|
|
|
InitTlsSize();
|
2017-11-10 10:06:59 +08:00
|
|
|
InstallDeadlySignalHandlers(MsanOnDeadlySignal);
|
2013-09-27 19:32:21 +08:00
|
|
|
InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2014-08-13 06:37:47 +08:00
|
|
|
DisableCoreDumperIfNecessary();
|
2012-12-11 20:27:27 +08:00
|
|
|
if (StackSizeIsUnlimited()) {
|
2013-12-05 20:04:51 +08:00
|
|
|
VPrintf(1, "Unlimited stack, doing reexec\n");
|
2012-12-11 20:27:27 +08:00
|
|
|
// A reasonably large stack size. It is bigger than the usual 8Mb, because,
|
|
|
|
// well, the program could have been run with unlimited stack for a reason.
|
|
|
|
SetStackSizeLimitInBytes(32 * 1024 * 1024);
|
|
|
|
ReExec();
|
|
|
|
}
|
2013-02-19 19:09:29 +08:00
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
__msan_clear_on_return();
|
2013-12-05 20:04:51 +08:00
|
|
|
if (__msan_get_track_origins())
|
|
|
|
VPrintf(1, "msan_track_origins\n");
|
2015-05-24 10:47:59 +08:00
|
|
|
if (!InitShadow(__msan_get_track_origins())) {
|
2012-12-26 14:37:23 +08:00
|
|
|
Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n");
|
2012-12-11 20:27:27 +08:00
|
|
|
Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n");
|
2012-12-26 14:37:23 +08:00
|
|
|
Printf("FATAL: Disabling ASLR is known to cause this error.\n");
|
2012-12-27 22:09:19 +08:00
|
|
|
Printf("FATAL: If running under GDB, try "
|
|
|
|
"'set disable-randomization off'.\n");
|
2012-12-11 20:27:27 +08:00
|
|
|
DumpProcessMap();
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2014-07-26 09:37:23 +08:00
|
|
|
Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
|
2012-12-11 20:27:27 +08:00
|
|
|
|
2014-12-26 20:32:32 +08:00
|
|
|
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
|
2014-12-04 07:29:14 +08:00
|
|
|
|
2014-04-04 17:47:41 +08:00
|
|
|
MsanTSDInit(MsanTSDDtor);
|
|
|
|
|
2015-09-30 05:28:54 +08:00
|
|
|
MsanAllocatorInit();
|
|
|
|
|
2015-10-01 08:22:21 +08:00
|
|
|
MsanThread *main_thread = MsanThread::Create(nullptr, nullptr);
|
2014-04-04 17:47:41 +08:00
|
|
|
SetCurrentThread(main_thread);
|
|
|
|
main_thread->ThreadStart();
|
|
|
|
|
2015-04-28 08:56:48 +08:00
|
|
|
#if MSAN_CONTAINS_UBSAN
|
|
|
|
__ubsan::InitAsPlugin();
|
|
|
|
#endif
|
|
|
|
|
2013-12-05 20:04:51 +08:00
|
|
|
VPrintf(1, "MemorySanitizer init done\n");
|
2013-12-13 21:13:46 +08:00
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
msan_init_is_running = 0;
|
|
|
|
msan_inited = 1;
|
|
|
|
}
|
|
|
|
|
2013-06-21 20:37:58 +08:00
|
|
|
void __msan_set_keep_going(int keep_going) {
|
2013-08-13 23:33:00 +08:00
|
|
|
flags()->halt_on_error = !keep_going;
|
2013-06-21 20:37:58 +08:00
|
|
|
}
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
void __msan_set_expect_umr(int expect_umr) {
|
|
|
|
if (expect_umr) {
|
|
|
|
msan_expected_umr_found = 0;
|
|
|
|
} else if (!msan_expected_umr_found) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
2014-05-26 21:08:08 +08:00
|
|
|
GET_FATAL_STACK_TRACE_PC_BP(pc, bp);
|
2012-12-26 17:32:05 +08:00
|
|
|
ReportExpectedUMRNotFound(&stack);
|
2012-12-11 20:27:27 +08:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
msan_expect_umr = expect_umr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __msan_print_shadow(const void *x, uptr size) {
|
2013-11-01 23:53:25 +08:00
|
|
|
if (!MEM_IS_APP(x)) {
|
|
|
|
Printf("Not a valid application address: %p\n", x);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-30 17:50:30 +08:00
|
|
|
|
|
|
|
DescribeMemoryRange(x, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __msan_dump_shadow(const void *x, uptr size) {
|
|
|
|
if (!MEM_IS_APP(x)) {
|
|
|
|
Printf("Not a valid application address: %p\n", x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
unsigned char *s = (unsigned char*)MEM_TO_SHADOW(x);
|
2016-02-26 14:44:10 +08:00
|
|
|
for (uptr i = 0; i < size; i++)
|
2012-12-11 20:27:27 +08:00
|
|
|
Printf("%x%x ", s[i] >> 4, s[i] & 0xf);
|
|
|
|
Printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sptr __msan_test_shadow(const void *x, uptr size) {
|
2013-12-06 17:19:07 +08:00
|
|
|
if (!MEM_IS_APP(x)) return -1;
|
|
|
|
unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
|
2020-08-11 03:03:40 +08:00
|
|
|
if (__sanitizer::mem_is_zero((const char *)s, size))
|
|
|
|
return -1;
|
|
|
|
// Slow path: loop through again to find the location.
|
2012-12-11 20:27:27 +08:00
|
|
|
for (uptr i = 0; i < size; ++i)
|
|
|
|
if (s[i])
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-02 19:50:42 +08:00
|
|
|
void __msan_check_mem_is_initialized(const void *x, uptr size) {
|
|
|
|
if (!__msan::flags()->report_umrs) return;
|
2014-05-07 19:50:14 +08:00
|
|
|
sptr offset = __msan_test_shadow(x, size);
|
2014-04-02 19:50:42 +08:00
|
|
|
if (offset < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
2014-05-07 19:50:14 +08:00
|
|
|
ReportUMRInsideAddressRange(__func__, x, size, offset);
|
2014-04-02 19:50:42 +08:00
|
|
|
__msan::PrintWarningWithOrigin(pc, bp,
|
2014-11-14 06:40:59 +08:00
|
|
|
__msan_get_origin(((const char *)x) + offset));
|
2014-04-02 19:50:42 +08:00
|
|
|
if (__msan::flags()->halt_on_error) {
|
|
|
|
Printf("Exiting\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:27:27 +08:00
|
|
|
int __msan_set_poison_in_malloc(int do_poison) {
|
|
|
|
int old = flags()->poison_in_malloc;
|
|
|
|
flags()->poison_in_malloc = do_poison;
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:33:15 +08:00
|
|
|
int __msan_has_dynamic_component() { return false; }
|
2012-12-11 20:27:27 +08:00
|
|
|
|
|
|
|
NOINLINE
|
|
|
|
void __msan_clear_on_return() {
|
|
|
|
__msan_param_tls[0] = 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:34:19 +08:00
|
|
|
void __msan_partial_poison(const void* data, void* shadow, uptr size) {
|
2012-12-11 20:27:27 +08:00
|
|
|
internal_memcpy((void*)MEM_TO_SHADOW((uptr)data), shadow, size);
|
|
|
|
}
|
|
|
|
|
2015-07-18 07:28:00 +08:00
|
|
|
void __msan_load_unpoisoned(const void *src, uptr size, void *dst) {
|
2012-12-11 20:27:27 +08:00
|
|
|
internal_memcpy(dst, src, size);
|
|
|
|
__msan_unpoison(dst, size);
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:34:19 +08:00
|
|
|
void __msan_set_origin(const void *a, uptr size, u32 origin) {
|
2015-01-22 00:42:30 +08:00
|
|
|
if (__msan_get_track_origins()) SetOrigin(a, size, origin);
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 'descr' is created at compile time and contains '----' in the beginning.
|
|
|
|
// When we see descr for the first time we replace '----' with a uniq id
|
|
|
|
// and set the origin to (id | (31-th bit)).
|
2014-11-14 06:40:59 +08:00
|
|
|
void __msan_set_alloca_origin(void *a, uptr size, char *descr) {
|
2013-09-13 20:49:13 +08:00
|
|
|
__msan_set_alloca_origin4(a, size, descr, 0);
|
|
|
|
}
|
|
|
|
|
2014-11-14 06:40:59 +08:00
|
|
|
void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc) {
|
2012-12-11 20:27:27 +08:00
|
|
|
static const u32 dash = '-';
|
|
|
|
static const u32 first_timer =
|
|
|
|
dash + (dash << 8) + (dash << 16) + (dash << 24);
|
|
|
|
u32 *id_ptr = (u32*)descr;
|
|
|
|
bool print = false; // internal_strstr(descr + 4, "AllocaTOTest") != 0;
|
|
|
|
u32 id = *id_ptr;
|
|
|
|
if (id == first_timer) {
|
2014-05-21 17:02:13 +08:00
|
|
|
u32 idx = atomic_fetch_add(&NumStackOriginDescrs, 1, memory_order_relaxed);
|
|
|
|
CHECK_LT(idx, kNumStackOriginDescrs);
|
|
|
|
StackOriginDescr[idx] = descr + 4;
|
2016-04-28 05:24:24 +08:00
|
|
|
#if SANITIZER_PPC64V1
|
|
|
|
// On PowerPC64 ELFv1, the address of a function actually points to a
|
|
|
|
// three-doubleword data structure with the first field containing
|
|
|
|
// the address of the function's code.
|
|
|
|
if (pc)
|
|
|
|
pc = *reinterpret_cast<uptr*>(pc);
|
|
|
|
#endif
|
2014-05-21 17:02:13 +08:00
|
|
|
StackOriginPC[idx] = pc;
|
2014-12-03 21:58:40 +08:00
|
|
|
id = Origin::CreateStackOrigin(idx).raw_id();
|
2012-12-11 20:27:27 +08:00
|
|
|
*id_ptr = id;
|
|
|
|
if (print)
|
2014-05-21 17:02:13 +08:00
|
|
|
Printf("First time: idx=%d id=%d %s %p \n", idx, id, descr + 4, pc);
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
if (print)
|
|
|
|
Printf("__msan_set_alloca_origin: descr=%s id=%x\n", descr + 4, id);
|
2014-12-03 21:58:40 +08:00
|
|
|
__msan_set_origin(a, size, id);
|
2012-12-11 20:27:27 +08:00
|
|
|
}
|
|
|
|
|
2014-03-18 21:45:19 +08:00
|
|
|
u32 __msan_chain_origin(u32 id) {
|
2014-03-31 22:18:55 +08:00
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
(void)sp;
|
|
|
|
GET_STORE_STACK_TRACE_PC_BP(pc, bp);
|
2014-03-18 21:45:19 +08:00
|
|
|
return ChainOrigin(id, &stack);
|
|
|
|
}
|
|
|
|
|
2013-04-23 21:34:19 +08:00
|
|
|
u32 __msan_get_origin(const void *a) {
|
2013-05-31 20:04:08 +08:00
|
|
|
if (!__msan_get_track_origins()) return 0;
|
2012-12-11 20:27:27 +08:00
|
|
|
uptr x = (uptr)a;
|
|
|
|
uptr aligned = x & ~3ULL;
|
|
|
|
uptr origin_ptr = MEM_TO_ORIGIN(aligned);
|
|
|
|
return *(u32*)origin_ptr;
|
|
|
|
}
|
|
|
|
|
2015-02-26 23:19:33 +08:00
|
|
|
int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id) {
|
|
|
|
Origin o = Origin::FromRawId(this_id);
|
|
|
|
while (o.raw_id() != prev_id && o.isChainedOrigin())
|
|
|
|
o = o.getNextChainedOrigin(nullptr);
|
|
|
|
return o.raw_id() == prev_id;
|
|
|
|
}
|
|
|
|
|
2013-01-29 22:33:29 +08:00
|
|
|
u32 __msan_get_umr_origin() {
|
2012-12-11 20:27:27 +08:00
|
|
|
return __msan_origin_tls;
|
|
|
|
}
|
2013-02-13 15:19:47 +08:00
|
|
|
|
2013-06-04 21:49:10 +08:00
|
|
|
u16 __sanitizer_unaligned_load16(const uu16 *p) {
|
2020-05-28 23:50:31 +08:00
|
|
|
internal_memcpy(&__msan_retval_tls[0], (void *)MEM_TO_SHADOW((uptr)p),
|
|
|
|
sizeof(uu16));
|
2013-10-16 16:25:13 +08:00
|
|
|
if (__msan_get_track_origins())
|
2014-04-02 19:06:35 +08:00
|
|
|
__msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
|
2013-06-04 21:49:10 +08:00
|
|
|
return *p;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
2013-06-04 21:49:10 +08:00
|
|
|
u32 __sanitizer_unaligned_load32(const uu32 *p) {
|
2020-05-28 23:50:31 +08:00
|
|
|
internal_memcpy(&__msan_retval_tls[0], (void *)MEM_TO_SHADOW((uptr)p),
|
|
|
|
sizeof(uu32));
|
2013-10-16 16:25:13 +08:00
|
|
|
if (__msan_get_track_origins())
|
2014-04-02 19:06:35 +08:00
|
|
|
__msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
|
2013-06-04 21:49:10 +08:00
|
|
|
return *p;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
2013-06-04 21:49:10 +08:00
|
|
|
u64 __sanitizer_unaligned_load64(const uu64 *p) {
|
2020-05-28 23:50:31 +08:00
|
|
|
internal_memcpy(&__msan_retval_tls[0], (void *)MEM_TO_SHADOW((uptr)p),
|
|
|
|
sizeof(uu64));
|
2013-10-16 16:25:13 +08:00
|
|
|
if (__msan_get_track_origins())
|
2014-04-02 19:06:35 +08:00
|
|
|
__msan_retval_origin_tls = GetOriginIfPoisoned((uptr)p, sizeof(*p));
|
2013-06-04 21:49:10 +08:00
|
|
|
return *p;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
2013-06-04 21:49:10 +08:00
|
|
|
void __sanitizer_unaligned_store16(uu16 *p, u16 x) {
|
2020-05-28 23:50:31 +08:00
|
|
|
static_assert(sizeof(uu16) == sizeof(u16), "incompatible types");
|
|
|
|
u16 s;
|
|
|
|
internal_memcpy(&s, &__msan_param_tls[1], sizeof(uu16));
|
|
|
|
internal_memcpy((void *)MEM_TO_SHADOW((uptr)p), &s, sizeof(uu16));
|
2014-04-02 19:06:35 +08:00
|
|
|
if (s && __msan_get_track_origins())
|
2013-11-19 22:47:56 +08:00
|
|
|
if (uu32 o = __msan_param_origin_tls[2])
|
2014-04-02 19:06:35 +08:00
|
|
|
SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
|
2013-06-04 21:49:10 +08:00
|
|
|
*p = x;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
2013-06-04 21:49:10 +08:00
|
|
|
void __sanitizer_unaligned_store32(uu32 *p, u32 x) {
|
2020-05-28 23:50:31 +08:00
|
|
|
static_assert(sizeof(uu32) == sizeof(u32), "incompatible types");
|
|
|
|
u32 s;
|
|
|
|
internal_memcpy(&s, &__msan_param_tls[1], sizeof(uu32));
|
|
|
|
internal_memcpy((void *)MEM_TO_SHADOW((uptr)p), &s, sizeof(uu32));
|
2014-04-02 19:06:35 +08:00
|
|
|
if (s && __msan_get_track_origins())
|
2013-11-19 22:47:56 +08:00
|
|
|
if (uu32 o = __msan_param_origin_tls[2])
|
2014-04-02 19:06:35 +08:00
|
|
|
SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
|
2013-06-04 21:49:10 +08:00
|
|
|
*p = x;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
2013-06-04 21:49:10 +08:00
|
|
|
void __sanitizer_unaligned_store64(uu64 *p, u64 x) {
|
2014-04-02 19:06:35 +08:00
|
|
|
u64 s = __msan_param_tls[1];
|
|
|
|
*(uu64 *)MEM_TO_SHADOW((uptr)p) = s;
|
|
|
|
if (s && __msan_get_track_origins())
|
2013-11-19 22:47:56 +08:00
|
|
|
if (uu32 o = __msan_param_origin_tls[2])
|
2014-04-02 19:06:35 +08:00
|
|
|
SetOriginIfPoisoned((uptr)p, (uptr)&s, sizeof(s), o);
|
2013-06-04 21:49:10 +08:00
|
|
|
*p = x;
|
2013-06-04 21:08:36 +08:00
|
|
|
}
|
|
|
|
|
2014-03-27 22:04:58 +08:00
|
|
|
void __msan_set_death_callback(void (*callback)(void)) {
|
2015-08-22 06:45:12 +08:00
|
|
|
SetUserDieCallback(callback);
|
2014-03-27 22:04:58 +08:00
|
|
|
}
|
|
|
|
|
2020-08-28 10:21:59 +08:00
|
|
|
void __msan_start_switch_fiber(const void *bottom, uptr size) {
|
|
|
|
MsanThread *t = GetCurrentThread();
|
|
|
|
if (!t) {
|
|
|
|
VReport(1, "__msan_start_switch_fiber called from unknown thread\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->StartSwitchFiber((uptr)bottom, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __msan_finish_switch_fiber(const void **bottom_old, uptr *size_old) {
|
|
|
|
MsanThread *t = GetCurrentThread();
|
|
|
|
if (!t) {
|
|
|
|
VReport(1, "__msan_finish_switch_fiber called from unknown thread\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->FinishSwitchFiber((uptr *)bottom_old, (uptr *)size_old);
|
|
|
|
|
|
|
|
internal_memset(__msan_param_tls, 0, sizeof(__msan_param_tls));
|
|
|
|
internal_memset(__msan_retval_tls, 0, sizeof(__msan_retval_tls));
|
|
|
|
internal_memset(__msan_va_arg_tls, 0, sizeof(__msan_va_arg_tls));
|
|
|
|
|
|
|
|
if (__msan_get_track_origins()) {
|
|
|
|
internal_memset(__msan_param_origin_tls, 0,
|
|
|
|
sizeof(__msan_param_origin_tls));
|
|
|
|
internal_memset(&__msan_retval_origin_tls, 0,
|
|
|
|
sizeof(__msan_retval_origin_tls));
|
|
|
|
internal_memset(__msan_va_arg_origin_tls, 0,
|
|
|
|
sizeof(__msan_va_arg_origin_tls));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 10:19:20 +08:00
|
|
|
SANITIZER_INTERFACE_WEAK_DEF(const char *, __msan_default_options, void) {
|
|
|
|
return "";
|
|
|
|
}
|
2014-05-26 21:08:08 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_print_stack_trace() {
|
|
|
|
GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME());
|
|
|
|
stack.Print();
|
|
|
|
}
|
2015-10-01 08:22:21 +08:00
|
|
|
} // extern "C"
|