DynamoRIO / DynamoRIO/dynamorio
add API to set exit cti target of bb
- Dominant language
- C
- Stars
- 3.2k
- Forks
- 629
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 31
Description
_From [bruen...@google.com](https://code.google.com/u/109494838902877177630/) on March 28, 2011 17:27:53_
for function replacing (part of drwrap: issue #296 ) I'm replacing the first bb
w/ a jmp to the replacement. this works well on 32-bit.
on 64-bit though reachability problems add complications.
here are 2 ways to do it, one that jumps through DR memory and thus doesn't
work, and another that clobbers xax:
#ifdef X64
# if 0
//NOCHECKIN: meta instrs in app2app!
dr_save_reg(drcontext, bb, NULL, DR_REG_XAX, SPILL_SLOT_1);
instrlist_meta_preinsert(bb, NULL, INSTR_CREATE_mov_imm
(drcontext, opnd_create_reg(DR_REG_XAX),
OPND_CREATE_INT64(replace)));
instrlist_meta_preinsert(bb, NULL, INSTR_CREATE_mov_st
(drcontext,
dr_reg_spill_slot_opnd(drcontext, SPILL_SLOT_2),
opnd_create_reg(DR_REG_XAX)));
dr_restore_reg(drcontext, bb, NULL, DR_REG_XAX, SPILL_SLOT_1);
//NOCHECKIN: app using DR segment => fail today, mangled w/ issue #107!
instrlist_append(bb, INSTR_XL8
(INSTR_CREATE_jmp_ind
(drcontext,
dr_reg_spill_slot_opnd(drcontext, SPILL_SLOT_2)), pc));
# else
//NOCHECKIN: assumes xax is dead: it is scratch for typical
//calling conventions but best to not assume that
instrlist_append(bb, INSTR_XL8(INSTR_CREATE_mov_imm
(drcontext, opnd_create_reg(DR_REG_XAX),
OPND_CREATE_INT64(replace)), pc));
instrlist_append(bb, INSTR_XL8
(INSTR_CREATE_jmp_ind
(drcontext, opnd_create_reg(DR_REG_XAX)), pc));
# endif
#else
instrlist_append(bb, INSTR_XL8(INSTR_CREATE_jmp
(drcontext, opnd_create_pc(replace)), pc));
#endif
maybe could add DR API to set the exit cti target of a bb, and then have
the bb be empty? should be local change to bb building for DR, w/ target
stored permanently in exit cti. I don't think it would break any DR
assumptions. would look weird to another client: discontinuity in code.
_Original issue: http://code.google.com/p/dynamorio/issues/detail?id=429_
Contributor guide
Assessment
This issue has not been assessed yet.