[compiler-rt] r191188 - [ASan] Add DLL thunks for the new stack UAR interface

Timur Iskhodzhanov timurrrr at google.com
Mon Sep 23 04:05:41 PDT 2013


Author: timurrrr
Date: Mon Sep 23 06:05:41 2013
New Revision: 191188

URL: http://llvm.org/viewvc/llvm-project?rev=191188&view=rev
Log:
[ASan] Add DLL thunks for the new stack UAR interface

Modified:
    compiler-rt/trunk/lib/asan/asan_dll_thunk.cc
    compiler-rt/trunk/lib/asan/asan_win.cc

Modified: compiler-rt/trunk/lib/asan/asan_dll_thunk.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_dll_thunk.cc?rev=191188&r1=191187&r2=191188&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_dll_thunk.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_dll_thunk.cc Mon Sep 23 06:05:41 2013
@@ -56,6 +56,20 @@ static void *getRealProcAddressOrDie(con
     fn(arg1, arg2);                                                            \
   }
 
+#define WRAP_V_WWW(name)                                                       \
+  extern "C" void name(void *arg1, void *arg2, void *arg3) {                   \
+    typedef void *(*fntype)(void *, void *, void *);                           \
+    fntype fn = (fntype)getRealProcAddressOrDie(#name);                        \
+    fn(arg1, arg2, arg3);                                                      \
+  }
+
+#define WRAP_W_V(name)                                                         \
+  extern "C" void *name() {                                                    \
+    typedef void *(*fntype)();                                                 \
+    fntype fn = (fntype)getRealProcAddressOrDie(#name);                        \
+    return fn();                                                               \
+  }
+
 #define WRAP_W_W(name)                                                         \
   extern "C" void *name(void *arg) {                                           \
     typedef void *(*fntype)(void *arg);                                        \
@@ -102,7 +116,21 @@ static void *getRealProcAddressOrDie(con
 // }}}
 
 // ----------------- ASan own interface functions --------------------
-WRAP_V_V(__asan_init_v3)
+WRAP_W_V(__asan_should_detect_stack_use_after_return)
+
+extern "C" {
+  int __asan_option_detect_stack_use_after_return;
+
+  // Manually wrap __asan_init as we need to initialize
+  // __asan_option_detect_stack_use_after_return afterwards.
+  void __asan_init_v3() {
+    typedef void (*fntype)();
+    static fntype fn = (fntype)getRealProcAddressOrDie("__asan_init_v3");
+    fn();
+    __asan_option_detect_stack_use_after_return =
+        (bool)__asan_should_detect_stack_use_after_return();
+  }
+}
 
 WRAP_V_W(__asan_report_store1)
 WRAP_V_W(__asan_report_store2)
@@ -121,6 +149,29 @@ WRAP_V_WW(__asan_report_load_n)
 WRAP_V_WW(__asan_register_globals)
 WRAP_V_WW(__asan_unregister_globals)
 
+WRAP_W_WW(__asan_stack_malloc_0)
+WRAP_W_WW(__asan_stack_malloc_1)
+WRAP_W_WW(__asan_stack_malloc_2)
+WRAP_W_WW(__asan_stack_malloc_3)
+WRAP_W_WW(__asan_stack_malloc_4)
+WRAP_W_WW(__asan_stack_malloc_5)
+WRAP_W_WW(__asan_stack_malloc_6)
+WRAP_W_WW(__asan_stack_malloc_7)
+WRAP_W_WW(__asan_stack_malloc_8)
+WRAP_W_WW(__asan_stack_malloc_9)
+WRAP_W_WW(__asan_stack_malloc_10)
+
+WRAP_V_WWW(__asan_stack_free_0)
+WRAP_V_WWW(__asan_stack_free_1)
+WRAP_V_WWW(__asan_stack_free_2)
+WRAP_V_WWW(__asan_stack_free_4)
+WRAP_V_WWW(__asan_stack_free_5)
+WRAP_V_WWW(__asan_stack_free_6)
+WRAP_V_WWW(__asan_stack_free_7)
+WRAP_V_WWW(__asan_stack_free_8)
+WRAP_V_WWW(__asan_stack_free_9)
+WRAP_V_WWW(__asan_stack_free_10)
+
 // TODO(timurrrr): Add more interface functions on the as-needed basis.
 
 // ----------------- Memory allocation functions ---------------------

Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=191188&r1=191187&r2=191188&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Mon Sep 23 06:05:41 2013
@@ -25,6 +25,14 @@
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_mutex.h"
 
+extern "C" {
+  SANITIZER_INTERFACE_ATTRIBUTE
+  bool __asan_should_detect_stack_use_after_return() {
+    __asan_init();
+    return __asan_option_detect_stack_use_after_return;
+  }
+}
+
 namespace __asan {
 
 // ---------------------- Stacktraces, symbols, etc. ---------------- {{{1





More information about the llvm-commits mailing list