2019-08-14 10:47:11 +02:00
|
|
|
//===-- asan_thread.cpp ---------------------------------------------------===//
|
2012-11-12 16:53:47 +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-12 16:53:47 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Thread-related code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "asan_allocator.h"
|
|
|
|
#include "asan_interceptors.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "asan_poisoning.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_stack.h"
|
|
|
|
#include "asan_thread.h"
|
|
|
|
#include "asan_mapping.h"
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
2013-12-05 10:18:38 +01:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2014-05-22 09:09:21 +02:00
|
|
|
#include "sanitizer_common/sanitizer_tls_get_addr.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "lsan/lsan_common.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// AsanThreadContext implementation.
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void AsanThreadContext::OnCreated(void *arg) {
|
|
|
|
CreateThreadContextArgs *args = static_cast<CreateThreadContextArgs*>(arg);
|
2013-12-05 10:18:38 +01:00
|
|
|
if (args->stack)
|
2014-11-13 21:41:38 +01:00
|
|
|
stack_id = StackDepotPut(*args->stack);
|
2013-11-04 22:33:31 +01:00
|
|
|
thread = args->thread;
|
|
|
|
thread->set_context(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsanThreadContext::OnFinished() {
|
|
|
|
// Drop the link to the AsanThread object.
|
2015-10-21 09:32:45 +02:00
|
|
|
thread = nullptr;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// MIPS requires aligned address
|
|
|
|
static ALIGNED(16) char thread_registry_placeholder[sizeof(ThreadRegistry)];
|
|
|
|
static ThreadRegistry *asan_thread_registry;
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
static BlockingMutex mu_for_thread_context(LINKER_INITIALIZED);
|
|
|
|
static LowLevelAllocator allocator_for_thread_context;
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
static ThreadContextBase *GetAsanThreadContext(u32 tid) {
|
2013-12-05 10:18:38 +01:00
|
|
|
BlockingMutexLock lock(&mu_for_thread_context);
|
|
|
|
return new(allocator_for_thread_context) AsanThreadContext(tid);
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadRegistry &asanThreadRegistry() {
|
|
|
|
static bool initialized;
|
|
|
|
// Don't worry about thread_safety - this should be called when there is
|
|
|
|
// a single thread.
|
|
|
|
if (!initialized) {
|
|
|
|
// Never reuse ASan threads: we store pointer to AsanThreadContext
|
|
|
|
// in TSD and can't reliably tell when no more TSD destructors will
|
|
|
|
// be called. It would be wrong to reuse AsanThreadContext for another
|
|
|
|
// thread before all TSD destructors will be called for it.
|
|
|
|
asan_thread_registry = new(thread_registry_placeholder) ThreadRegistry(
|
|
|
|
GetAsanThreadContext, kMaxNumberOfThreads, kMaxNumberOfThreads);
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
return *asan_thread_registry;
|
|
|
|
}
|
|
|
|
|
|
|
|
AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {
|
|
|
|
return static_cast<AsanThreadContext *>(
|
|
|
|
asanThreadRegistry().GetThreadLocked(tid));
|
|
|
|
}
|
|
|
|
|
|
|
|
// AsanThread implementation.
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
AsanThread *AsanThread::Create(thread_callback_t start_routine, void *arg,
|
|
|
|
u32 parent_tid, StackTrace *stack,
|
|
|
|
bool detached) {
|
2012-11-27 15:01:46 +01:00
|
|
|
uptr PageSize = GetPageSizeCached();
|
|
|
|
uptr size = RoundUpTo(sizeof(AsanThread), PageSize);
|
2014-05-22 09:09:21 +02:00
|
|
|
AsanThread *thread = (AsanThread*)MmapOrDie(size, __func__);
|
2012-11-12 16:53:47 +01:00
|
|
|
thread->start_routine_ = start_routine;
|
|
|
|
thread->arg_ = arg;
|
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
|
|
|
AsanThreadContext::CreateThreadContextArgs args = {thread, stack};
|
2015-10-21 09:32:45 +02:00
|
|
|
asanThreadRegistry().CreateThread(*reinterpret_cast<uptr *>(thread), detached,
|
|
|
|
parent_tid, &args);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void AsanThread::TSDDtor(void *tsd) {
|
|
|
|
AsanThreadContext *context = (AsanThreadContext*)tsd;
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(1, "T%d TSDDtor\n", context->tid);
|
2013-11-04 22:33:31 +01:00
|
|
|
if (context->thread)
|
|
|
|
context->thread->Destroy();
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AsanThread::Destroy() {
|
2014-05-22 09:09:21 +02:00
|
|
|
int tid = this->tid();
|
|
|
|
VReport(1, "T%d exited\n", tid);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
malloc_storage().CommitBack();
|
2014-05-22 09:09:21 +02:00
|
|
|
if (common_flags()->use_sigaltstack) UnsetAlternateSignalStack();
|
|
|
|
asanThreadRegistry().FinishThread(tid);
|
2013-11-04 22:33:31 +01:00
|
|
|
FlushToDeadThreadStats(&stats_);
|
2012-11-12 16:53:47 +01:00
|
|
|
// We also clear the shadow on thread destruction because
|
|
|
|
// some code may still be executing in later TSD destructors
|
|
|
|
// and we don't want it to have any poisoned stack.
|
2013-11-04 22:33:31 +01:00
|
|
|
ClearShadowForThreadStackAndTLS();
|
2014-05-22 09:09:21 +02:00
|
|
|
DeleteFakeStack(tid);
|
2012-11-27 15:01:46 +01:00
|
|
|
uptr size = RoundUpTo(sizeof(AsanThread), GetPageSizeCached());
|
2012-11-12 16:53:47 +01:00
|
|
|
UnmapOrDie(this, size);
|
2014-05-22 09:09:21 +02:00
|
|
|
DTLS_Destroy();
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
|
|
|
|
uptr size) {
|
|
|
|
if (atomic_load(&stack_switching_, memory_order_relaxed)) {
|
|
|
|
Report("ERROR: starting fiber switch while in fiber switch\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
next_stack_bottom_ = bottom;
|
|
|
|
next_stack_top_ = bottom + size;
|
|
|
|
atomic_store(&stack_switching_, 1, memory_order_release);
|
|
|
|
|
|
|
|
FakeStack *current_fake_stack = fake_stack_;
|
|
|
|
if (fake_stack_save)
|
|
|
|
*fake_stack_save = fake_stack_;
|
|
|
|
fake_stack_ = nullptr;
|
|
|
|
SetTLSFakeStack(nullptr);
|
|
|
|
// if fake_stack_save is null, the fiber will die, delete the fakestack
|
|
|
|
if (!fake_stack_save && current_fake_stack)
|
|
|
|
current_fake_stack->Destroy(this->tid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save,
|
|
|
|
uptr *bottom_old,
|
|
|
|
uptr *size_old) {
|
|
|
|
if (!atomic_load(&stack_switching_, memory_order_relaxed)) {
|
|
|
|
Report("ERROR: finishing a fiber switch that has not started\n");
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fake_stack_save) {
|
|
|
|
SetTLSFakeStack(fake_stack_save);
|
|
|
|
fake_stack_ = fake_stack_save;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom_old)
|
|
|
|
*bottom_old = stack_bottom_;
|
|
|
|
if (size_old)
|
|
|
|
*size_old = stack_top_ - stack_bottom_;
|
|
|
|
stack_bottom_ = next_stack_bottom_;
|
|
|
|
stack_top_ = next_stack_top_;
|
|
|
|
atomic_store(&stack_switching_, 0, memory_order_release);
|
|
|
|
next_stack_top_ = 0;
|
|
|
|
next_stack_bottom_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline AsanThread::StackBounds AsanThread::GetStackBounds() const {
|
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 (!atomic_load(&stack_switching_, memory_order_acquire)) {
|
|
|
|
// Make sure the stack bounds are fully initialized.
|
|
|
|
if (stack_bottom_ >= stack_top_) return {0, 0};
|
|
|
|
return {stack_bottom_, stack_top_};
|
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
char local;
|
|
|
|
const uptr cur_stack = (uptr)&local;
|
|
|
|
// Note: need to check next stack first, because FinishSwitchFiber
|
|
|
|
// may be in process of overwriting stack_top_/bottom_. But in such case
|
|
|
|
// we are already on the next stack.
|
|
|
|
if (cur_stack >= next_stack_bottom_ && cur_stack < next_stack_top_)
|
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
|
|
|
return {next_stack_bottom_, next_stack_top_};
|
|
|
|
return {stack_bottom_, stack_top_};
|
2016-11-08 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uptr AsanThread::stack_top() {
|
|
|
|
return GetStackBounds().top;
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr AsanThread::stack_bottom() {
|
|
|
|
return GetStackBounds().bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr AsanThread::stack_size() {
|
|
|
|
const auto bounds = GetStackBounds();
|
|
|
|
return bounds.top - bounds.bottom;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// We want to create the FakeStack lazyly on the first use, but not eralier
|
|
|
|
// than the stack size is known and the procedure has to be async-signal safe.
|
|
|
|
FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
|
|
|
|
uptr stack_size = this->stack_size();
|
|
|
|
if (stack_size == 0) // stack_size is not yet available, don't use FakeStack.
|
2015-10-21 09:32:45 +02:00
|
|
|
return nullptr;
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr old_val = 0;
|
|
|
|
// fake_stack_ has 3 states:
|
|
|
|
// 0 -- not initialized
|
|
|
|
// 1 -- being initialized
|
|
|
|
// ptr -- initialized
|
|
|
|
// This CAS checks if the state was 0 and if so changes it to state 1,
|
2014-05-22 09:09:21 +02:00
|
|
|
// if that was successful, it initializes the pointer.
|
2013-11-04 22:33:31 +01:00
|
|
|
if (atomic_compare_exchange_strong(
|
|
|
|
reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), &old_val, 1UL,
|
|
|
|
memory_order_relaxed)) {
|
|
|
|
uptr stack_size_log = Log2(RoundUpToPowerOfTwo(stack_size));
|
2014-05-22 09:09:21 +02:00
|
|
|
CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
|
|
|
|
stack_size_log =
|
|
|
|
Min(stack_size_log, static_cast<uptr>(flags()->max_uar_stack_size_log));
|
|
|
|
stack_size_log =
|
|
|
|
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
|
2013-11-04 22:33:31 +01:00
|
|
|
fake_stack_ = FakeStack::Create(stack_size_log);
|
|
|
|
SetTLSFakeStack(fake_stack_);
|
|
|
|
return fake_stack_;
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
return nullptr;
|
2013-11-04 22:33:31 +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
|
|
|
void AsanThread::Init(const InitOptions *options) {
|
2016-11-08 23:04:09 +01:00
|
|
|
next_stack_top_ = next_stack_bottom_ = 0;
|
|
|
|
atomic_store(&stack_switching_, false, memory_order_release);
|
2014-09-23 19:59:53 +02:00
|
|
|
CHECK_EQ(this->stack_size(), 0U);
|
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
|
|
|
SetThreadStackAndTls(options);
|
2019-08-14 10:47:11 +02:00
|
|
|
if (stack_top_ != stack_bottom_) {
|
|
|
|
CHECK_GT(this->stack_size(), 0U);
|
|
|
|
CHECK(AddrIsInMem(stack_bottom_));
|
|
|
|
CHECK(AddrIsInMem(stack_top_ - 1));
|
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
ClearShadowForThreadStackAndTLS();
|
2018-10-31 12:14:23 +01:00
|
|
|
fake_stack_ = nullptr;
|
|
|
|
if (__asan_option_detect_stack_use_after_return)
|
|
|
|
AsyncSignalSafeLazyInitFakeStack();
|
2014-05-22 09:09:21 +02:00
|
|
|
int local = 0;
|
|
|
|
VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
|
|
|
|
(void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,
|
|
|
|
&local);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
// Fuchsia and RTEMS don't use ThreadStart.
|
|
|
|
// asan_fuchsia.c/asan_rtems.c define CreateMainThread and
|
|
|
|
// SetThreadStackAndTls.
|
|
|
|
#if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
|
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
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
thread_return_t AsanThread::ThreadStart(
|
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
|
|
|
tid_t os_id, atomic_uintptr_t *signal_thread_is_registered) {
|
2012-11-12 16:53:47 +01:00
|
|
|
Init();
|
2019-08-14 10:47:11 +02:00
|
|
|
asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);
|
2015-10-21 09:32:45 +02:00
|
|
|
if (signal_thread_is_registered)
|
|
|
|
atomic_store(signal_thread_is_registered, 1, memory_order_release);
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
if (common_flags()->use_sigaltstack) SetAlternateSignalStack();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
if (!start_routine_) {
|
|
|
|
// start_routine_ == 0 if we're on the main thread or on one of the
|
|
|
|
// OS X libdispatch worker threads. But nobody is supposed to call
|
|
|
|
// ThreadStart() for the worker threads.
|
2013-11-04 22:33:31 +01:00
|
|
|
CHECK_EQ(tid(), 0);
|
2012-11-12 16:53:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_return_t res = start_routine_(arg_);
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
// On POSIX systems we defer this to the TSD destructor. LSan will consider
|
|
|
|
// the thread's memory as non-live from the moment we call Destroy(), even
|
|
|
|
// though that memory might contain pointers to heap objects which will be
|
|
|
|
// cleaned up by a user-defined TSD destructor. Thus, calling Destroy() before
|
|
|
|
// the TSD destructors have run might cause false positives in LSan.
|
|
|
|
if (!SANITIZER_POSIX)
|
|
|
|
this->Destroy();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
AsanThread *CreateMainThread() {
|
|
|
|
AsanThread *main_thread = AsanThread::Create(
|
|
|
|
/* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ 0,
|
|
|
|
/* stack */ nullptr, /* detached */ true);
|
|
|
|
SetCurrentThread(main_thread);
|
|
|
|
main_thread->ThreadStart(internal_getpid(),
|
|
|
|
/* signal_thread_is_registered */ nullptr);
|
|
|
|
return main_thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This implementation doesn't use the argument, which is just passed down
|
|
|
|
// from the caller of Init (which see, above). It's only there to support
|
|
|
|
// OS-specific implementations that need more information passed through.
|
|
|
|
void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
|
|
|
|
DCHECK_EQ(options, nullptr);
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr tls_size = 0;
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr stack_size = 0;
|
2019-08-14 10:47:11 +02:00
|
|
|
GetThreadStackAndTls(tid() == 0, &stack_bottom_, &stack_size, &tls_begin_,
|
|
|
|
&tls_size);
|
2016-11-08 23:04:09 +01:00
|
|
|
stack_top_ = stack_bottom_ + stack_size;
|
2013-11-04 22:33:31 +01:00
|
|
|
tls_end_ = tls_begin_ + tls_size;
|
2016-11-08 23:04:09 +01:00
|
|
|
dtls_ = DTLS_Get();
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
if (stack_top_ != stack_bottom_) {
|
|
|
|
int local;
|
|
|
|
CHECK(AddrIsInStack((uptr)&local));
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#endif // !SANITIZER_FUCHSIA && !SANITIZER_RTEMS
|
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
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void AsanThread::ClearShadowForThreadStackAndTLS() {
|
2019-08-14 10:47:11 +02:00
|
|
|
if (stack_top_ != stack_bottom_)
|
|
|
|
PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
|
2018-10-31 12:14:23 +01:00
|
|
|
if (tls_begin_ != tls_end_) {
|
|
|
|
uptr tls_begin_aligned = RoundDownTo(tls_begin_, SHADOW_GRANULARITY);
|
|
|
|
uptr tls_end_aligned = RoundUpTo(tls_end_, SHADOW_GRANULARITY);
|
|
|
|
FastPoisonShadowPartialRightRedzone(tls_begin_aligned,
|
|
|
|
tls_end_ - tls_begin_aligned,
|
|
|
|
tls_end_aligned - tls_end_, 0);
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-13 21:41:38 +01:00
|
|
|
bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
|
|
|
|
StackFrameAccess *access) {
|
2019-08-14 10:47:11 +02:00
|
|
|
if (stack_top_ == stack_bottom_)
|
|
|
|
return false;
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
uptr bottom = 0;
|
|
|
|
if (AddrIsInStack(addr)) {
|
|
|
|
bottom = stack_bottom();
|
2013-11-04 22:33:31 +01:00
|
|
|
} else if (has_fake_stack()) {
|
|
|
|
bottom = fake_stack()->AddrIsInFakeStack(addr);
|
2012-11-12 16:53:47 +01:00
|
|
|
CHECK(bottom);
|
2014-11-13 21:41:38 +01:00
|
|
|
access->offset = addr - bottom;
|
|
|
|
access->frame_pc = ((uptr*)bottom)[2];
|
|
|
|
access->frame_descr = (const char *)((uptr*)bottom)[1];
|
|
|
|
return true;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2017-12-05 10:23:25 +01:00
|
|
|
uptr aligned_addr = RoundDownTo(addr, SANITIZER_WORDSIZE / 8); // align addr.
|
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 mem_ptr = RoundDownTo(aligned_addr, SHADOW_GRANULARITY);
|
2012-11-12 16:53:47 +01:00
|
|
|
u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr);
|
|
|
|
u8 *shadow_bottom = (u8*)MemToShadow(bottom);
|
|
|
|
|
|
|
|
while (shadow_ptr >= shadow_bottom &&
|
2012-11-23 15:46:25 +01:00
|
|
|
*shadow_ptr != kAsanStackLeftRedzoneMagic) {
|
2012-11-12 16:53:47 +01:00
|
|
|
shadow_ptr--;
|
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
|
|
|
mem_ptr -= SHADOW_GRANULARITY;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (shadow_ptr >= shadow_bottom &&
|
2012-11-23 15:46:25 +01:00
|
|
|
*shadow_ptr == kAsanStackLeftRedzoneMagic) {
|
2012-11-12 16:53:47 +01:00
|
|
|
shadow_ptr--;
|
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
|
|
|
mem_ptr -= SHADOW_GRANULARITY;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow_ptr < shadow_bottom) {
|
2014-11-13 21:41:38 +01:00
|
|
|
return false;
|
2012-11-12 16:53:47 +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
|
|
|
uptr* ptr = (uptr*)(mem_ptr + SHADOW_GRANULARITY);
|
2012-11-23 15:46:25 +01:00
|
|
|
CHECK(ptr[0] == kCurrentStackFrameMagic);
|
2014-11-13 21:41:38 +01:00
|
|
|
access->offset = addr - (uptr)ptr;
|
|
|
|
access->frame_pc = ptr[2];
|
|
|
|
access->frame_descr = (const char*)ptr[1];
|
|
|
|
return true;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2017-12-05 10:23:25 +01:00
|
|
|
uptr AsanThread::GetStackVariableShadowStart(uptr addr) {
|
|
|
|
uptr bottom = 0;
|
|
|
|
if (AddrIsInStack(addr)) {
|
|
|
|
bottom = stack_bottom();
|
|
|
|
} else if (has_fake_stack()) {
|
|
|
|
bottom = fake_stack()->AddrIsInFakeStack(addr);
|
|
|
|
CHECK(bottom);
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uptr aligned_addr = RoundDownTo(addr, SANITIZER_WORDSIZE / 8); // align addr.
|
|
|
|
u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr);
|
|
|
|
u8 *shadow_bottom = (u8*)MemToShadow(bottom);
|
|
|
|
|
|
|
|
while (shadow_ptr >= shadow_bottom &&
|
|
|
|
(*shadow_ptr != kAsanStackLeftRedzoneMagic &&
|
|
|
|
*shadow_ptr != kAsanStackMidRedzoneMagic &&
|
|
|
|
*shadow_ptr != kAsanStackRightRedzoneMagic))
|
|
|
|
shadow_ptr--;
|
|
|
|
|
|
|
|
return (uptr)shadow_ptr + 1;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
bool AsanThread::AddrIsInStack(uptr addr) {
|
|
|
|
const auto bounds = GetStackBounds();
|
|
|
|
return addr >= bounds.bottom && addr < bounds.top;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
static bool ThreadStackContainsAddress(ThreadContextBase *tctx_base,
|
|
|
|
void *addr) {
|
|
|
|
AsanThreadContext *tctx = static_cast<AsanThreadContext*>(tctx_base);
|
|
|
|
AsanThread *t = tctx->thread;
|
|
|
|
if (!t) return false;
|
|
|
|
if (t->AddrIsInStack((uptr)addr)) return true;
|
|
|
|
if (t->has_fake_stack() && t->fake_stack()->AddrIsInFakeStack((uptr)addr))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AsanThread *GetCurrentThread() {
|
2018-10-31 12:14:23 +01:00
|
|
|
if (SANITIZER_RTEMS && !asan_inited)
|
|
|
|
return nullptr;
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
AsanThreadContext *context =
|
|
|
|
reinterpret_cast<AsanThreadContext *>(AsanTSDGet());
|
|
|
|
if (!context) {
|
|
|
|
if (SANITIZER_ANDROID) {
|
|
|
|
// On Android, libc constructor is called _after_ asan_init, and cleans up
|
|
|
|
// TSD. Try to figure out if this is still the main thread by the stack
|
|
|
|
// address. We are not entirely sure that we have correct main thread
|
|
|
|
// limits, so only do this magic on Android, and only if the found thread
|
|
|
|
// is the main thread.
|
|
|
|
AsanThreadContext *tctx = GetThreadContextByTidLocked(0);
|
2016-11-08 23:04:09 +01:00
|
|
|
if (tctx && ThreadStackContainsAddress(tctx, &context)) {
|
2013-11-04 22:33:31 +01:00
|
|
|
SetCurrentThread(tctx->thread);
|
|
|
|
return tctx->thread;
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
return nullptr;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
return context->thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCurrentThread(AsanThread *t) {
|
|
|
|
CHECK(t->context());
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(2, "SetCurrentThread: %p for thread %p\n", t->context(),
|
|
|
|
(void *)GetThreadSelf());
|
2013-11-04 22:33:31 +01:00
|
|
|
// Make sure we do not reset the current AsanThread.
|
|
|
|
CHECK_EQ(0, AsanTSDGet());
|
|
|
|
AsanTSDSet(t->context());
|
|
|
|
CHECK_EQ(t->context(), AsanTSDGet());
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GetCurrentTidOrInvalid() {
|
|
|
|
AsanThread *t = GetCurrentThread();
|
|
|
|
return t ? t->tid() : kInvalidTid;
|
|
|
|
}
|
|
|
|
|
|
|
|
AsanThread *FindThreadByStackAddress(uptr addr) {
|
|
|
|
asanThreadRegistry().CheckLocked();
|
|
|
|
AsanThreadContext *tctx = static_cast<AsanThreadContext *>(
|
|
|
|
asanThreadRegistry().FindThreadContextLocked(ThreadStackContainsAddress,
|
|
|
|
(void *)addr));
|
2015-10-21 09:32:45 +02:00
|
|
|
return tctx ? tctx->thread : nullptr;
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnsureMainThreadIDIsCorrect() {
|
|
|
|
AsanThreadContext *context =
|
|
|
|
reinterpret_cast<AsanThreadContext *>(AsanTSDGet());
|
|
|
|
if (context && (context->tid == 0))
|
|
|
|
context->os_id = GetTid();
|
|
|
|
}
|
2013-12-05 10:18:38 +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
|
|
|
__asan::AsanThread *GetAsanThreadByOsIDLocked(tid_t os_id) {
|
2013-12-05 10:18:38 +01:00
|
|
|
__asan::AsanThreadContext *context = static_cast<__asan::AsanThreadContext *>(
|
|
|
|
__asan::asanThreadRegistry().FindThreadContextByOsIDLocked(os_id));
|
2015-10-21 09:32:45 +02:00
|
|
|
if (!context) return nullptr;
|
2013-12-05 10:18:38 +01:00
|
|
|
return context->thread;
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __asan
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
// --- Implementation of LSan-specific functions --- {{{1
|
|
|
|
namespace __lsan {
|
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
|
|
|
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
|
|
|
|
uptr *cache_end, DTLS **dtls) {
|
2013-12-05 10:18:38 +01:00
|
|
|
__asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
|
2013-11-04 22:33:31 +01:00
|
|
|
if (!t) return false;
|
|
|
|
*stack_begin = t->stack_bottom();
|
|
|
|
*stack_end = t->stack_top();
|
|
|
|
*tls_begin = t->tls_begin();
|
|
|
|
*tls_end = t->tls_end();
|
|
|
|
// ASan doesn't keep allocator caches in TLS, so these are unused.
|
|
|
|
*cache_begin = 0;
|
|
|
|
*cache_end = 0;
|
2016-11-08 23:04:09 +01:00
|
|
|
*dtls = t->dtls();
|
2013-11-04 22:33:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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 ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback,
|
2013-12-05 10:18:38 +01:00
|
|
|
void *arg) {
|
|
|
|
__asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
|
|
|
|
if (t && t->has_fake_stack())
|
|
|
|
t->fake_stack()->ForEachFakeFrame(callback, arg);
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void LockThreadRegistry() {
|
|
|
|
__asan::asanThreadRegistry().Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnlockThreadRegistry() {
|
|
|
|
__asan::asanThreadRegistry().Unlock();
|
|
|
|
}
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
ThreadRegistry *GetThreadRegistryLocked() {
|
|
|
|
__asan::asanThreadRegistry().CheckLocked();
|
|
|
|
return &__asan::asanThreadRegistry();
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
void EnsureMainThreadIDIsCorrect() {
|
|
|
|
__asan::EnsureMainThreadIDIsCorrect();
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __lsan
|
2016-11-08 23:04:09 +01:00
|
|
|
|
|
|
|
// ---------------------- Interface ---------------- {{{1
|
|
|
|
using namespace __asan; // NOLINT
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_start_switch_fiber(void **fakestacksave, const void *bottom,
|
|
|
|
uptr size) {
|
|
|
|
AsanThread *t = GetCurrentThread();
|
|
|
|
if (!t) {
|
|
|
|
VReport(1, "__asan_start_switch_fiber called from unknown thread\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->StartSwitchFiber((FakeStack**)fakestacksave, (uptr)bottom, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __sanitizer_finish_switch_fiber(void* fakestack,
|
|
|
|
const void **bottom_old,
|
|
|
|
uptr *size_old) {
|
|
|
|
AsanThread *t = GetCurrentThread();
|
|
|
|
if (!t) {
|
|
|
|
VReport(1, "__asan_finish_switch_fiber called from unknown thread\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->FinishSwitchFiber((FakeStack*)fakestack,
|
|
|
|
(uptr*)bottom_old,
|
|
|
|
(uptr*)size_old);
|
|
|
|
}
|
|
|
|
}
|