1//===-- asan_win.cc -------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of AddressSanitizer, an address sanity checker.
11//
12// Windows-specific details.
13//===----------------------------------------------------------------------===//
14
15#include "sanitizer_common/sanitizer_platform.h"
16#if SANITIZER_WINDOWS
17#include <windows.h>
18
19#include <dbghelp.h>
20#include <stdlib.h>
21
22#include "asan_interceptors.h"
23#include "asan_internal.h"
24#include "asan_thread.h"
25#include "sanitizer_common/sanitizer_libc.h"
26#include "sanitizer_common/sanitizer_mutex.h"
27
28extern "C" {
29  SANITIZER_INTERFACE_ATTRIBUTE
30  int __asan_should_detect_stack_use_after_return() {
31    __asan_init();
32    return __asan_option_detect_stack_use_after_return;
33  }
34}
35
36namespace __asan {
37
38// ---------------------- TSD ---------------- {{{1
39static bool tsd_key_inited = false;
40
41static __declspec(thread) void *fake_tsd = 0;
42
43void AsanTSDInit(void (*destructor)(void *tsd)) {
44  // FIXME: we're ignoring the destructor for now.
45  tsd_key_inited = true;
46}
47
48void *AsanTSDGet() {
49  CHECK(tsd_key_inited);
50  return fake_tsd;
51}
52
53void AsanTSDSet(void *tsd) {
54  CHECK(tsd_key_inited);
55  fake_tsd = tsd;
56}
57
58void PlatformTSDDtor(void *tsd) {
59  AsanThread::TSDDtor(tsd);
60}
61// ---------------------- Various stuff ---------------- {{{1
62void MaybeReexec() {
63  // No need to re-exec on Windows.
64}
65
66void *AsanDoesNotSupportStaticLinkage() {
67#if defined(_DEBUG)
68#error Please build the runtime with a non-debug CRT: /MD or /MT
69#endif
70  return 0;
71}
72
73void AsanCheckDynamicRTPrereqs() { UNIMPLEMENTED(); }
74
75void AsanCheckIncompatibleRT() {}
76
77void AsanPlatformThreadInit() {
78  // Nothing here for now.
79}
80
81void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
82  UNIMPLEMENTED();
83}
84
85void AsanOnSIGSEGV(int, void *siginfo, void *context) {
86  UNIMPLEMENTED();
87}
88
89}  // namespace __asan
90
91#endif  // _WIN32
92