[PATCH] [ASan/Win] Handle situations when the client app has used DbgHelp before
Timur Iskhodzhanov
timurrrr at google.com
Wed Jul 16 05:52:28 PDT 2014
Hi kcc,
http://reviews.llvm.org/D4533
Files:
lib/sanitizer_common/sanitizer_symbolizer_win.cc
test/asan/TestCases/Windows/report_after_syminitialize.cc
Index: lib/sanitizer_common/sanitizer_symbolizer_win.cc
===================================================================
--- lib/sanitizer_common/sanitizer_symbolizer_win.cc
+++ lib/sanitizer_common/sanitizer_symbolizer_win.cc
@@ -32,11 +32,17 @@
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 @@
// 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_;
Index: test/asan/TestCases/Windows/report_after_syminitialize.cc
===================================================================
--- test/asan/TestCases/Windows/report_after_syminitialize.cc
+++ 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.
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4533.11499.patch
Type: text/x-patch
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140716/211ddf65/attachment.bin>
More information about the llvm-commits
mailing list