2019-08-14 10:47:11 +02:00
|
|
|
//===-- tsan_rtl_thread.cpp -----------------------------------------------===//
|
2012-11-22 23:03:11 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02: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-11-22 23:03:11 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_report.h"
|
|
|
|
#include "tsan_sync.h"
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// ThreadContext implementation.
|
|
|
|
|
|
|
|
ThreadContext::ThreadContext(int tid)
|
|
|
|
: ThreadContextBase(tid)
|
|
|
|
, thr()
|
|
|
|
, sync()
|
|
|
|
, epoch0()
|
|
|
|
, epoch1() {
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-11-04 22:33:31 +01:00
|
|
|
ThreadContext::~ThreadContext() {
|
|
|
|
}
|
2012-11-22 23:03:11 +01:00
|
|
|
#endif
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void ThreadContext::OnDead() {
|
2014-09-23 19:59:53 +02:00
|
|
|
CHECK_EQ(sync.size(), 0);
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadContext::OnJoined(void *arg) {
|
|
|
|
ThreadState *caller_thr = static_cast<ThreadState *>(arg);
|
2013-12-05 10:18:38 +01:00
|
|
|
AcquireImpl(caller_thr, 0, &sync);
|
2016-11-08 23:04:09 +01:00
|
|
|
sync.Reset(&caller_thr->proc()->clock_cache);
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct OnCreatedArgs {
|
|
|
|
ThreadState *thr;
|
|
|
|
uptr pc;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ThreadContext::OnCreated(void *arg) {
|
|
|
|
thr = 0;
|
|
|
|
if (tid == 0)
|
2012-11-22 23:03:11 +01:00
|
|
|
return;
|
2013-11-04 22:33:31 +01:00
|
|
|
OnCreatedArgs *args = static_cast<OnCreatedArgs *>(arg);
|
2015-11-23 10:07:18 +01:00
|
|
|
if (!args->thr) // GCD workers don't have a parent thread.
|
|
|
|
return;
|
2013-11-04 22:33:31 +01:00
|
|
|
args->thr->fast_state.IncrementEpoch();
|
|
|
|
// Can't increment epoch w/o writing to the trace as well.
|
|
|
|
TraceAddEvent(args->thr, args->thr->fast_state, EventTypeMop, 0);
|
2013-12-05 10:18:38 +01:00
|
|
|
ReleaseImpl(args->thr, 0, &sync);
|
2013-11-04 22:33:31 +01:00
|
|
|
creation_stack_id = CurrentStackId(args->thr, args->pc);
|
|
|
|
if (reuse_count == 0)
|
|
|
|
StatInc(args->thr, StatThreadMaxTid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadContext::OnReset() {
|
2014-09-23 19:59:53 +02:00
|
|
|
CHECK_EQ(sync.size(), 0);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
uptr trace_p = GetThreadTrace(tid);
|
|
|
|
ReleaseMemoryPagesToOS(trace_p, trace_p + TraceSize() * sizeof(Event));
|
2016-11-08 23:04:09 +01:00
|
|
|
//!!! ReleaseMemoryToOS(GetThreadTraceHeader(tid), sizeof(Trace));
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void ThreadContext::OnDetached(void *arg) {
|
|
|
|
ThreadState *thr1 = static_cast<ThreadState*>(arg);
|
2016-11-08 23:04:09 +01:00
|
|
|
sync.Reset(&thr1->proc()->clock_cache);
|
2014-09-23 19:59:53 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
struct OnStartedArgs {
|
|
|
|
ThreadState *thr;
|
|
|
|
uptr stk_addr;
|
|
|
|
uptr stk_size;
|
|
|
|
uptr tls_addr;
|
|
|
|
uptr tls_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ThreadContext::OnStarted(void *arg) {
|
|
|
|
OnStartedArgs *args = static_cast<OnStartedArgs*>(arg);
|
|
|
|
thr = args->thr;
|
|
|
|
// RoundUp so that one trace part does not contain events
|
|
|
|
// from different threads.
|
|
|
|
epoch0 = RoundUp(epoch1 + 1, kTracePartSize);
|
|
|
|
epoch1 = (u64)-1;
|
2014-05-22 09:09:21 +02:00
|
|
|
new(thr) ThreadState(ctx, tid, unique_id, epoch0, reuse_count,
|
|
|
|
args->stk_addr, args->stk_size, args->tls_addr, args->tls_size);
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-12-05 10:18:38 +01:00
|
|
|
thr->shadow_stack = &ThreadTrace(thr->tid)->shadow_stack[0];
|
|
|
|
thr->shadow_stack_pos = thr->shadow_stack;
|
|
|
|
thr->shadow_stack_end = thr->shadow_stack + kShadowStackSize;
|
|
|
|
#else
|
2013-11-04 22:33:31 +01:00
|
|
|
// Setup dynamic shadow stack.
|
|
|
|
const int kInitStackSize = 8;
|
2013-12-05 10:18:38 +01:00
|
|
|
thr->shadow_stack = (uptr*)internal_alloc(MBlockShadowStack,
|
2013-11-04 22:33:31 +01:00
|
|
|
kInitStackSize * sizeof(uptr));
|
2013-12-05 10:18:38 +01:00
|
|
|
thr->shadow_stack_pos = thr->shadow_stack;
|
|
|
|
thr->shadow_stack_end = thr->shadow_stack + kInitStackSize;
|
2013-11-04 22:33:31 +01:00
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
if (common_flags()->detect_deadlocks)
|
2014-05-22 09:09:21 +02:00
|
|
|
thr->dd_lt = ctx->dd->CreateLogicalThread(unique_id);
|
2015-01-13 18:01:30 +01:00
|
|
|
thr->fast_state.SetHistorySize(flags()->history_size);
|
|
|
|
// Commit switch to the new part of the trace.
|
|
|
|
// TraceAddEvent will reset stack0/mset0 in the new part for us.
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
thr->fast_synch_epoch = epoch0;
|
2013-12-05 10:18:38 +01:00
|
|
|
AcquireImpl(thr, 0, &sync);
|
2013-11-04 22:33:31 +01:00
|
|
|
StatInc(thr, StatSyncAcquire);
|
2016-11-08 23:04:09 +01:00
|
|
|
sync.Reset(&thr->proc()->clock_cache);
|
2015-10-21 09:32:45 +02:00
|
|
|
thr->is_inited = true;
|
2013-11-04 22:33:31 +01:00
|
|
|
DPrintf("#%d: ThreadStart epoch=%zu stk_addr=%zx stk_size=%zx "
|
|
|
|
"tls_addr=%zx tls_size=%zx\n",
|
|
|
|
tid, (uptr)epoch0, args->stk_addr, args->stk_size,
|
|
|
|
args->tls_addr, args->tls_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadContext::OnFinished() {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if SANITIZER_GO
|
|
|
|
internal_free(thr->shadow_stack);
|
|
|
|
thr->shadow_stack = nullptr;
|
|
|
|
thr->shadow_stack_pos = nullptr;
|
|
|
|
thr->shadow_stack_end = nullptr;
|
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
if (!detached) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
// Can't increment epoch w/o writing to the trace as well.
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
|
2013-12-05 10:18:38 +01:00
|
|
|
ReleaseImpl(thr, 0, &sync);
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
epoch1 = thr->fast_state.epoch();
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
if (common_flags()->detect_deadlocks)
|
2014-05-22 09:09:21 +02:00
|
|
|
ctx->dd->DestroyLogicalThread(thr->dd_lt);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
thr->clock.ResetCached(&thr->proc()->clock_cache);
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
thr->last_sleep_clock.ResetCached(&thr->proc()->clock_cache);
|
2020-06-01 21:15:18 +02:00
|
|
|
#endif
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
PlatformCleanUpThreadState(thr);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
thr->~ThreadState();
|
2015-10-21 09:32:45 +02:00
|
|
|
#if TSAN_COLLECT_STATS
|
2014-05-22 09:09:21 +02:00
|
|
|
StatAggregate(ctx->stat, thr->stat);
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
thr = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-11-04 22:33:31 +01:00
|
|
|
struct ThreadLeak {
|
|
|
|
ThreadContext *tctx;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void MaybeReportThreadLeak(ThreadContextBase *tctx_base, void *arg) {
|
|
|
|
Vector<ThreadLeak> &leaks = *(Vector<ThreadLeak>*)arg;
|
|
|
|
ThreadContext *tctx = static_cast<ThreadContext*>(tctx_base);
|
|
|
|
if (tctx->detached || tctx->status != ThreadStatusFinished)
|
2012-11-22 23:03:11 +01:00
|
|
|
return;
|
2013-11-04 22:33:31 +01:00
|
|
|
for (uptr i = 0; i < leaks.Size(); i++) {
|
|
|
|
if (leaks[i].tctx->creation_stack_id == tctx->creation_stack_id) {
|
|
|
|
leaks[i].count++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ThreadLeak leak = {tctx, 1};
|
|
|
|
leaks.PushBack(leak);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-12-05 10:18:38 +01:00
|
|
|
static void ReportIgnoresEnabled(ThreadContext *tctx, IgnoreSet *set) {
|
|
|
|
if (tctx->tid == 0) {
|
|
|
|
Printf("ThreadSanitizer: main thread finished with ignores enabled\n");
|
|
|
|
} else {
|
|
|
|
Printf("ThreadSanitizer: thread T%d %s finished with ignores enabled,"
|
|
|
|
" created at:\n", tctx->tid, tctx->name);
|
|
|
|
PrintStack(SymbolizeStackId(tctx->creation_stack_id));
|
|
|
|
}
|
|
|
|
Printf(" One of the following ignores was not ended"
|
|
|
|
" (in order of probability)\n");
|
|
|
|
for (uptr i = 0; i < set->Size(); i++) {
|
|
|
|
Printf(" Ignore was enabled at:\n");
|
|
|
|
PrintStack(SymbolizeStackId(set->At(i)));
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
2013-12-05 10:18:38 +01:00
|
|
|
Die();
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
static void ThreadCheckIgnore(ThreadState *thr) {
|
2014-05-22 09:09:21 +02:00
|
|
|
if (ctx->after_multithreaded_fork)
|
|
|
|
return;
|
2013-12-05 10:18:38 +01:00
|
|
|
if (thr->ignore_reads_and_writes)
|
|
|
|
ReportIgnoresEnabled(thr->tctx, &thr->mop_ignore_set);
|
|
|
|
if (thr->ignore_sync)
|
|
|
|
ReportIgnoresEnabled(thr->tctx, &thr->sync_ignore_set);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void ThreadCheckIgnore(ThreadState *thr) {}
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
void ThreadFinalize(ThreadState *thr) {
|
2013-11-04 22:33:31 +01:00
|
|
|
ThreadCheckIgnore(thr);
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2012-11-22 23:03:11 +01:00
|
|
|
if (!flags()->report_thread_leaks)
|
|
|
|
return;
|
2014-05-22 09:09:21 +02:00
|
|
|
ThreadRegistryLock l(ctx->thread_registry);
|
2018-10-31 12:14:23 +01:00
|
|
|
Vector<ThreadLeak> leaks;
|
2014-05-22 09:09:21 +02:00
|
|
|
ctx->thread_registry->RunCallbackForEachThreadLocked(
|
2013-11-04 22:33:31 +01:00
|
|
|
MaybeReportThreadLeak, &leaks);
|
|
|
|
for (uptr i = 0; i < leaks.Size(); i++) {
|
|
|
|
ScopedReport rep(ReportTypeThreadLeak);
|
2014-09-23 19:59:53 +02:00
|
|
|
rep.AddThread(leaks[i].tctx, true);
|
2013-11-04 22:33:31 +01:00
|
|
|
rep.SetCount(leaks[i].count);
|
2014-09-23 19:59:53 +02:00
|
|
|
OutputReport(thr, rep);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2012-11-23 15:46:25 +01:00
|
|
|
int ThreadCount(ThreadState *thr) {
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr result;
|
|
|
|
ctx->thread_registry->GetNumberOfThreads(0, 0, &result);
|
|
|
|
return (int)result;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) {
|
|
|
|
StatInc(thr, StatThreadCreate);
|
2013-11-04 22:33:31 +01:00
|
|
|
OnCreatedArgs args = { thr, pc };
|
2015-11-23 10:07:18 +01:00
|
|
|
u32 parent_tid = thr ? thr->tid : kInvalidTid; // No parent for GCD workers.
|
|
|
|
int tid =
|
|
|
|
ctx->thread_registry->CreateThread(uid, detached, parent_tid, &args);
|
|
|
|
DPrintf("#%d: ThreadCreate tid=%d uid=%zu\n", parent_tid, tid, uid);
|
2013-11-04 22:33:31 +01:00
|
|
|
StatSet(thr, StatThreadMaxAlive, ctx->thread_registry->GetMaxAliveThreads());
|
2012-11-22 23:03:11 +01:00
|
|
|
return tid;
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
void ThreadStart(ThreadState *thr, int tid, tid_t os_id,
|
|
|
|
ThreadType thread_type) {
|
2012-11-22 23:03:11 +01:00
|
|
|
uptr stk_addr = 0;
|
|
|
|
uptr stk_size = 0;
|
|
|
|
uptr tls_addr = 0;
|
|
|
|
uptr tls_size = 0;
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2019-08-14 10:47:11 +02:00
|
|
|
if (thread_type != ThreadType::Fiber)
|
|
|
|
GetThreadStackAndTls(tid == 0, &stk_addr, &stk_size, &tls_addr, &tls_size);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
if (tid) {
|
2013-11-04 22:33:31 +01:00
|
|
|
if (stk_addr && stk_size)
|
|
|
|
MemoryRangeImitateWrite(thr, /*pc=*/ 1, stk_addr, stk_size);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (tls_addr && tls_size) ImitateTlsWrite(thr, tls_addr, tls_size);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
ThreadRegistry *tr = ctx->thread_registry;
|
2013-11-04 22:33:31 +01:00
|
|
|
OnStartedArgs args = { thr, stk_addr, stk_size, tls_addr, tls_size };
|
2019-08-14 10:47:11 +02:00
|
|
|
tr->StartThread(tid, os_id, thread_type, &args);
|
2013-12-05 10:18:38 +01:00
|
|
|
|
|
|
|
tr->Lock();
|
|
|
|
thr->tctx = (ThreadContext*)tr->GetThreadLocked(tid);
|
|
|
|
tr->Unlock();
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2014-05-22 09:09:21 +02:00
|
|
|
if (ctx->after_multithreaded_fork) {
|
|
|
|
thr->ignore_interceptors++;
|
|
|
|
ThreadIgnoreBegin(thr, 0);
|
|
|
|
ThreadIgnoreSyncBegin(thr, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadFinish(ThreadState *thr) {
|
2013-11-04 22:33:31 +01:00
|
|
|
ThreadCheckIgnore(thr);
|
2012-11-22 23:03:11 +01:00
|
|
|
StatInc(thr, StatThreadFinish);
|
|
|
|
if (thr->stk_addr && thr->stk_size)
|
2013-11-04 22:33:31 +01:00
|
|
|
DontNeedShadowFor(thr->stk_addr, thr->stk_size);
|
|
|
|
if (thr->tls_addr && thr->tls_size)
|
|
|
|
DontNeedShadowFor(thr->tls_addr, thr->tls_size);
|
2014-09-23 19:59:53 +02:00
|
|
|
thr->is_dead = true;
|
2013-11-04 22:33:31 +01:00
|
|
|
ctx->thread_registry->FinishThread(thr->tid);
|
|
|
|
}
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2020-06-01 21:15:18 +02:00
|
|
|
struct ConsumeThreadContext {
|
|
|
|
uptr uid;
|
|
|
|
ThreadContextBase *tctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool ConsumeThreadByUid(ThreadContextBase *tctx, void *arg) {
|
|
|
|
ConsumeThreadContext *findCtx = (ConsumeThreadContext *)arg;
|
|
|
|
if (tctx->user_id == findCtx->uid && tctx->status != ThreadStatusInvalid) {
|
|
|
|
if (findCtx->tctx) {
|
|
|
|
// Ensure that user_id is unique. If it's not the case we are screwed.
|
|
|
|
// Something went wrong before, but now there is no way to recover.
|
|
|
|
// Returning a wrong thread is not an option, it may lead to very hard
|
|
|
|
// to debug false positives (e.g. if we join a wrong thread).
|
|
|
|
Report("ThreadSanitizer: dup thread with used id 0x%zx\n", findCtx->uid);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
findCtx->tctx = tctx;
|
2013-11-04 22:33:31 +01:00
|
|
|
tctx->user_id = 0;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
return false;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 21:15:18 +02:00
|
|
|
int ThreadConsumeTid(ThreadState *thr, uptr pc, uptr uid) {
|
|
|
|
ConsumeThreadContext findCtx = {uid, nullptr};
|
|
|
|
ctx->thread_registry->FindThread(ConsumeThreadByUid, &findCtx);
|
|
|
|
int tid = findCtx.tctx ? findCtx.tctx->tid : ThreadRegistry::kUnknownTid;
|
|
|
|
DPrintf("#%d: ThreadTid uid=%zu tid=%d\n", thr->tid, uid, tid);
|
|
|
|
return tid;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadJoin(ThreadState *thr, uptr pc, int tid) {
|
|
|
|
CHECK_GT(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
|
|
|
DPrintf("#%d: ThreadJoin tid=%d\n", thr->tid, tid);
|
2013-11-04 22:33:31 +01:00
|
|
|
ctx->thread_registry->JoinThread(tid, thr);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadDetach(ThreadState *thr, uptr pc, int tid) {
|
|
|
|
CHECK_GT(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
2014-09-23 19:59:53 +02:00
|
|
|
ctx->thread_registry->DetachThread(tid, thr);
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
void ThreadNotJoined(ThreadState *thr, uptr pc, int tid, uptr uid) {
|
|
|
|
CHECK_GT(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
|
|
|
ctx->thread_registry->SetThreadUserId(tid, uid);
|
|
|
|
}
|
|
|
|
|
2012-12-05 14:19:55 +01:00
|
|
|
void ThreadSetName(ThreadState *thr, const char *name) {
|
2014-05-22 09:09:21 +02:00
|
|
|
ctx->thread_registry->SetThreadName(thr->tid, name);
|
2012-12-05 14:19:55 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
uptr size, bool is_write) {
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u64 *shadow_mem = (u64*)MemToShadow(addr);
|
|
|
|
DPrintf2("#%d: MemoryAccessRange: @%p %p size=%d is_write=%d\n",
|
|
|
|
thr->tid, (void*)pc, (void*)addr,
|
|
|
|
(int)size, is_write);
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#if SANITIZER_DEBUG
|
2012-11-22 23:03:11 +01:00
|
|
|
if (!IsAppMem(addr)) {
|
2012-11-23 15:46:25 +01:00
|
|
|
Printf("Access to non app mem %zx\n", addr);
|
2012-11-22 23:03:11 +01:00
|
|
|
DCHECK(IsAppMem(addr));
|
|
|
|
}
|
|
|
|
if (!IsAppMem(addr + size - 1)) {
|
2012-11-23 15:46:25 +01:00
|
|
|
Printf("Access to non app mem %zx\n", addr + size - 1);
|
2012-11-22 23:03:11 +01:00
|
|
|
DCHECK(IsAppMem(addr + size - 1));
|
|
|
|
}
|
|
|
|
if (!IsShadowMem((uptr)shadow_mem)) {
|
2012-11-23 15:46:25 +01:00
|
|
|
Printf("Bad shadow addr %p (%zx)\n", shadow_mem, addr);
|
2012-11-22 23:03:11 +01:00
|
|
|
DCHECK(IsShadowMem((uptr)shadow_mem));
|
|
|
|
}
|
|
|
|
if (!IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1))) {
|
2012-11-23 15:46:25 +01:00
|
|
|
Printf("Bad shadow addr %p (%zx)\n",
|
2012-11-22 23:03:11 +01:00
|
|
|
shadow_mem + size * kShadowCnt / 8 - 1, addr + size - 1);
|
|
|
|
DCHECK(IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
StatInc(thr, StatMopRange);
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
if (*shadow_mem == kShadowRodata) {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
DCHECK(!is_write);
|
2013-11-04 22:33:31 +01:00
|
|
|
// Access to .rodata section, no races here.
|
|
|
|
// Measurements show that it can be 10-20% of all memory accesses.
|
|
|
|
StatInc(thr, StatMopRangeRodata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
FastState fast_state = thr->fast_state;
|
|
|
|
if (fast_state.GetIgnoreBit())
|
|
|
|
return;
|
|
|
|
|
|
|
|
fast_state.IncrementEpoch();
|
|
|
|
thr->fast_state = fast_state;
|
2012-12-05 14:19:55 +01:00
|
|
|
TraceAddEvent(thr, fast_state, EventTypeMop, pc);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
bool unaligned = (addr % kShadowCell) != 0;
|
|
|
|
|
|
|
|
// Handle unaligned beginning, if any.
|
|
|
|
for (; addr % kShadowCell && size; addr++, size--) {
|
|
|
|
int const kAccessSizeLog = 0;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
|
2013-02-13 11:46:01 +01:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write, false,
|
2012-11-22 23:03:11 +01:00
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
if (unaligned)
|
|
|
|
shadow_mem += kShadowCnt;
|
|
|
|
// Handle middle part, if any.
|
|
|
|
for (; size >= kShadowCell; addr += kShadowCell, size -= kShadowCell) {
|
|
|
|
int const kAccessSizeLog = 3;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(0, kAccessSizeLog);
|
2013-02-13 11:46:01 +01:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write, false,
|
2012-11-22 23:03:11 +01:00
|
|
|
shadow_mem, cur);
|
|
|
|
shadow_mem += kShadowCnt;
|
|
|
|
}
|
|
|
|
// Handle ending, if any.
|
|
|
|
for (; size; addr++, size--) {
|
|
|
|
int const kAccessSizeLog = 0;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
|
2013-02-13 11:46:01 +01:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write, false,
|
2012-11-22 23:03:11 +01:00
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 11:57:10 +01:00
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
#if !SANITIZER_GO
|
|
|
|
void FiberSwitchImpl(ThreadState *from, ThreadState *to) {
|
|
|
|
Processor *proc = from->proc();
|
|
|
|
ProcUnwire(proc, from);
|
|
|
|
ProcWire(proc, to);
|
|
|
|
set_cur_thread(to);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadState *FiberCreate(ThreadState *thr, uptr pc, unsigned flags) {
|
|
|
|
void *mem = internal_alloc(MBlockThreadContex, sizeof(ThreadState));
|
|
|
|
ThreadState *fiber = static_cast<ThreadState *>(mem);
|
|
|
|
internal_memset(fiber, 0, sizeof(*fiber));
|
|
|
|
int tid = ThreadCreate(thr, pc, 0, true);
|
|
|
|
FiberSwitchImpl(thr, fiber);
|
|
|
|
ThreadStart(fiber, tid, 0, ThreadType::Fiber);
|
|
|
|
FiberSwitchImpl(fiber, thr);
|
|
|
|
return fiber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FiberDestroy(ThreadState *thr, uptr pc, ThreadState *fiber) {
|
|
|
|
FiberSwitchImpl(thr, fiber);
|
|
|
|
ThreadFinish(fiber);
|
|
|
|
FiberSwitchImpl(fiber, thr);
|
|
|
|
internal_free(fiber);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FiberSwitch(ThreadState *thr, uptr pc,
|
|
|
|
ThreadState *fiber, unsigned flags) {
|
|
|
|
if (!(flags & FiberSwitchFlagNoSync))
|
|
|
|
Release(thr, pc, (uptr)fiber);
|
|
|
|
FiberSwitchImpl(thr, fiber);
|
|
|
|
if (!(flags & FiberSwitchFlagNoSync))
|
|
|
|
Acquire(fiber, pc, (uptr)fiber);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
} // namespace __tsan
|