diff options
author | Reid Kleckner <rnk@google.com> | 2016-11-08 20:45:45 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-11-08 20:45:45 +0000 |
commit | 91a6efd7648b46b5defdb883de44711fe8e3c723 (patch) | |
tree | 882531cc94e7bdb251575bc90fe9ad2cd25c6bed /lib/asan/asan_win.cc | |
parent | 5f787a17478ab75610bee81a58ae7f093cadf642 (diff) |
[asan/win] Add init hooks to .CRT$XLAB
Summary:
User applications may register hooks in the .CRT$XL* callback list,
which is called very early by the loader. This is very common in
Chromium:
https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs
This has flown under the radar for a long time because the loader
appears to catch exceptions originating from these callbacks. It's a
real problem when you're debugging an asan application, though, since it
makes the program crash early.
The solution is to add our own callback to this list, and sort it very
early in the list like we do elsewhere. Also add a test with such an
instrumented callback, and test that it gets called with asan.
Reviewers: etienneb
Subscribers: llvm-commits, kubabrecka
Differential Revision: https://reviews.llvm.org/D26404
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286290 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_win.cc')
-rw-r--r-- | lib/asan/asan_win.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc index c3f7943c2..54f622fb2 100644 --- a/lib/asan/asan_win.cc +++ b/lib/asan/asan_win.cc @@ -343,9 +343,23 @@ int __asan_set_seh_filter() { // immediately after the CRT runs. This way, our exception filter is called // first and we can delegate to their filter if appropriate. #pragma section(".CRT$XCAB", long, read) // NOLINT -__declspec(allocate(".CRT$XCAB")) - int (*__intercept_seh)() = __asan_set_seh_filter; +__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) { + if (reason == DLL_PROCESS_ATTACH) __asan_init(); +} + +#pragma section(".CRT$XLAB", long, read) // NOLINT +__declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)( + void *, unsigned long, void *) = asan_thread_init; #endif + + // }}} } // namespace __asan |