Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#4197: Add new drwrap post-call scheme: replace retaddr #4221

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ Further non-compatibility-affecting changes include:
- Added drwrap_get_stats().
- Added #DRWRAP_NO_DYNAMIC_RETADDRS for reducing drwrap overhead at the cost
of missing some post-call callbacks.
- Added #DRWRAP_REPLACE_RETADDR for an alternative method of setting up post-call
control points by replacing return addresses. This does not work for every
application, but reduces overhead.
- Added -record_dynsym_only to drcachesim for faster function tracing symbol
lookups when internal symbols are not needed.
- Added dr_merge_arith_flags() as a convenience routine to merge arithmetic flags
Expand Down
29 changes: 29 additions & 0 deletions core/synch.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,27 @@ translate_mcontext(thread_record_t *trec, priv_mcontext_t *mcontext, bool restor
dump_mcontext(get_mcontext(trec->dcontext), THREAD_GET, DUMP_NOT_XML);
});
*mcontext = *get_mcontext(trec->dcontext);
#ifdef CLIENT_INTERFACE
if (dr_xl8_hook_exists()) {
/* The client may need to translate here if it's using sentinel
* addresses outside of the code cache as targets.
*/
dr_restore_state_info_t client_info;
dr_mcontext_t client_mcontext;
dr_mcontext_init(&client_mcontext);
priv_mcontext_to_dr_mcontext(&client_mcontext, mcontext);
client_info.raw_mcontext = &client_mcontext;
client_info.raw_mcontext_valid = true;
client_info.mcontext = &client_mcontext;
client_info.fragment_info.tag = NULL;
client_info.fragment_info.cache_start_pc = NULL;
client_info.fragment_info.is_trace = false;
client_info.fragment_info.app_code_consistent = true;
if (!instrument_restore_state(trec->dcontext, true, &client_info))
return false;
dr_mcontext_to_priv_mcontext(mcontext, &client_mcontext);
}
#endif
return true;
}
}
Expand Down Expand Up @@ -2165,6 +2186,14 @@ detach_on_permanent_stack(bool internal, bool do_cleanup, dr_stats_t *drstats)
* app that assumes no signals and assumes its non-auto-restart syscalls
* don't need loops could be broken.
*/
LOG(GLOBAL, LOG_ALL, 3,
/* Having the code bytes can help diagnose post-detach where the code
* cache is gone.
*/
"Detach: pre-xl8 pc=%p (%02x %02x %02x %02x %02x), xsp=%p "
"for thread " TIDFMT "\n",
mc.pc, *mc.pc, *(mc.pc + 1), *(mc.pc + 2), *(mc.pc + 3), *(mc.pc + 4),
mc.xsp, threads[i]->id);
DEBUG_DECLARE(ok =)
translate_mcontext(threads[i], &mc, true /*restore mem*/, NULL /*f*/);
ASSERT(ok);
Expand Down
11 changes: 9 additions & 2 deletions core/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ translate_restore_clean_call(dcontext_t *tdcontext, translate_walk_t *walk)
/* PR 302951: we recognize a clean call by its combination of
* our-mangling and NULL translation.
* We restore to the priv_mcontext_t that was pushed on the stack.
* FIXME i#4219: This is not safe: see comment below.
*/
LOG(THREAD_GET, LOG_INTERP, 2, "\ttranslating clean call arg crash\n");
dr_get_mcontext_priv(tdcontext, NULL, walk->mc);
Expand Down Expand Up @@ -733,7 +734,11 @@ recreate_app_state_from_info(dcontext_t *tdcontext, const translation_info_t *in
* (should spend enough time at syscalls that will hit safe spot in
* reasonable time).
*/
/* PR 302951: our clean calls do show up here and have full state */
/* PR 302951: our clean calls do show up here and have full state.
* FIXME i#4219: Actually we do *not* always have full state: for asynch
* xl8 we could be before setup or after teardown of the mcontext on the
* dstack, and with leaner clean calls we might not have the full mcontext.
*/
if (answer == NULL && ours)
translate_restore_clean_call(tdcontext, &walk);
else
Expand Down Expand Up @@ -888,7 +893,9 @@ recreate_app_state_from_ilist(dcontext_t *tdcontext, instrlist_t *ilist, byte *s
* in the middle of client meta code.
*/
ASSERT(instr_is_meta(inst));
/* PR 302951: our clean calls do show up here and have full state */
/* PR 302951: our clean calls do show up here and have full state.
* FIXME i#4219: This is not safe: see comment above.
*/
if (instr_is_our_mangling(inst))
translate_restore_clean_call(tdcontext, &walk);
else
Expand Down
Loading