2019-08-14 10:47:11 +02:00
|
|
|
//===-- asan_win.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.
|
|
|
|
//
|
|
|
|
// Windows-specific details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
|
|
|
#if SANITIZER_WINDOWS
|
2015-11-23 10:07:18 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2012-11-12 16:53:47 +01:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "asan_interceptors.h"
|
|
|
|
#include "asan_internal.h"
|
2019-08-14 10:47:11 +02:00
|
|
|
#include "asan_mapping.h"
|
2014-09-23 19:59:53 +02:00
|
|
|
#include "asan_report.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "asan_stack.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_thread.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2013-01-23 12:41:33 +01:00
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
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
|
|
|
#include "sanitizer_common/sanitizer_win.h"
|
|
|
|
#include "sanitizer_common/sanitizer_win_defs.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
using namespace __asan;
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
extern "C" {
|
2015-10-21 09:32:45 +02:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
int __asan_should_detect_stack_use_after_return() {
|
|
|
|
__asan_init();
|
|
|
|
return __asan_option_detect_stack_use_after_return;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
uptr __asan_get_shadow_memory_dynamic_address() {
|
|
|
|
__asan_init();
|
|
|
|
return __asan_shadow_memory_dynamic_address;
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
} // extern "C"
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
// ---------------------- Windows-specific interceptors ---------------- {{{
|
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
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER default_seh_handler;
|
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER user_seh_handler;
|
|
|
|
|
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
long __asan_unhandled_exception_filter(EXCEPTION_POINTERS *info) {
|
|
|
|
EXCEPTION_RECORD *exception_record = info->ExceptionRecord;
|
|
|
|
CONTEXT *context = info->ContextRecord;
|
|
|
|
|
|
|
|
// FIXME: Handle EXCEPTION_STACK_OVERFLOW here.
|
|
|
|
|
|
|
|
SignalContext sig(exception_record, context);
|
|
|
|
ReportDeadlySignal(sig);
|
|
|
|
UNREACHABLE("returned from reporting deadly signal");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper SEH Handler. If the exception should be handled by asan, we call
|
|
|
|
// __asan_unhandled_exception_filter, otherwise, we execute the user provided
|
|
|
|
// exception handler or the default.
|
|
|
|
static long WINAPI SEHHandler(EXCEPTION_POINTERS *info) {
|
|
|
|
DWORD exception_code = info->ExceptionRecord->ExceptionCode;
|
|
|
|
if (__sanitizer::IsHandledDeadlyException(exception_code))
|
|
|
|
return __asan_unhandled_exception_filter(info);
|
|
|
|
if (user_seh_handler)
|
|
|
|
return user_seh_handler(info);
|
|
|
|
// Bubble out to the default exception filter.
|
|
|
|
if (default_seh_handler)
|
|
|
|
return default_seh_handler(info);
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR_WINAPI(LPTOP_LEVEL_EXCEPTION_FILTER, SetUnhandledExceptionFilter,
|
2019-08-14 10:47:11 +02:00
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER ExceptionFilter) {
|
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
|
|
|
CHECK(REAL(SetUnhandledExceptionFilter));
|
|
|
|
if (ExceptionFilter == &SEHHandler)
|
|
|
|
return REAL(SetUnhandledExceptionFilter)(ExceptionFilter);
|
|
|
|
// We record the user provided exception handler to be called for all the
|
|
|
|
// exceptions unhandled by asan.
|
|
|
|
Swap(ExceptionFilter, user_seh_handler);
|
|
|
|
return ExceptionFilter;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
INTERCEPTOR_WINAPI(void, RtlRaiseException, EXCEPTION_RECORD *ExceptionRecord) {
|
|
|
|
CHECK(REAL(RtlRaiseException));
|
|
|
|
// This is a noreturn function, unless it's one of the exceptions raised to
|
|
|
|
// communicate with the debugger, such as the one from OutputDebugString.
|
|
|
|
if (ExceptionRecord->ExceptionCode != DBG_PRINTEXCEPTION_C)
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(RtlRaiseException)(ExceptionRecord);
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
INTERCEPTOR_WINAPI(void, RaiseException, void *a, void *b, void *c, void *d) {
|
|
|
|
CHECK(REAL(RaiseException));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(RaiseException)(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#ifdef _WIN64
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
INTERCEPTOR_WINAPI(EXCEPTION_DISPOSITION, __C_specific_handler,
|
|
|
|
_EXCEPTION_RECORD *a, void *b, _CONTEXT *c,
|
2019-11-05 14:54:57 +01:00
|
|
|
_DISPATCHER_CONTEXT *d) {
|
2016-11-08 23:04:09 +01:00
|
|
|
CHECK(REAL(__C_specific_handler));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(__C_specific_handler)(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
INTERCEPTOR(int, _except_handler3, void *a, void *b, void *c, void *d) {
|
|
|
|
CHECK(REAL(_except_handler3));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(_except_handler3)(a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ASAN_DYNAMIC
|
|
|
|
// This handler is named differently in -MT and -MD CRTs.
|
|
|
|
#define _except_handler4 _except_handler4_common
|
|
|
|
#endif
|
|
|
|
INTERCEPTOR(int, _except_handler4, void *a, void *b, void *c, void *d) {
|
|
|
|
CHECK(REAL(_except_handler4));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(_except_handler4)(a, b, c, d);
|
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
|
2019-08-14 10:47:11 +02:00
|
|
|
AsanThread *t = (AsanThread *)arg;
|
2015-10-21 09:32:45 +02:00
|
|
|
SetCurrentThread(t);
|
|
|
|
return t->ThreadStart(GetTid(), /* signal_thread_is_registered */ nullptr);
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
INTERCEPTOR_WINAPI(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES security,
|
|
|
|
SIZE_T stack_size, LPTHREAD_START_ROUTINE start_routine,
|
|
|
|
void *arg, DWORD thr_flags, DWORD *tid) {
|
2015-10-21 09:32:45 +02:00
|
|
|
// Strict init-order checking is thread-hostile.
|
|
|
|
if (flags()->strict_init_order)
|
|
|
|
StopInitOrderChecking();
|
|
|
|
GET_STACK_TRACE_THREAD;
|
|
|
|
// FIXME: The CreateThread interceptor is not the same as a pthread_create
|
|
|
|
// one. This is a bandaid fix for PR22025.
|
|
|
|
bool detached = false; // FIXME: how can we determine it on Windows?
|
|
|
|
u32 current_tid = GetCurrentTidOrInvalid();
|
|
|
|
AsanThread *t =
|
2019-08-14 10:47:11 +02:00
|
|
|
AsanThread::Create(start_routine, arg, current_tid, &stack, detached);
|
|
|
|
return REAL(CreateThread)(security, stack_size, asan_thread_start, t,
|
|
|
|
thr_flags, tid);
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
namespace __asan {
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
void InitializePlatformInterceptors() {
|
2018-10-31 12:14:23 +01:00
|
|
|
// The interceptors were not designed to be removable, so we have to keep this
|
|
|
|
// module alive for the life of the process.
|
|
|
|
HMODULE pinned;
|
2019-08-14 10:47:11 +02:00
|
|
|
CHECK(GetModuleHandleExW(
|
|
|
|
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
|
|
|
|
(LPCWSTR)&InitializePlatformInterceptors, &pinned));
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_INTERCEPT_FUNC(CreateThread);
|
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_INTERCEPT_FUNC(SetUnhandledExceptionFilter);
|
2016-11-08 23:04:09 +01:00
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
ASAN_INTERCEPT_FUNC(__C_specific_handler);
|
|
|
|
#else
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_INTERCEPT_FUNC(_except_handler3);
|
|
|
|
ASAN_INTERCEPT_FUNC(_except_handler4);
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Try to intercept kernel32!RaiseException, and if that fails, intercept
|
|
|
|
// ntdll!RtlRaiseException instead.
|
|
|
|
if (!::__interception::OverrideFunction("RaiseException",
|
|
|
|
(uptr)WRAP(RaiseException),
|
|
|
|
(uptr *)&REAL(RaiseException))) {
|
|
|
|
CHECK(::__interception::OverrideFunction("RtlRaiseException",
|
|
|
|
(uptr)WRAP(RtlRaiseException),
|
|
|
|
(uptr *)&REAL(RtlRaiseException)));
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
|
|
|
|
UNIMPLEMENTED();
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
|
2020-10-16 10:03:04 +02:00
|
|
|
void FlushUnneededASanShadowMemory(uptr p, uptr size) {
|
|
|
|
// Since asan's mapping is compacting, the shadow chunk may be
|
|
|
|
// not page-aligned, so we only flush the page-aligned portion.
|
|
|
|
ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
// ---------------------- TSD ---------------- {{{
|
2012-11-12 16:53:47 +01:00
|
|
|
static bool tsd_key_inited = false;
|
|
|
|
|
|
|
|
static __declspec(thread) void *fake_tsd = 0;
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
// https://docs.microsoft.com/en-us/windows/desktop/api/winternl/ns-winternl-_teb
|
|
|
|
// "[This structure may be altered in future versions of Windows. Applications
|
|
|
|
// should use the alternate functions listed in this topic.]"
|
|
|
|
typedef struct _TEB {
|
|
|
|
PVOID Reserved1[12];
|
|
|
|
// PVOID ThreadLocalStoragePointer; is here, at the last field in Reserved1.
|
|
|
|
PVOID ProcessEnvironmentBlock;
|
|
|
|
PVOID Reserved2[399];
|
|
|
|
BYTE Reserved3[1952];
|
|
|
|
PVOID TlsSlots[64];
|
|
|
|
BYTE Reserved4[8];
|
|
|
|
PVOID Reserved5[26];
|
|
|
|
PVOID ReservedForOle;
|
|
|
|
PVOID Reserved6[4];
|
|
|
|
PVOID TlsExpansionSlots;
|
|
|
|
} TEB, *PTEB;
|
|
|
|
|
|
|
|
constexpr size_t TEB_RESERVED_FIELDS_THREAD_LOCAL_STORAGE_OFFSET = 11;
|
|
|
|
BOOL IsTlsInitialized() {
|
|
|
|
PTEB teb = (PTEB)NtCurrentTeb();
|
|
|
|
return teb->Reserved1[TEB_RESERVED_FIELDS_THREAD_LOCAL_STORAGE_OFFSET] !=
|
|
|
|
nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
void AsanTSDInit(void (*destructor)(void *tsd)) {
|
|
|
|
// FIXME: we're ignoring the destructor for now.
|
|
|
|
tsd_key_inited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *AsanTSDGet() {
|
|
|
|
CHECK(tsd_key_inited);
|
2019-08-14 10:47:11 +02:00
|
|
|
return IsTlsInitialized() ? fake_tsd : nullptr;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AsanTSDSet(void *tsd) {
|
|
|
|
CHECK(tsd_key_inited);
|
|
|
|
fake_tsd = tsd;
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
void PlatformTSDDtor(void *tsd) { AsanThread::TSDDtor(tsd); }
|
2015-10-21 09:32:45 +02:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// ---------------------- Various stuff ---------------- {{{
|
2012-11-12 16:53:47 +01:00
|
|
|
void *AsanDoesNotSupportStaticLinkage() {
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
#error Please build the runtime with a non-debug CRT: /MD or /MT
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
uptr FindDynamicShadowStart() {
|
2020-10-16 10:03:04 +02:00
|
|
|
return MapDynamicShadow(MemToShadowSize(kHighMemEnd), SHADOW_SCALE,
|
|
|
|
/*min_shadow_base_alignment*/ 0, kHighMemEnd);
|
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
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void AsanCheckDynamicRTPrereqs() {}
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
void AsanCheckIncompatibleRT() {}
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-01-23 12:41:33 +01:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2012-11-23 15:46:25 +01:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
void AsanOnDeadlySignal(int, void *siginfo, void *context) { UNIMPLEMENTED(); }
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2020-10-16 10:03:04 +02:00
|
|
|
bool PlatformUnpoisonStacks() { return false; }
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if SANITIZER_WINDOWS64
|
|
|
|
// Exception handler for dealing with shadow memory.
|
|
|
|
static LONG CALLBACK
|
|
|
|
ShadowExceptionHandler(PEXCEPTION_POINTERS exception_pointers) {
|
|
|
|
uptr page_size = GetPageSizeCached();
|
|
|
|
// Only handle access violations.
|
|
|
|
if (exception_pointers->ExceptionRecord->ExceptionCode !=
|
2019-08-14 10:47:11 +02:00
|
|
|
EXCEPTION_ACCESS_VIOLATION ||
|
|
|
|
exception_pointers->ExceptionRecord->NumberParameters < 2) {
|
|
|
|
__asan_handle_no_return();
|
2016-11-08 23:04:09 +01:00
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only handle access violations that land within the shadow memory.
|
|
|
|
uptr addr =
|
|
|
|
(uptr)(exception_pointers->ExceptionRecord->ExceptionInformation[1]);
|
|
|
|
|
|
|
|
// Check valid shadow range.
|
2019-08-14 10:47:11 +02:00
|
|
|
if (!AddrIsInShadow(addr)) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
|
|
|
|
// This is an access violation while trying to read from the shadow. Commit
|
|
|
|
// the relevant page and let execution continue.
|
|
|
|
|
|
|
|
// Determine the address of the page that is being accessed.
|
|
|
|
uptr page = RoundDownTo(addr, page_size);
|
|
|
|
|
|
|
|
// Commit the page.
|
|
|
|
uptr result =
|
|
|
|
(uptr)::VirtualAlloc((LPVOID)page, page_size, MEM_COMMIT, PAGE_READWRITE);
|
2019-08-14 10:47:11 +02:00
|
|
|
if (result != page)
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
2016-11-08 23:04:09 +01:00
|
|
|
|
|
|
|
// The page mapping succeeded, so continue execution as usual.
|
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void InitializePlatformExceptionHandlers() {
|
|
|
|
#if SANITIZER_WINDOWS64
|
|
|
|
// On Win64, we map memory on demand with access violation handler.
|
|
|
|
// Install our exception handler.
|
|
|
|
CHECK(AddVectoredExceptionHandler(TRUE, &ShadowExceptionHandler));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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 IsSystemHeapAddress(uptr addr) {
|
2019-08-14 10:47:11 +02:00
|
|
|
return ::HeapValidate(GetProcessHeap(), 0, (void *)addr) != FALSE;
|
2014-09-23 19:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// We want to install our own exception handler (EH) to print helpful reports
|
|
|
|
// on access violations and whatnot. Unfortunately, the CRT initializers assume
|
|
|
|
// they are run before any user code and drop any previously-installed EHs on
|
|
|
|
// the floor, so we can't install our handler inside __asan_init.
|
|
|
|
// (See crt0dat.c in the CRT sources for the details)
|
|
|
|
//
|
|
|
|
// Things get even more complicated with the dynamic runtime, as it finishes its
|
|
|
|
// initialization before the .exe module CRT begins to initialize.
|
|
|
|
//
|
|
|
|
// For the static runtime (-MT), it's enough to put a callback to
|
|
|
|
// __asan_set_seh_filter in the last section for C initializers.
|
|
|
|
//
|
|
|
|
// For the dynamic runtime (-MD), we want link the same
|
|
|
|
// asan_dynamic_runtime_thunk.lib to all the modules, thus __asan_set_seh_filter
|
|
|
|
// will be called for each instrumented module. This ensures that at least one
|
|
|
|
// __asan_set_seh_filter call happens after the .exe module CRT is initialized.
|
2019-08-14 10:47:11 +02:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE int __asan_set_seh_filter() {
|
2014-09-23 19:59:53 +02:00
|
|
|
// We should only store the previous handler if it's not our own handler in
|
|
|
|
// order to avoid loops in the EH chain.
|
|
|
|
auto prev_seh_handler = SetUnhandledExceptionFilter(SEHHandler);
|
|
|
|
if (prev_seh_handler != &SEHHandler)
|
|
|
|
default_seh_handler = prev_seh_handler;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
bool HandleDlopenInit() {
|
|
|
|
// Not supported on this platform.
|
|
|
|
static_assert(!SANITIZER_SUPPORTS_INIT_FOR_DLOPEN,
|
|
|
|
"Expected SANITIZER_SUPPORTS_INIT_FOR_DLOPEN to be false");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
#if !ASAN_DYNAMIC
|
2016-11-08 23:04:09 +01:00
|
|
|
// The CRT runs initializers in this order:
|
|
|
|
// - C initializers, from XIA to XIZ
|
|
|
|
// - C++ initializers, from XCA to XCZ
|
|
|
|
// Prior to 2015, the CRT set the unhandled exception filter at priority XIY,
|
|
|
|
// near the end of C initialization. Starting in 2015, it was moved to the
|
|
|
|
// beginning of C++ initialization. We set our priority to XCAB to run
|
|
|
|
// immediately after the CRT runs. This way, our exception filter is called
|
|
|
|
// first and we can delegate to their filter if appropriate.
|
2019-11-05 14:54:57 +01:00
|
|
|
#pragma section(".CRT$XCAB", long, read)
|
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
|
|
|
__declspec(allocate(".CRT$XCAB")) int (*__intercept_seh)() =
|
|
|
|
__asan_set_seh_filter;
|
|
|
|
|
|
|
|
// Piggyback on the TLS initialization callback directory to initialize asan as
|
|
|
|
// early as possible. Initializers in .CRT$XL* are called directly by ntdll,
|
|
|
|
// which run before the CRT. Users also add code to .CRT$XLC, so it's important
|
|
|
|
// to run our initializers first.
|
|
|
|
static void NTAPI asan_thread_init(void *module, DWORD reason, void *reserved) {
|
2019-08-14 10:47:11 +02:00
|
|
|
if (reason == DLL_PROCESS_ATTACH)
|
|
|
|
__asan_init();
|
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
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#pragma section(".CRT$XLAB", long, read)
|
2019-08-14 10:47:11 +02:00
|
|
|
__declspec(allocate(".CRT$XLAB")) void(NTAPI *__asan_tls_init)(
|
|
|
|
void *, unsigned long, void *) = asan_thread_init;
|
2014-09-23 19:59:53 +02:00
|
|
|
#endif
|
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
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
static void NTAPI asan_thread_exit(void *module, DWORD reason, void *reserved) {
|
|
|
|
if (reason == DLL_THREAD_DETACH) {
|
|
|
|
// Unpoison the thread's stack because the memory may be re-used.
|
|
|
|
NT_TIB *tib = (NT_TIB *)NtCurrentTeb();
|
|
|
|
uptr stackSize = (uptr)tib->StackBase - (uptr)tib->StackLimit;
|
|
|
|
__asan_unpoison_memory_region(tib->StackLimit, stackSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#pragma section(".CRT$XLY", long, read)
|
2019-08-14 10:47:11 +02:00
|
|
|
__declspec(allocate(".CRT$XLY")) void(NTAPI *__asan_tls_exit)(
|
|
|
|
void *, unsigned long, void *) = asan_thread_exit;
|
|
|
|
|
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
|
|
|
WIN_FORCE_LINK(__asan_dso_reg_hook)
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
// }}}
|
2014-05-22 09:09:21 +02:00
|
|
|
} // namespace __asan
|
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
|
|
|
#endif // SANITIZER_WINDOWS
|