2012-02-10 01:20:14 +08:00
|
|
|
//===-- asan_win.cc -------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Windows-specific details.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-19 22:33:38 +08:00
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2013-03-19 22:54:17 +08:00
|
|
|
#if SANITIZER_WINDOWS
|
2012-02-10 01:20:14 +08:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <dbghelp.h>
|
2012-02-22 22:07:06 +08:00
|
|
|
#include <stdlib.h>
|
2012-02-10 01:20:14 +08:00
|
|
|
|
|
|
|
#include "asan_interceptors.h"
|
|
|
|
#include "asan_internal.h"
|
2014-07-11 19:57:41 +08:00
|
|
|
#include "asan_report.h"
|
2012-02-10 01:20:14 +08:00
|
|
|
#include "asan_thread.h"
|
2012-06-19 17:21:57 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2013-01-14 15:51:39 +08:00
|
|
|
#include "sanitizer_common/sanitizer_mutex.h"
|
2012-02-10 01:20:14 +08:00
|
|
|
|
2013-09-23 19:05:41 +08:00
|
|
|
extern "C" {
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2013-09-23 19:19:43 +08:00
|
|
|
int __asan_should_detect_stack_use_after_return() {
|
2013-09-23 19:05:41 +08:00
|
|
|
__asan_init();
|
|
|
|
return __asan_option_detect_stack_use_after_return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-10 01:20:14 +08:00
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
// ---------------------- TSD ---------------- {{{1
|
|
|
|
static bool tsd_key_inited = false;
|
|
|
|
|
2012-05-31 22:35:53 +08:00
|
|
|
static __declspec(thread) void *fake_tsd = 0;
|
2012-02-10 01:20:14 +08: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);
|
|
|
|
return fake_tsd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsanTSDSet(void *tsd) {
|
|
|
|
CHECK(tsd_key_inited);
|
|
|
|
fake_tsd = tsd;
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:01:05 +08:00
|
|
|
void PlatformTSDDtor(void *tsd) {
|
|
|
|
AsanThread::TSDDtor(tsd);
|
|
|
|
}
|
2012-02-10 01:20:14 +08:00
|
|
|
// ---------------------- Various stuff ---------------- {{{1
|
2012-08-24 17:22:05 +08:00
|
|
|
void MaybeReexec() {
|
|
|
|
// No need to re-exec on Windows.
|
|
|
|
}
|
|
|
|
|
2012-02-10 01:20:14 +08:00
|
|
|
void *AsanDoesNotSupportStaticLinkage() {
|
2012-03-12 19:45:09 +08:00
|
|
|
#if defined(_DEBUG)
|
|
|
|
#error Please build the runtime with a non-debug CRT: /MD or /MT
|
2012-02-22 21:59:49 +08:00
|
|
|
#endif
|
2012-05-31 22:35:53 +08:00
|
|
|
return 0;
|
2012-02-10 01:20:14 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
void AsanCheckDynamicRTPrereqs() { UNIMPLEMENTED(); }
|
|
|
|
|
|
|
|
void AsanCheckIncompatibleRT() {}
|
|
|
|
|
2012-07-23 22:07:58 +08:00
|
|
|
void AsanPlatformThreadInit() {
|
|
|
|
// Nothing here for now.
|
|
|
|
}
|
|
|
|
|
2013-01-17 23:45:28 +08:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
|
2012-11-23 17:46:34 +08:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2014-01-31 23:11:11 +08:00
|
|
|
void AsanOnSIGSEGV(int, void *siginfo, void *context) {
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
2014-07-11 19:57:41 +08:00
|
|
|
static LPTOP_LEVEL_EXCEPTION_FILTER default_seh_handler;
|
|
|
|
|
|
|
|
long WINAPI SEHHandler(EXCEPTION_POINTERS *info) {
|
|
|
|
EXCEPTION_RECORD *exception_record = info->ExceptionRecord;
|
|
|
|
CONTEXT *context = info->ContextRecord;
|
|
|
|
uptr pc = (uptr)exception_record->ExceptionAddress;
|
|
|
|
#ifdef _WIN64
|
|
|
|
uptr bp = (uptr)context->Rbp, sp = (uptr)context->Rsp;
|
|
|
|
#else
|
|
|
|
uptr bp = (uptr)context->Ebp, sp = (uptr)context->Esp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
|
|
|
|
exception_record->ExceptionCode == EXCEPTION_IN_PAGE_ERROR) {
|
|
|
|
const char *description =
|
|
|
|
(exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
|
|
|
|
? "access-violation"
|
|
|
|
: "in-page-error";
|
|
|
|
uptr access_addr = exception_record->ExceptionInformation[1];
|
|
|
|
ReportSIGSEGV(description, pc, sp, bp, context, access_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Handle EXCEPTION_STACK_OVERFLOW here.
|
|
|
|
|
|
|
|
return default_seh_handler(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SetSEHFilter() {
|
|
|
|
default_seh_handler = SetUnhandledExceptionFilter(SEHHandler);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put a pointer to SetSEHFilter at the end of the global list
|
|
|
|
// of C initializers, after the default handler is set by the CRT.
|
|
|
|
// See crt0dat.c in the CRT sources for the details.
|
|
|
|
#pragma section(".CRT$XIZ", long, read) // NOLINT
|
|
|
|
__declspec(allocate(".CRT$XIZ")) int (*__intercept_seh)() = SetSEHFilter;
|
|
|
|
|
2012-02-10 01:20:14 +08:00
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#endif // _WIN32
|