[compiler-rt] r213151 - [ASan/Win] Handle situations when the client app has used DbgHelp before

Timur Iskhodzhanov timurrrr at google.com
Wed Jul 16 07:11:05 PDT 2014


Author: timurrrr
Date: Wed Jul 16 09:11:02 2014
New Revision: 213151

URL: http://llvm.org/viewvc/llvm-project?rev=213151&view=rev
Log:
[ASan/Win] Handle situations when the client app has used DbgHelp before

Reviewed at http://reviews.llvm.org/D4533

Added:
    compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc?rev=213151&r1=213150&r2=213151&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_win.cc Wed Jul 16 09:11:02 2014
@@ -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_;

Added: compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc?rev=213151&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/report_after_syminitialize.cc Wed Jul 16 09:11:02 2014
@@ -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.
+}





More information about the llvm-commits mailing list