[PATCH] make msandr access tls directly

Qin Zhao zhaoqin at google.com
Fri Jan 17 07:01:02 PST 2014


Hi eugenis,

In optimized hybrid execution, we do not use DynamoRIO private loader, which mangle TLS access, so we can access the application's TLS directly.
This diff update msandr to access tls directly when build for optimized hybrid execution.

http://llvm-reviews.chandlerc.com/D2568

Files:
  msandr.cc

Index: msandr.cc
===================================================================
--- msandr.cc
+++ msandr.cc
@@ -92,6 +92,10 @@
 # define SHADOW_MEMORY_MASK 0x3fffffffffffULL
 #endif /* MSANDR_STANDALONE_TEST */
 
+typedef void *(*WrapperFn)(void *);
+extern "C" void __msan_set_indirect_call_wrapper(WrapperFn wrapper);
+extern "C" void __msan_dr_is_initialized();
+
 namespace {
 
 int msan_retval_tls_offset;
@@ -366,8 +370,18 @@
                                        OPSZ_PTR),
              OPND_CREATE_INT32(0)));
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  /* For optimized native exec, -mangle_app_seg and -private_loader are turned off,
+   * so we can reference msan_retval_tls_offset directly.
+   */
+  PRE(instr,
+      mov_st(drcontext,
+             opnd_create_far_base_disp(DR_SEG_FS, DR_REG_NULL, DR_REG_NULL, 0,
+                                       msan_retval_tls_offset, OPSZ_PTR),
+             OPND_CREATE_INT32(0)));
+# else /* !MSANDR_NATIVE_EXEC */
   /* XXX: the code below only works if -mangle_app_seg and -private_loader, 
-   * which is turned of for optimized native exec
+   * which is turned off for optimized native exec
    */
   dr_save_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
 
@@ -382,7 +396,7 @@
              OPND_CREATE_INT32(0)));
 
   dr_restore_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
-
+# endif /* !MSANDR_NATIVE_EXEC */
   // The original instruction is left untouched. The above instrumentation is just
   // a prefix.
 #endif  /* !MSANDR_STANDALONE_TEST */
@@ -403,6 +417,16 @@
                  OPND_CREATE_INT32(0)));
   }
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  for (int i = 0; i < NUM_TLS_PARAM; ++i) {
+    PRE(instr,
+        mov_st(drcontext,
+               opnd_create_far_base_disp(DR_SEG_FS, DR_REG_NULL, DR_REG_NULL, 0,
+                                         msan_param_tls_offset + i*sizeof(void*),
+                                         OPSZ_PTR),
+               OPND_CREATE_INT32(0)));
+  }
+# else /* !MSANDR_NATIVE_EXEC */
   /* XXX: the code below only works if -mangle_app_seg and -private_loader, 
    * which is turned off for optimized native exec
    */
@@ -422,7 +446,7 @@
   }
 
   dr_restore_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
-
+# endif /* !MSANDR_NATIVE_EXEC */
   // The original instruction is left untouched. The above instrumentation is just
   // a prefix.
 #endif  /* !MSANDR_STANDALONE_TEST */
@@ -869,6 +893,8 @@
   drmgr_register_module_load_event(event_module_load);
   drmgr_register_module_unload_event(event_module_unload);
 #endif /* MSANDR_NATIVE_EXEC */
+  __msan_dr_is_initialized();
+  __msan_set_indirect_call_wrapper(dr_app_handle_mbr_target);
   if (VERBOSITY > 0)
     dr_printf("==MSANDR== Starting!\n");
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2568.1.patch
Type: text/x-patch
Size: 2822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140117/6a61fe6b/attachment.bin>


More information about the llvm-commits mailing list