2012-11-22 23:03:11 +01:00
|
|
|
//===-- tsan_rtl.h ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
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.
|
|
|
|
//
|
|
|
|
// Main internal TSan header file.
|
|
|
|
//
|
|
|
|
// Ground rules:
|
|
|
|
// - C++ run-time should not be used (static CTORs, RTTI, exceptions, static
|
|
|
|
// function-scope locals)
|
|
|
|
// - All functions/classes/etc reside in namespace __tsan, except for those
|
|
|
|
// declared in tsan_interface.h.
|
|
|
|
// - Platform-specific files should be used instead of ifdefs (*).
|
|
|
|
// - No system headers included in header files (*).
|
|
|
|
// - Platform specific headres included only into platform-specific files (*).
|
|
|
|
//
|
|
|
|
// (*) Except when inlining is critical for performance.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef TSAN_RTL_H
|
|
|
|
#define TSAN_RTL_H
|
|
|
|
|
2012-12-05 14:19:55 +01:00
|
|
|
#include "sanitizer_common/sanitizer_allocator.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_allocator_internal.h"
|
2013-12-05 11:28:59 +01:00
|
|
|
#include "sanitizer_common/sanitizer_asm.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2014-05-22 09:09:21 +02:00
|
|
|
#include "sanitizer_common/sanitizer_deadlock_detector_interface.h"
|
2013-12-05 10:18:38 +01:00
|
|
|
#include "sanitizer_common/sanitizer_libignore.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_suppressions.h"
|
|
|
|
#include "sanitizer_common/sanitizer_thread_registry.h"
|
2018-10-31 12:14:23 +01:00
|
|
|
#include "sanitizer_common/sanitizer_vector.h"
|
2012-11-22 23:03:11 +01:00
|
|
|
#include "tsan_clock.h"
|
|
|
|
#include "tsan_defs.h"
|
|
|
|
#include "tsan_flags.h"
|
2021-09-27 19:43:33 +02:00
|
|
|
#include "tsan_ignoreset.h"
|
2018-10-31 12:14:23 +01:00
|
|
|
#include "tsan_mman.h"
|
2013-01-10 13:44:08 +01:00
|
|
|
#include "tsan_mutexset.h"
|
2021-09-27 19:43:33 +02:00
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_report.h"
|
|
|
|
#include "tsan_shadow.h"
|
2014-09-23 19:59:53 +02:00
|
|
|
#include "tsan_stack_trace.h"
|
2021-09-27 19:43:33 +02:00
|
|
|
#include "tsan_sync.h"
|
|
|
|
#include "tsan_trace.h"
|
2012-12-05 14:19:55 +01:00
|
|
|
|
|
|
|
#if SANITIZER_WORDSIZE != 64
|
|
|
|
# error "ThreadSanitizer is supported only on 64-bit platforms"
|
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-11-04 22:33:31 +01:00
|
|
|
struct MapUnmapCallback;
|
2016-11-08 23:04:09 +01:00
|
|
|
#if defined(__mips64) || defined(__aarch64__) || defined(__powerpc__)
|
2019-08-14 10:47:11 +02: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
|
|
|
struct AP32 {
|
|
|
|
static const uptr kSpaceBeg = 0;
|
|
|
|
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
|
|
|
|
static const uptr kMetadataSize = 0;
|
|
|
|
typedef __sanitizer::CompactSizeClassMap SizeClassMap;
|
2019-08-14 10:47:11 +02:00
|
|
|
static const uptr kRegionSizeLog = 20;
|
|
|
|
using AddressSpaceView = LocalAddressSpaceView;
|
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
|
|
|
typedef __tsan::MapUnmapCallback MapUnmapCallback;
|
|
|
|
static const uptr kFlags = 0;
|
|
|
|
};
|
|
|
|
typedef SizeClassAllocator32<AP32> PrimaryAllocator;
|
2015-10-21 09:32:45 +02:00
|
|
|
#else
|
2016-11-08 23:04:09 +01:00
|
|
|
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
2021-09-27 19:43:33 +02:00
|
|
|
# if defined(__s390x__)
|
|
|
|
typedef MappingS390x Mapping;
|
|
|
|
# else
|
|
|
|
typedef Mapping48AddressSpace Mapping;
|
|
|
|
# endif
|
2016-11-08 23:04:09 +01:00
|
|
|
static const uptr kSpaceBeg = Mapping::kHeapMemBeg;
|
|
|
|
static const uptr kSpaceSize = Mapping::kHeapMemEnd - Mapping::kHeapMemBeg;
|
|
|
|
static const uptr kMetadataSize = 0;
|
|
|
|
typedef DefaultSizeClassMap SizeClassMap;
|
|
|
|
typedef __tsan::MapUnmapCallback MapUnmapCallback;
|
|
|
|
static const uptr kFlags = 0;
|
2019-08-14 10:47:11 +02:00
|
|
|
using AddressSpaceView = LocalAddressSpaceView;
|
2016-11-08 23:04:09 +01:00
|
|
|
};
|
|
|
|
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2019-08-14 10:47:11 +02:00
|
|
|
typedef CombinedAllocator<PrimaryAllocator> Allocator;
|
|
|
|
typedef Allocator::AllocatorCache AllocatorCache;
|
2012-11-22 23:03:11 +01:00
|
|
|
Allocator *allocator();
|
|
|
|
#endif
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
struct ThreadSignalContext;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
struct JmpBuf {
|
|
|
|
uptr sp;
|
2014-09-23 19:59:53 +02:00
|
|
|
int int_signal_send;
|
|
|
|
bool in_blocking_func;
|
|
|
|
uptr in_signal_handler;
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr *shadow_stack_pos;
|
|
|
|
};
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
// A Processor represents a physical thread, or a P for Go.
|
|
|
|
// It is used to store internal resources like allocate cache, and does not
|
|
|
|
// participate in race-detection logic (invisible to end user).
|
|
|
|
// In C++ it is tied to an OS thread just like ThreadState, however ideally
|
|
|
|
// it should be tied to a CPU (this way we will have fewer allocator caches).
|
|
|
|
// In Go it is tied to a P, so there are significantly fewer Processor's than
|
|
|
|
// ThreadState's (which are tied to Gs).
|
|
|
|
// A ThreadState must be wired with a Processor to handle events.
|
|
|
|
struct Processor {
|
|
|
|
ThreadState *thr; // currently wired thread, or nullptr
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
AllocatorCache alloc_cache;
|
|
|
|
InternalAllocatorCache internal_alloc_cache;
|
|
|
|
#endif
|
|
|
|
DenseSlabAllocCache block_cache;
|
|
|
|
DenseSlabAllocCache sync_cache;
|
|
|
|
DenseSlabAllocCache clock_cache;
|
|
|
|
DDPhysicalThread *dd_pt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
// ScopedGlobalProcessor temporary setups a global processor for the current
|
|
|
|
// thread, if it does not have one. Intended for interceptors that can run
|
|
|
|
// at the very thread end, when we already destroyed the thread processor.
|
|
|
|
struct ScopedGlobalProcessor {
|
|
|
|
ScopedGlobalProcessor();
|
|
|
|
~ScopedGlobalProcessor();
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
// This struct is stored in TLS.
|
|
|
|
struct ThreadState {
|
|
|
|
FastState fast_state;
|
|
|
|
// Synch epoch represents the threads's epoch before the last synchronization
|
|
|
|
// action. It allows to reduce number of shadow state updates.
|
|
|
|
// For example, fast_synch_epoch=100, last write to addr X was at epoch=150,
|
|
|
|
// if we are processing write to X from the same thread at epoch=200,
|
|
|
|
// we do nothing, because both writes happen in the same 'synch epoch'.
|
|
|
|
// That is, if another memory access does not race with the former write,
|
|
|
|
// it does not race with the latter as well.
|
|
|
|
// QUESTION: can we can squeeze this into ThreadState::Fast?
|
|
|
|
// E.g. ThreadState::Fast is a 44-bit, 32 are taken by synch_epoch and 12 are
|
|
|
|
// taken by epoch between synchs.
|
|
|
|
// This way we can save one load from tls.
|
|
|
|
u64 fast_synch_epoch;
|
2019-08-14 10:47:11 +02:00
|
|
|
// Technically `current` should be a separate THREADLOCAL variable;
|
|
|
|
// but it is placed here in order to share cache line with previous fields.
|
|
|
|
ThreadState* current;
|
2012-11-22 23:03:11 +01:00
|
|
|
// This is a slow path flag. On fast path, fast_state.GetIgnoreBit() is read.
|
|
|
|
// We do not distinguish beteween ignoring reads and writes
|
|
|
|
// for better performance.
|
|
|
|
int ignore_reads_and_writes;
|
2021-09-27 19:43:33 +02:00
|
|
|
atomic_sint32_t pending_signals;
|
2013-12-05 10:18:38 +01:00
|
|
|
int ignore_sync;
|
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
|
|
|
int suppress_reports;
|
2013-12-05 10:18:38 +01:00
|
|
|
// Go does not support ignores.
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-12-05 10:18:38 +01:00
|
|
|
IgnoreSet mop_ignore_set;
|
|
|
|
IgnoreSet sync_ignore_set;
|
2021-09-27 19:43:33 +02:00
|
|
|
// C/C++ uses fixed size shadow stack.
|
|
|
|
uptr shadow_stack[kShadowStackSize];
|
|
|
|
#else
|
2013-12-05 10:18:38 +01:00
|
|
|
// Go uses malloc-allocated shadow stack with dynamic size.
|
2012-11-22 23:03:11 +01:00
|
|
|
uptr *shadow_stack;
|
2021-09-27 19:43:33 +02:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
uptr *shadow_stack_end;
|
2013-12-05 10:18:38 +01:00
|
|
|
uptr *shadow_stack_pos;
|
2021-09-27 19:43:33 +02:00
|
|
|
RawShadow *racy_shadow_addr;
|
|
|
|
RawShadow racy_state[2];
|
2013-01-10 13:44:08 +01:00
|
|
|
MutexSet mset;
|
2012-11-22 23:03:11 +01:00
|
|
|
ThreadClock clock;
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2013-11-04 22:33:31 +01:00
|
|
|
Vector<JmpBuf> jmp_bufs;
|
2014-05-22 09:09:21 +02:00
|
|
|
int ignore_interceptors;
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2021-09-27 19:43:33 +02:00
|
|
|
const Tid tid;
|
2012-11-22 23:03:11 +01:00
|
|
|
const int unique_id;
|
2013-02-13 11:46:01 +01:00
|
|
|
bool in_symbolizer;
|
2013-12-05 10:18:38 +01:00
|
|
|
bool in_ignored_lib;
|
2015-10-21 09:32:45 +02:00
|
|
|
bool is_inited;
|
2014-09-23 19:59:53 +02:00
|
|
|
bool is_dead;
|
2013-02-13 11:46:01 +01:00
|
|
|
bool is_freeing;
|
2013-11-04 22:33:31 +01:00
|
|
|
bool is_vptr_access;
|
2012-11-22 23:03:11 +01:00
|
|
|
const uptr stk_addr;
|
|
|
|
const uptr stk_size;
|
|
|
|
const uptr tls_addr;
|
|
|
|
const uptr tls_size;
|
2013-12-05 10:18:38 +01:00
|
|
|
ThreadContext *tctx;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
DDLogicalThread *dd_lt;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
// Current wired Processor, or nullptr. Required to handle any events.
|
|
|
|
Processor *proc1;
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
Processor *proc() { return proc1; }
|
|
|
|
#else
|
|
|
|
Processor *proc();
|
|
|
|
#endif
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
atomic_uintptr_t in_signal_handler;
|
2015-10-21 09:32:45 +02:00
|
|
|
ThreadSignalContext *signal_ctx;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2021-09-27 19:43:33 +02:00
|
|
|
StackID last_sleep_stack_id;
|
2012-11-22 23:03:11 +01:00
|
|
|
ThreadClock last_sleep_clock;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set in regions of runtime that must be signal-safe and fork-safe.
|
|
|
|
// If set, malloc must not be called.
|
|
|
|
int nomalloc;
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
const ReportDesc *current_report;
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
// Current position in tctx->trace.Back()->events (Event*).
|
|
|
|
atomic_uintptr_t trace_pos;
|
|
|
|
// PC of the last memory access, used to compute PC deltas in the trace.
|
|
|
|
uptr trace_prev_pc;
|
|
|
|
Sid sid;
|
|
|
|
Epoch epoch;
|
|
|
|
|
|
|
|
explicit ThreadState(Context *ctx, Tid tid, int unique_id, u64 epoch,
|
2021-05-12 14:37:22 +02:00
|
|
|
unsigned reuse_count, uptr stk_addr, uptr stk_size,
|
2012-11-22 23:03:11 +01:00
|
|
|
uptr tls_addr, uptr tls_size);
|
2021-09-27 19:43:33 +02:00
|
|
|
} ALIGNED(SANITIZER_CACHE_LINE_SIZE);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
|
|
|
#if SANITIZER_MAC || SANITIZER_ANDROID
|
2015-11-23 10:07:18 +01:00
|
|
|
ThreadState *cur_thread();
|
2019-08-14 10:47:11 +02:00
|
|
|
void set_cur_thread(ThreadState *thr);
|
2015-11-23 10:07:18 +01:00
|
|
|
void cur_thread_finalize();
|
2021-10-06 19:24:24 +02:00
|
|
|
inline ThreadState *cur_thread_init() { return cur_thread(); }
|
|
|
|
# else
|
2014-05-22 09:09:21 +02:00
|
|
|
__attribute__((tls_model("initial-exec")))
|
2012-11-22 23:03:11 +01:00
|
|
|
extern THREADLOCAL char cur_thread_placeholder[];
|
2020-10-16 10:03:04 +02:00
|
|
|
inline ThreadState *cur_thread() {
|
2019-08-14 10:47:11 +02:00
|
|
|
return reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current;
|
|
|
|
}
|
2021-10-06 19:24:24 +02:00
|
|
|
inline ThreadState *cur_thread_init() {
|
2019-08-14 10:47:11 +02:00
|
|
|
ThreadState *thr = reinterpret_cast<ThreadState *>(cur_thread_placeholder);
|
|
|
|
if (UNLIKELY(!thr->current))
|
|
|
|
thr->current = thr;
|
2021-10-06 19:24:24 +02:00
|
|
|
return thr->current;
|
2019-08-14 10:47:11 +02:00
|
|
|
}
|
2020-10-16 10:03:04 +02:00
|
|
|
inline void set_cur_thread(ThreadState *thr) {
|
2019-08-14 10:47:11 +02:00
|
|
|
reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current = thr;
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2020-10-16 10:03:04 +02:00
|
|
|
inline void cur_thread_finalize() { }
|
2021-10-06 19:24:24 +02:00
|
|
|
# endif // SANITIZER_MAC || SANITIZER_ANDROID
|
2015-11-23 10:07:18 +01:00
|
|
|
#endif // SANITIZER_GO
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2020-11-13 17:03:23 +01:00
|
|
|
class ThreadContext final : public ThreadContextBase {
|
2013-11-04 22:33:31 +01:00
|
|
|
public:
|
2021-09-27 19:43:33 +02:00
|
|
|
explicit ThreadContext(Tid tid);
|
2013-11-04 22:33:31 +01:00
|
|
|
~ThreadContext();
|
2012-11-22 23:03:11 +01:00
|
|
|
ThreadState *thr;
|
2021-09-27 19:43:33 +02:00
|
|
|
StackID creation_stack_id;
|
2012-11-22 23:03:11 +01:00
|
|
|
SyncClock sync;
|
|
|
|
// Epoch at which the thread had started.
|
|
|
|
// If we see an event from the thread stamped by an older epoch,
|
|
|
|
// the event is from a dead thread that shared tid with this thread.
|
|
|
|
u64 epoch0;
|
|
|
|
u64 epoch1;
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
v3::Trace trace;
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// Override superclass callbacks.
|
2015-10-21 09:32:45 +02:00
|
|
|
void OnDead() override;
|
|
|
|
void OnJoined(void *arg) override;
|
|
|
|
void OnFinished() override;
|
|
|
|
void OnStarted(void *arg) override;
|
|
|
|
void OnCreated(void *arg) override;
|
|
|
|
void OnReset() override;
|
|
|
|
void OnDetached(void *arg) override;
|
2012-11-22 23:03:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RacyStacks {
|
|
|
|
MD5Hash hash[2];
|
2021-09-27 19:43:33 +02:00
|
|
|
bool operator==(const RacyStacks &other) const;
|
2012-11-22 23:03:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RacyAddress {
|
|
|
|
uptr addr_min;
|
|
|
|
uptr addr_max;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FiredSuppression {
|
|
|
|
ReportType type;
|
2015-10-21 09:32:45 +02:00
|
|
|
uptr pc_or_addr;
|
2013-11-04 22:33:31 +01:00
|
|
|
Suppression *supp;
|
2012-11-22 23:03:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Context {
|
|
|
|
Context();
|
|
|
|
|
|
|
|
bool initialized;
|
2018-10-31 12:14:23 +01:00
|
|
|
#if !SANITIZER_GO
|
2014-05-22 09:09:21 +02:00
|
|
|
bool after_multithreaded_fork;
|
2018-10-31 12:14:23 +01:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
MetaMap metamap;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
Mutex report_mtx;
|
|
|
|
int nreported;
|
2013-11-04 22:33:31 +01:00
|
|
|
atomic_uint64_t last_symbolize_time_ns;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
void *background_thread;
|
|
|
|
atomic_uint32_t stop_background_thread;
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
ThreadRegistry thread_registry;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
Mutex racy_mtx;
|
2012-11-22 23:03:11 +01:00
|
|
|
Vector<RacyStacks> racy_stacks;
|
|
|
|
Vector<RacyAddress> racy_addresses;
|
2013-11-04 22:33:31 +01:00
|
|
|
// Number of fired suppressions may be large enough.
|
2015-10-21 09:32:45 +02:00
|
|
|
Mutex fired_suppressions_mtx;
|
2013-11-04 22:33:31 +01:00
|
|
|
InternalMmapVector<FiredSuppression> fired_suppressions;
|
2014-05-22 09:09:21 +02:00
|
|
|
DDetector *dd;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
ClockAlloc clock_alloc;
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
Flags flags;
|
2021-09-27 19:43:33 +02:00
|
|
|
fd_t memprof_fd;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
Mutex slot_mtx;
|
2012-11-22 23:03:11 +01:00
|
|
|
};
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
extern Context *ctx; // The one and the only global runtime context.
|
|
|
|
|
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
|
|
|
ALWAYS_INLINE Flags *flags() {
|
|
|
|
return &ctx->flags;
|
|
|
|
}
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
struct ScopedIgnoreInterceptors {
|
|
|
|
ScopedIgnoreInterceptors() {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2014-05-22 09:09:21 +02:00
|
|
|
cur_thread()->ignore_interceptors++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedIgnoreInterceptors() {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2014-05-22 09:09:21 +02:00
|
|
|
cur_thread()->ignore_interceptors--;
|
|
|
|
#endif
|
|
|
|
}
|
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
|
|
|
const char *GetObjectTypeFromTag(uptr tag);
|
|
|
|
const char *GetReportHeaderFromTag(uptr tag);
|
|
|
|
uptr TagFromShadowStackFrame(uptr pc);
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
class ScopedReportBase {
|
2012-11-22 23:03:11 +01:00
|
|
|
public:
|
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
|
|
|
void AddMemoryAccess(uptr addr, uptr external_tag, Shadow s, StackTrace stack,
|
2013-01-10 13:44:08 +01:00
|
|
|
const MutexSet *mset);
|
2014-11-13 21:41:38 +01:00
|
|
|
void AddStack(StackTrace stack, bool suppressable = false);
|
2014-09-23 19:59:53 +02:00
|
|
|
void AddThread(const ThreadContext *tctx, bool suppressable = false);
|
2021-09-27 19:43:33 +02:00
|
|
|
void AddThread(Tid unique_tid, bool suppressable = false);
|
|
|
|
void AddUniqueTid(Tid unique_tid);
|
2012-11-22 23:03:11 +01:00
|
|
|
void AddMutex(const SyncVar *s);
|
2014-05-22 09:09:21 +02:00
|
|
|
u64 AddMutex(u64 id);
|
2012-11-22 23:03:11 +01:00
|
|
|
void AddLocation(uptr addr, uptr size);
|
2021-09-27 19:43:33 +02:00
|
|
|
void AddSleep(StackID stack_id);
|
2013-11-04 22:33:31 +01:00
|
|
|
void SetCount(int count);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
const ReportDesc *GetReport() const;
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
protected:
|
|
|
|
ScopedReportBase(ReportType typ, uptr tag);
|
|
|
|
~ScopedReportBase();
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
private:
|
|
|
|
ReportDesc *rep_;
|
2014-05-22 09:09:21 +02:00
|
|
|
// Symbolizer makes lots of intercepted calls. If we try to process them,
|
|
|
|
// at best it will cause deadlocks on internal mutexes.
|
|
|
|
ScopedIgnoreInterceptors ignore_interceptors_;
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
void AddDeadMutex(u64 id);
|
2013-01-10 13:44:08 +01:00
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
ScopedReportBase(const ScopedReportBase &) = delete;
|
|
|
|
void operator=(const ScopedReportBase &) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScopedReport : public ScopedReportBase {
|
|
|
|
public:
|
|
|
|
explicit ScopedReport(ReportType typ, uptr tag = kExternalTagNone);
|
|
|
|
~ScopedReport();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ScopedErrorReportLock lock_;
|
2012-11-22 23:03:11 +01:00
|
|
|
};
|
|
|
|
|
2021-05-12 14:37:22 +02:00
|
|
|
bool ShouldReport(ThreadState *thr, ReportType typ);
|
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
|
|
|
ThreadContext *IsThreadStackOrTls(uptr addr, bool *is_stack);
|
2021-09-27 19:43:33 +02:00
|
|
|
void RestoreStack(Tid tid, const u64 epoch, VarSizeStackTrace *stk,
|
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
|
|
|
MutexSet *mset, uptr *tag = nullptr);
|
|
|
|
|
|
|
|
// The stack could look like:
|
|
|
|
// <start> | <main> | <foo> | tag | <bar>
|
|
|
|
// This will extract the tag and keep:
|
|
|
|
// <start> | <main> | <foo> | <bar>
|
|
|
|
template<typename StackTraceTy>
|
|
|
|
void ExtractTagFromStack(StackTraceTy *stack, uptr *tag = nullptr) {
|
|
|
|
if (stack->size < 2) return;
|
|
|
|
uptr possible_tag_pc = stack->trace[stack->size - 2];
|
|
|
|
uptr possible_tag = TagFromShadowStackFrame(possible_tag_pc);
|
|
|
|
if (possible_tag == kExternalTagNone) return;
|
|
|
|
stack->trace_buffer[stack->size - 2] = stack->trace_buffer[stack->size - 1];
|
|
|
|
stack->size -= 1;
|
|
|
|
if (tag) *tag = possible_tag;
|
|
|
|
}
|
2014-11-13 21:41:38 +01:00
|
|
|
|
|
|
|
template<typename StackTraceTy>
|
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
|
|
|
void ObtainCurrentStack(ThreadState *thr, uptr toppc, StackTraceTy *stack,
|
|
|
|
uptr *tag = nullptr) {
|
2014-11-13 21:41:38 +01:00
|
|
|
uptr size = thr->shadow_stack_pos - thr->shadow_stack;
|
|
|
|
uptr start = 0;
|
|
|
|
if (size + !!toppc > kStackTraceMax) {
|
|
|
|
start = size + !!toppc - kStackTraceMax;
|
|
|
|
size = kStackTraceMax - !!toppc;
|
|
|
|
}
|
|
|
|
stack->Init(&thr->shadow_stack[start], size, toppc);
|
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
|
|
|
ExtractTagFromStack(stack, tag);
|
2014-11-13 21:41:38 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#define GET_STACK_TRACE_FATAL(thr, pc) \
|
|
|
|
VarSizeStackTrace stack; \
|
|
|
|
ObtainCurrentStack(thr, pc, &stack); \
|
|
|
|
stack.ReverseOrder();
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2012-11-23 15:46:25 +01:00
|
|
|
void MapShadow(uptr addr, uptr size);
|
2015-10-21 09:32:45 +02:00
|
|
|
void MapThreadTrace(uptr addr, uptr size, const char *name);
|
2013-11-04 22:33:31 +01:00
|
|
|
void DontNeedShadowFor(uptr addr, uptr size);
|
2019-11-05 14:54:57 +01:00
|
|
|
void UnmapShadow(ThreadState *thr, uptr addr, uptr size);
|
2012-11-22 23:03:11 +01:00
|
|
|
void InitializeShadowMemory();
|
|
|
|
void InitializeInterceptors();
|
2013-12-05 10:18:38 +01:00
|
|
|
void InitializeLibIgnore();
|
2012-11-22 23:03:11 +01:00
|
|
|
void InitializeDynamicAnnotations();
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
void ForkBefore(ThreadState *thr, uptr pc);
|
|
|
|
void ForkParentAfter(ThreadState *thr, uptr pc);
|
2021-11-13 07:23:45 +01:00
|
|
|
void ForkChildAfter(ThreadState *thr, uptr pc, bool start_thread);
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
void ReportRace(ThreadState *thr);
|
2014-09-23 19:59:53 +02:00
|
|
|
bool OutputReport(ThreadState *thr, const ScopedReport &srep);
|
2015-10-21 09:32:45 +02:00
|
|
|
bool IsFiredSuppression(Context *ctx, ReportType type, StackTrace trace);
|
2012-11-22 23:03:11 +01:00
|
|
|
bool IsExpectedReport(uptr addr, uptr size);
|
|
|
|
|
|
|
|
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1
|
2012-11-23 15:46:25 +01:00
|
|
|
# define DPrintf Printf
|
2012-11-22 23:03:11 +01:00
|
|
|
#else
|
|
|
|
# define DPrintf(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 2
|
2012-11-23 15:46:25 +01:00
|
|
|
# define DPrintf2 Printf
|
2012-11-22 23:03:11 +01:00
|
|
|
#else
|
|
|
|
# define DPrintf2(...)
|
|
|
|
#endif
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
StackID CurrentStackId(ThreadState *thr, uptr pc);
|
|
|
|
ReportStack *SymbolizeStackId(StackID stack_id);
|
2012-11-22 23:03:11 +01:00
|
|
|
void PrintCurrentStack(ThreadState *thr, uptr pc);
|
2014-11-13 21:41:38 +01:00
|
|
|
void PrintCurrentStackSlow(uptr pc); // uses libunwind
|
2021-09-27 19:43:33 +02:00
|
|
|
MBlock *JavaHeapBlock(uptr addr, uptr *start);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
void Initialize(ThreadState *thr);
|
2018-10-31 12:14:23 +01:00
|
|
|
void MaybeSpawnBackgroundThread();
|
2012-11-22 23:03:11 +01:00
|
|
|
int Finalize(ThreadState *thr);
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void OnUserAlloc(ThreadState *thr, uptr pc, uptr p, uptr sz, bool write);
|
|
|
|
void OnUserFree(ThreadState *thr, uptr pc, uptr p, bool write);
|
2013-01-10 13:44:08 +01:00
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
|
2013-02-13 11:46:01 +01:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic);
|
2012-11-22 23:03:11 +01:00
|
|
|
void MemoryAccessImpl(ThreadState *thr, uptr addr,
|
2013-02-13 11:46:01 +01:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic,
|
2012-11-22 23:03:11 +01:00
|
|
|
u64 *shadow_mem, Shadow cur);
|
|
|
|
void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr,
|
2013-02-13 11:46:01 +01:00
|
|
|
uptr size, bool is_write);
|
2021-09-27 19:43:33 +02:00
|
|
|
void UnalignedMemoryAccess(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
AccessType typ);
|
2013-02-13 11:46:01 +01:00
|
|
|
|
|
|
|
const int kSizeLog1 = 0;
|
|
|
|
const int kSizeLog2 = 1;
|
|
|
|
const int kSizeLog4 = 2;
|
|
|
|
const int kSizeLog8 = 3;
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
ALWAYS_INLINE
|
|
|
|
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
AccessType typ) {
|
|
|
|
int size_log;
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
size_log = kSizeLog1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
size_log = kSizeLog2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
size_log = kSizeLog4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DCHECK_EQ(size, 8);
|
|
|
|
size_log = kSizeLog8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool is_write = !(typ & kAccessRead);
|
|
|
|
bool is_atomic = typ & kAccessAtomic;
|
|
|
|
if (typ & kAccessVptr)
|
|
|
|
thr->is_vptr_access = true;
|
|
|
|
if (typ & kAccessFree)
|
|
|
|
thr->is_freeing = true;
|
|
|
|
MemoryAccess(thr, pc, addr, size_log, is_write, is_atomic);
|
|
|
|
if (typ & kAccessVptr)
|
|
|
|
thr->is_vptr_access = false;
|
|
|
|
if (typ & kAccessFree)
|
|
|
|
thr->is_freeing = false;
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
|
|
|
void MemoryRangeFreed(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
|
|
|
void MemoryRangeImitateWrite(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
2019-11-05 14:54:57 +01:00
|
|
|
void MemoryRangeImitateWriteOrResetRange(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
uptr size);
|
2013-12-05 10:18:38 +01:00
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
void ThreadIgnoreBegin(ThreadState *thr, uptr pc);
|
|
|
|
void ThreadIgnoreEnd(ThreadState *thr);
|
|
|
|
void ThreadIgnoreSyncBegin(ThreadState *thr, uptr pc);
|
|
|
|
void ThreadIgnoreSyncEnd(ThreadState *thr);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
void FuncEntry(ThreadState *thr, uptr pc);
|
|
|
|
void FuncExit(ThreadState *thr);
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
Tid ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached);
|
|
|
|
void ThreadStart(ThreadState *thr, Tid tid, tid_t os_id,
|
2019-08-14 10:47:11 +02:00
|
|
|
ThreadType thread_type);
|
2012-11-22 23:03:11 +01:00
|
|
|
void ThreadFinish(ThreadState *thr);
|
2021-09-27 19:43:33 +02:00
|
|
|
Tid ThreadConsumeTid(ThreadState *thr, uptr pc, uptr uid);
|
|
|
|
void ThreadJoin(ThreadState *thr, uptr pc, Tid tid);
|
|
|
|
void ThreadDetach(ThreadState *thr, uptr pc, Tid tid);
|
2012-11-22 23:03:11 +01:00
|
|
|
void ThreadFinalize(ThreadState *thr);
|
2012-12-05 14:19:55 +01:00
|
|
|
void ThreadSetName(ThreadState *thr, const char *name);
|
2012-11-23 15:46:25 +01:00
|
|
|
int ThreadCount(ThreadState *thr);
|
2021-09-27 19:43:33 +02:00
|
|
|
void ProcessPendingSignalsImpl(ThreadState *thr);
|
|
|
|
void ThreadNotJoined(ThreadState *thr, uptr pc, Tid tid, uptr uid);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
Processor *ProcCreate();
|
|
|
|
void ProcDestroy(Processor *proc);
|
|
|
|
void ProcWire(Processor *proc, ThreadState *thr);
|
|
|
|
void ProcUnwire(Processor *proc, ThreadState *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
|
|
|
// Note: the parameter is called flagz, because flags is already taken
|
|
|
|
// by the global function that returns flags.
|
|
|
|
void MutexCreate(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
|
|
|
void MutexDestroy(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
|
|
|
void MutexPreLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
|
|
|
void MutexPostLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0,
|
|
|
|
int rec = 1);
|
|
|
|
int MutexUnlock(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
|
|
|
void MutexPreReadLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
|
|
|
void MutexPostReadLock(ThreadState *thr, uptr pc, uptr addr, u32 flagz = 0);
|
2012-11-22 23:03:11 +01:00
|
|
|
void MutexReadUnlock(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
void MutexReadOrWriteUnlock(ThreadState *thr, uptr pc, uptr addr);
|
2013-12-05 10:18:38 +01:00
|
|
|
void MutexRepair(ThreadState *thr, uptr pc, uptr addr); // call on EOWNERDEAD
|
2016-11-08 23:04:09 +01:00
|
|
|
void MutexInvalidAccess(ThreadState *thr, uptr pc, uptr addr);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
void Acquire(ThreadState *thr, uptr pc, uptr addr);
|
2015-10-21 09:32:45 +02:00
|
|
|
// AcquireGlobal synchronizes the current thread with all other threads.
|
|
|
|
// In terms of happens-before relation, it draws a HB edge from all threads
|
|
|
|
// (where they happen to execute right now) to the current thread. We use it to
|
|
|
|
// handle Go finalizers. Namely, finalizer goroutine executes AcquireGlobal
|
|
|
|
// right before executing finalizers. This provides a coarse, but simple
|
|
|
|
// approximation of the actual required synchronization.
|
2021-09-27 19:43:33 +02:00
|
|
|
void AcquireGlobal(ThreadState *thr);
|
2012-11-22 23:03:11 +01:00
|
|
|
void Release(ThreadState *thr, uptr pc, uptr addr);
|
2020-06-01 21:15:18 +02:00
|
|
|
void ReleaseStoreAcquire(ThreadState *thr, uptr pc, uptr addr);
|
2012-11-22 23:03:11 +01:00
|
|
|
void ReleaseStore(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
void AfterSleep(ThreadState *thr, uptr pc);
|
2013-12-05 10:18:38 +01:00
|
|
|
void AcquireImpl(ThreadState *thr, uptr pc, SyncClock *c);
|
|
|
|
void ReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c);
|
2020-06-01 21:15:18 +02:00
|
|
|
void ReleaseStoreAcquireImpl(ThreadState *thr, uptr pc, SyncClock *c);
|
2013-12-05 10:18:38 +01:00
|
|
|
void ReleaseStoreImpl(ThreadState *thr, uptr pc, SyncClock *c);
|
|
|
|
void AcquireReleaseImpl(ThreadState *thr, uptr pc, SyncClock *c);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
// The hacky call uses custom calling convention and an assembly thunk.
|
|
|
|
// It is considerably faster that a normal call for the caller
|
|
|
|
// if it is not executed (it is intended for slow paths from hot functions).
|
|
|
|
// The trick is that the call preserves all registers and the compiler
|
|
|
|
// does not treat it as a call.
|
|
|
|
// If it does not work for you, use normal call.
|
2015-11-23 10:07:18 +01:00
|
|
|
#if !SANITIZER_DEBUG && defined(__x86_64__) && !SANITIZER_MAC
|
2012-11-22 23:03:11 +01:00
|
|
|
// The caller may not create the stack frame for itself at all,
|
|
|
|
// so we create a reserve stack frame for it (1024b must be enough).
|
|
|
|
#define HACKY_CALL(f) \
|
|
|
|
__asm__ __volatile__("sub $1024, %%rsp;" \
|
2013-12-05 11:28:59 +01:00
|
|
|
CFI_INL_ADJUST_CFA_OFFSET(1024) \
|
2012-11-27 15:01:46 +01:00
|
|
|
".hidden " #f "_thunk;" \
|
2012-11-22 23:03:11 +01:00
|
|
|
"call " #f "_thunk;" \
|
|
|
|
"add $1024, %%rsp;" \
|
2013-12-05 11:28:59 +01:00
|
|
|
CFI_INL_ADJUST_CFA_OFFSET(-1024) \
|
2012-11-22 23:03:11 +01:00
|
|
|
::: "memory", "cc");
|
|
|
|
#else
|
|
|
|
#define HACKY_CALL(f) f()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void TraceSwitch(ThreadState *thr);
|
2012-12-05 14:19:55 +01:00
|
|
|
uptr TraceTopPC(ThreadState *thr);
|
|
|
|
uptr TraceSize();
|
|
|
|
uptr TraceParts();
|
2021-09-27 19:43:33 +02:00
|
|
|
Trace *ThreadTrace(Tid tid);
|
2012-11-22 23:03:11 +01:00
|
|
|
|
|
|
|
extern "C" void __tsan_trace_switch();
|
2013-11-04 22:33:31 +01:00
|
|
|
void ALWAYS_INLINE TraceAddEvent(ThreadState *thr, FastState fs,
|
2013-01-10 13:44:08 +01:00
|
|
|
EventType typ, u64 addr) {
|
2014-05-22 09:09:21 +02:00
|
|
|
if (!kCollectHistory)
|
|
|
|
return;
|
2013-01-10 13:44:08 +01:00
|
|
|
DCHECK_GE((int)typ, 0);
|
|
|
|
DCHECK_LE((int)typ, 7);
|
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_EQ(GetLsb(addr, kEventPCBits), addr);
|
2012-12-05 14:19:55 +01:00
|
|
|
u64 pos = fs.GetTracePos();
|
|
|
|
if (UNLIKELY((pos % kTracePartSize) == 0)) {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2012-11-23 15:46:25 +01:00
|
|
|
HACKY_CALL(__tsan_trace_switch);
|
|
|
|
#else
|
2012-11-22 23:03:11 +01:00
|
|
|
TraceSwitch(thr);
|
2012-11-23 15:46:25 +01:00
|
|
|
#endif
|
2012-11-22 23:03:11 +01:00
|
|
|
}
|
2012-12-05 14:19:55 +01:00
|
|
|
Event *trace = (Event*)GetThreadTrace(fs.tid());
|
|
|
|
Event *evp = &trace[pos];
|
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
|
|
|
Event ev = (u64)addr | ((u64)typ << kEventPCBits);
|
2012-11-22 23:03:11 +01:00
|
|
|
*evp = ev;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if !SANITIZER_GO
|
2015-10-21 09:32:45 +02:00
|
|
|
uptr ALWAYS_INLINE HeapEnd() {
|
2016-11-08 23:04:09 +01:00
|
|
|
return HeapMemEnd() + PrimaryAllocator::AdditionalSize();
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
ThreadState *FiberCreate(ThreadState *thr, uptr pc, unsigned flags);
|
|
|
|
void FiberDestroy(ThreadState *thr, uptr pc, ThreadState *fiber);
|
|
|
|
void FiberSwitch(ThreadState *thr, uptr pc, ThreadState *fiber, unsigned flags);
|
|
|
|
|
|
|
|
// These need to match __tsan_switch_to_fiber_* flags defined in
|
|
|
|
// tsan_interface.h. See documentation there as well.
|
|
|
|
enum FiberSwitchFlags {
|
|
|
|
FiberSwitchFlagNoSync = 1 << 0, // __tsan_switch_to_fiber_no_sync
|
|
|
|
};
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
ALWAYS_INLINE void ProcessPendingSignals(ThreadState *thr) {
|
|
|
|
if (UNLIKELY(atomic_load_relaxed(&thr->pending_signals)))
|
|
|
|
ProcessPendingSignalsImpl(thr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool is_initialized;
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
|
|
|
void LazyInitialize(ThreadState *thr) {
|
|
|
|
// If we can use .preinit_array, assume that __tsan_init
|
|
|
|
// called from .preinit_array initializes runtime before
|
|
|
|
// any instrumented code.
|
|
|
|
#if !SANITIZER_CAN_USE_PREINIT_ARRAY
|
|
|
|
if (UNLIKELY(!is_initialized))
|
|
|
|
Initialize(thr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace v3 {
|
|
|
|
|
|
|
|
void TraceSwitchPart(ThreadState *thr);
|
|
|
|
bool RestoreStack(Tid tid, EventType type, Sid sid, Epoch epoch, uptr addr,
|
|
|
|
uptr size, AccessType typ, VarSizeStackTrace *pstk,
|
|
|
|
MutexSet *pmset, uptr *ptag);
|
|
|
|
|
|
|
|
template <typename EventT>
|
|
|
|
ALWAYS_INLINE WARN_UNUSED_RESULT bool TraceAcquire(ThreadState *thr,
|
|
|
|
EventT **ev) {
|
|
|
|
Event *pos = reinterpret_cast<Event *>(atomic_load_relaxed(&thr->trace_pos));
|
|
|
|
#if SANITIZER_DEBUG
|
|
|
|
// TraceSwitch acquires these mutexes,
|
|
|
|
// so we lock them here to detect deadlocks more reliably.
|
|
|
|
{ Lock lock(&ctx->slot_mtx); }
|
|
|
|
{ Lock lock(&thr->tctx->trace.mtx); }
|
|
|
|
TracePart *current = thr->tctx->trace.parts.Back();
|
|
|
|
if (current) {
|
|
|
|
DCHECK_GE(pos, ¤t->events[0]);
|
|
|
|
DCHECK_LE(pos, ¤t->events[TracePart::kSize]);
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(pos, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// TracePart is allocated with mmap and is at least 4K aligned.
|
|
|
|
// So the following check is a faster way to check for part end.
|
|
|
|
// It may have false positives in the middle of the trace,
|
|
|
|
// they are filtered out in TraceSwitch.
|
|
|
|
if (UNLIKELY(((uptr)(pos + 1) & TracePart::kAlignment) == 0))
|
|
|
|
return false;
|
|
|
|
*ev = reinterpret_cast<EventT *>(pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EventT>
|
|
|
|
ALWAYS_INLINE void TraceRelease(ThreadState *thr, EventT *evp) {
|
|
|
|
DCHECK_LE(evp + 1, &thr->tctx->trace.parts.Back()->events[TracePart::kSize]);
|
|
|
|
atomic_store_relaxed(&thr->trace_pos, (uptr)(evp + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EventT>
|
|
|
|
void TraceEvent(ThreadState *thr, EventT ev) {
|
|
|
|
EventT *evp;
|
|
|
|
if (!TraceAcquire(thr, &evp)) {
|
|
|
|
TraceSwitchPart(thr);
|
|
|
|
UNUSED bool res = TraceAcquire(thr, &evp);
|
|
|
|
DCHECK(res);
|
|
|
|
}
|
|
|
|
*evp = ev;
|
|
|
|
TraceRelease(thr, evp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE WARN_UNUSED_RESULT bool TryTraceFunc(ThreadState *thr,
|
|
|
|
uptr pc = 0) {
|
|
|
|
if (!kCollectHistory)
|
|
|
|
return true;
|
|
|
|
EventFunc *ev;
|
|
|
|
if (UNLIKELY(!TraceAcquire(thr, &ev)))
|
|
|
|
return false;
|
|
|
|
ev->is_access = 0;
|
|
|
|
ev->is_func = 1;
|
|
|
|
ev->pc = pc;
|
|
|
|
TraceRelease(thr, ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_UNUSED_RESULT
|
|
|
|
bool TryTraceMemoryAccess(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
AccessType typ);
|
|
|
|
WARN_UNUSED_RESULT
|
|
|
|
bool TryTraceMemoryAccessRange(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
AccessType typ);
|
|
|
|
void TraceMemoryAccessRange(ThreadState *thr, uptr pc, uptr addr, uptr size,
|
|
|
|
AccessType typ);
|
|
|
|
void TraceFunc(ThreadState *thr, uptr pc = 0);
|
|
|
|
void TraceMutexLock(ThreadState *thr, EventType type, uptr pc, uptr addr,
|
|
|
|
StackID stk);
|
|
|
|
void TraceMutexUnlock(ThreadState *thr, uptr addr);
|
|
|
|
void TraceTime(ThreadState *thr);
|
|
|
|
|
|
|
|
} // namespace v3
|
|
|
|
|
2021-11-04 09:20:14 +01:00
|
|
|
void GrowShadowStack(ThreadState *thr);
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
|
|
|
void FuncEntry(ThreadState *thr, uptr pc) {
|
|
|
|
DPrintf2("#%d: FuncEntry %p\n", (int)thr->fast_state.tid(), (void *)pc);
|
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeFuncEnter, pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shadow stack maintenance can be replaced with
|
|
|
|
// stack unwinding during trace switch (which presumably must be faster).
|
|
|
|
DCHECK_GE(thr->shadow_stack_pos, thr->shadow_stack);
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end);
|
|
|
|
#else
|
|
|
|
if (thr->shadow_stack_pos == thr->shadow_stack_end)
|
|
|
|
GrowShadowStack(thr);
|
|
|
|
#endif
|
|
|
|
thr->shadow_stack_pos[0] = pc;
|
|
|
|
thr->shadow_stack_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE
|
|
|
|
void FuncExit(ThreadState *thr) {
|
|
|
|
DPrintf2("#%d: FuncExit\n", (int)thr->fast_state.tid());
|
|
|
|
if (kCollectHistory) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
TraceAddEvent(thr, thr->fast_state, EventTypeFuncExit, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK_GT(thr->shadow_stack_pos, thr->shadow_stack);
|
|
|
|
#if !SANITIZER_GO
|
|
|
|
DCHECK_LT(thr->shadow_stack_pos, thr->shadow_stack_end);
|
|
|
|
#endif
|
|
|
|
thr->shadow_stack_pos--;
|
|
|
|
}
|
|
|
|
|
2021-09-27 19:43:33 +02:00
|
|
|
#if !SANITIZER_GO
|
|
|
|
extern void (*on_initialize)(void);
|
|
|
|
extern int (*on_finalize)(int);
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 23:03:11 +01:00
|
|
|
} // namespace __tsan
|
|
|
|
|
|
|
|
#endif // TSAN_RTL_H
|