summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimur Iskhodzhanov <timurrrr@google.com>2014-07-16 14:11:02 +0000
committerTimur Iskhodzhanov <timurrrr@google.com>2014-07-16 14:11:02 +0000
commitc125262f6e89ce9d9145efb6fd0425ebd234975e (patch)
treec7aa8b7add0006bc25b1898716ad2a45f2b916de
parentb84dd55cab068d8287764588f0e74a159c7c87b2 (diff)
downloadcompiler-rt-c125262f6e89ce9d9145efb6fd0425ebd234975e.tar.gz
[ASan/Win] Handle situations when the client app has used DbgHelp before
Reviewed at http://reviews.llvm.org/D4533 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213151 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/sanitizer_symbolizer_win.cc22
-rw-r--r--test/asan/TestCases/Windows/report_after_syminitialize.cc18
2 files changed, 35 insertions, 5 deletions
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_win.cc b/lib/sanitizer_common/sanitizer_symbolizer_win.cc
index dc4816b66..a7acdb69b 100644
--- a/lib/sanitizer_common/sanitizer_symbolizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_symbolizer_win.cc
@@ -32,11 +32,17 @@ class WinSymbolizer : public Symbolizer {
BlockingMutexLock l(&dbghelp_mu_);
if (!initialized_) {
- SymSetOptions(SYMOPT_DEFERRED_LOADS |
- SYMOPT_UNDNAME |
- SYMOPT_LOAD_LINES);
- CHECK(SymInitialize(GetCurrentProcess(), 0, TRUE));
- // FIXME: We don't call SymCleanup() on exit yet - should we?
+ if (!TrySymInitialize()) {
+ // OK, maybe the client app has called SymInitialize already.
+ // That's a bit unfortunate for us as all the DbgHelp functions are
+ // single-threaded and we can't coordinate with the app.
+ // FIXME: Can we stop the other threads at this point?
+ // Anyways, we have to reconfigure stuff to make sure that SymInitialize
+ // has all the appropriate options set.
+ // Cross our fingers and reinitialize DbgHelp.
+ CHECK(SymCleanup(GetCurrentProcess()));
+ CHECK(TrySymInitialize());
+ }
initialized_ = true;
}
@@ -92,6 +98,12 @@ class WinSymbolizer : public Symbolizer {
// FIXME: Implement GetModuleNameAndOffsetForPC().
private:
+ bool TrySymInitialize() {
+ SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
+ return SymInitialize(GetCurrentProcess(), 0, TRUE);
+ // FIXME: We don't call SymCleanup() on exit yet - should we?
+ }
+
// All DbgHelp functions are single threaded, so we should use a mutex to
// serialize accesses.
BlockingMutex dbghelp_mu_;
diff --git a/test/asan/TestCases/Windows/report_after_syminitialize.cc b/test/asan/TestCases/Windows/report_after_syminitialize.cc
new file mode 100644
index 000000000..8a56bf087
--- /dev/null
+++ b/test/asan/TestCases/Windows/report_after_syminitialize.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <windows.h>
+#include <dbghelp.h>
+
+int main() {
+ // Make sure the RTL recovers from "no options enabled" dbghelp setup.
+ SymSetOptions(0);
+
+ // Make sure the RTL recovers from "fInvadeProcess=FALSE".
+ if (!SymInitialize(GetCurrentProcess(), 0, FALSE))
+ return 42;
+
+ *(int*)0 = 42;
+ // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
+ // CHECK-NEXT: {{#0 0x.* in main.*report_after_syminitialize.cc:}}[[@LINE-2]]
+ // CHECK: AddressSanitizer can not provide additional info.
+}