[msandr] Access app TLS directly in native exec mode.

In optimized hybrid execution we do not use DynamoRIO private loader, which
mangles TLS access, so we can access the application's TLS directly.

Patch by Qin Zhao.

llvm-svn: 199655
This commit is contained in:
Evgeniy Stepanov 2014-01-20 13:09:29 +00:00
parent caaa2850c0
commit e98f9099a9
1 changed files with 29 additions and 3 deletions

View File

@ -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 @@ void InstrumentReturn(void *drcontext, instrlist_t *bb, instr_t *instr) {
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 @@ void InstrumentReturn(void *drcontext, instrlist_t *bb, instr_t *instr) {
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 @@ void InstrumentIndirectBranch(void *drcontext, instrlist_t *bb,
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 @@ void InstrumentIndirectBranch(void *drcontext, instrlist_t *bb,
}
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 @@ DR_EXPORT void dr_init(client_id_t id) {
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");
}