[PATCH] Add NATIVE_EXEC macro for building client for running in DynamoRIO hybrid mode only

Qin Zhao zhaoqin at google.com
Tue Oct 15 13:54:40 PDT 2013


Hi eugenis,

When running application in DynamoRIO hybrid mode only, only those interested modules will run in DynamoRIO and be instrumented by the client, so we do not need module table in msander.
Put module table related code under the macro to reduce dependency.


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

Files:
  msandr.cc
  CMakeLists.txt

Index: msandr.cc
===================================================================
--- msandr.cc
+++ msandr.cc
@@ -48,6 +48,12 @@
 #define TESTALL(mask, var) (((mask) & (var)) == (mask))
 #define TESTANY(mask, var) (((mask) & (var)) != 0)
 
+#ifdef NATIVE_EXEC
+# define IF_NE_ELSE(x, y) x
+#else
+# define IF_NE_ELSE(x, y) y
+#endif
+
 #define CHECK_IMPL(condition, file, line)                                      \
   do {                                                                         \
     if (!(condition)) {                                                        \
@@ -62,6 +68,12 @@
 
 namespace {
 
+std::string g_app_path;
+
+int msan_retval_tls_offset;
+int msan_param_tls_offset;
+
+#ifndef NATIVE_EXEC
 class ModuleData {
 public:
   ModuleData();
@@ -78,11 +90,6 @@
   bool executed_;
 };
 
-std::string g_app_path;
-
-int msan_retval_tls_offset;
-int msan_param_tls_offset;
-
 // A vector of loaded modules sorted by module bounds.  We lookup the current PC
 // in here from the bb event.  This is better than an rb tree because the lookup
 // is faster and the bb event occurs far more than the module load event.
@@ -99,6 +106,7 @@
       // We'll check the black/white lists later and adjust this.
       should_instrument_(true), executed_(false) {
 }
+#endif /* !NATIVE_EXEC */
 
 int(*__msan_get_retval_tls_offset)();
 int(*__msan_get_param_tls_offset)();
@@ -319,6 +327,7 @@
   // a prefix.
 }
 
+#ifndef NATIVE_EXEC
 // For use with binary search.  Modules shouldn't overlap, so we shouldn't have
 // to look at end_.  If that can happen, we won't support such an application.
 bool ModuleDataCompareStart(const ModuleData &left, const ModuleData &right) {
@@ -373,22 +382,26 @@
   }
   return true;
 }
+#endif /* !NATIVE_CLIENT */
 
 // TODO(rnk): Make sure we instrument after __msan_init.
 dr_emit_flags_t
 event_basic_block_app2app(void *drcontext, void *tag, instrlist_t *bb,
                           bool for_trace, bool translating) {
+#ifndef NATIVE_EXEC
   app_pc pc = dr_fragment_app_pc(tag);
+#endif /* !NATIVE_EXEC */
 
-  if (ShouldInstrumentPc(pc, NULL))
+  if (IF_NE_ELSE(true, ShouldInstrumentPc(pc, NULL)))
     CHECK(drutil_expand_rep_string(drcontext, bb));
 
   return DR_EMIT_PERSISTABLE;
 }
 
 dr_emit_flags_t event_basic_block(void *drcontext, void *tag, instrlist_t *bb,
                                   bool for_trace, bool translating) {
   app_pc pc = dr_fragment_app_pc(tag);
+#ifndef NATIVE_EXEC
   ModuleData *mod_data;
 
   if (!ShouldInstrumentPc(pc, &mod_data))
@@ -411,6 +424,8 @@
           pc - mod_data->start_);
     }
   }
+#endif /* !NATIVE_EXEC */
+
   if (VERBOSITY > 1) {
     instrlist_disassemble(drcontext, pc, bb, STDOUT);
     instr_t *instr;
@@ -474,6 +489,7 @@
   return DR_EMIT_PERSISTABLE;
 }
 
+#ifndef NATIVE_EXEC
 void event_module_load(void *drcontext, const module_data_t *info,
                        bool loaded) {
   // Insert the module into the list while maintaining the ordering.
@@ -507,6 +523,7 @@
         it->end_ == mod_data.end_ && it->path_ == mod_data.path_);
   g_module_list.erase(it);
 }
+#endif /* !NATIVE_EXEC */
 
 void event_exit() {
   // Clean up so DR doesn't tell us we're leaking memory.
@@ -551,6 +568,7 @@
     drsys_syscall_t *syscall = (drsys_syscall_t *)user_data;
     const char *name;
     res = drsys_syscall_name(syscall, &name);
+    CHECK(res == DRMF_SUCCESS);
     dr_printf("drsyscall: syscall '%s' arg %d wrote range [%p, %p)\n",
               name, arg->ordinal, arg->start_addr,
               (char *)arg->start_addr + sz);
@@ -719,8 +737,10 @@
 
   drmgr_register_bb_app2app_event(event_basic_block_app2app, &priority);
   drmgr_register_bb_instru2instru_event(event_basic_block, &priority);
+#ifndef NATIVE_EXEC
   drmgr_register_module_load_event(event_module_load);
   drmgr_register_module_unload_event(event_module_unload);
+#endif /* NATIVE_EXEC */
   if (VERBOSITY > 0)
     dr_printf("==MSANDR== Starting!\n");
 }
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -4,6 +4,11 @@
   find_package(DynamoRIO)
   find_package(DrMemoryFramework)
 
+  option(NATIVE_EXEC "Building client for running in DynamoRIO hybrid mode, which allows some module running natively" ON)
+  if (NATIVE_EXEC)
+    add_definitions(-DNATIVE_EXEC)
+  endif (NATIVE_EXEC)
+
   set(arch "x86_64")
   add_library(clang_rt.msandr-${arch} SHARED msandr.cc)
   configure_DynamoRIO_client(clang_rt.msandr-${arch})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1942.1.patch
Type: text/x-patch
Size: 4514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/4f129c0c/attachment.bin>


More information about the llvm-commits mailing list