Skip to content

Commit

Permalink
i#975 static DR: support setup;detach
Browse files Browse the repository at this point in the history
Adds support for calling dr_app_setup();dr_app_stop_and_cleanup() with
no start in between.  This is useful to use DR as a decode/encode
library when it's statically linked and also used for instrumentation,
as that setup precludes using drdecodelib, which relies on redirecting
heap allocation via name redirection.

Add a test to api.static_noclient.

Issue: #975
  • Loading branch information
derekbruening committed Jul 12, 2018
1 parent ed7ee7e commit 66e5d4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions core/synch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,17 @@ detach_on_permanent_stack(bool internal, bool do_cleanup, dr_stats_t *drstats)

my_id = get_thread_id();
my_dcontext = get_thread_private_dcontext();
if (my_dcontext == NULL) {
/* We support detach after just dr_app_setup() with no start. */
ASSERT(!dynamo_started);
my_tr = thread_lookup(my_id);
ASSERT(my_tr != NULL);
my_dcontext = my_tr->dcontext;
os_process_under_dynamorio_initiate(my_dcontext);
os_process_under_dynamorio_complete(my_dcontext);
dynamo_thread_under_dynamo(my_dcontext);
ASSERT(get_thread_private_dcontext() == my_dcontext);
}
ASSERT(my_dcontext != NULL);

LOG(GLOBAL, LOG_ALL, 1, "Detach: thread %d starting detach process\n", my_id);
Expand Down
16 changes: 15 additions & 1 deletion suite/tests/api/static_noclient.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2016 Google, Inc. All rights reserved.
* Copyright (c) 2016-2018 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -52,6 +52,20 @@ do_some_work(int seed)
int
main(int argc, const char *argv[])
{
/* We test using DR IR routines when statically linked. We can't use
* drdecode when statically linked with DR as drdecode relies on symbol
* replacement, so instead we initialize DR and then "detach" to do a full
* cleanup (even without an attach) before starting our regular
* attach+detach testing.
* XXX: When there's a client, this requires a flag to skip the client init
* in this first dr_app_setup().
*/
dr_app_setup();
instr_t *instr = XINST_CREATE_return(GLOBAL_DCONTEXT);
assert(instr_is_return(instr));
instr_destroy(GLOBAL_DCONTEXT, instr);
dr_app_stop_and_cleanup();

print("pre-DR init\n");
dr_app_setup();
assert(!dr_app_running_under_dynamorio());
Expand Down

0 comments on commit 66e5d4e

Please sign in to comment.