Skip to content

Commit

Permalink
fix: Fix issue with process exit not synchronizing with client threads
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrewh committed Oct 31, 2024
1 parent 9224d8c commit 73d5a94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyda_core/pyda_core_py.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,4 @@ PydaProcess_pop_state(PyObject* self, PyObject *noarg) {

Py_INCREF(Py_None);
return Py_None;
}
}
11 changes: 7 additions & 4 deletions pyda_core/tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dr_client_main(client_id_t id, int argc, const char *argv[])
dr_register_post_attach_event(event_attach_post);

drmgr_register_signal_event(signal_event);
dr_request_synchronized_exit();

pthread_cond_init(&python_thread_init1, 0);

Expand Down Expand Up @@ -155,6 +156,7 @@ void thread_exit_event(void *drcontext) {
t->app_exited = 1;

pyda_break_noblock(t);
/* dr_fprintf(STDERR, "pyda_break\n"); */
}

static const char *script_name;
Expand Down Expand Up @@ -311,7 +313,7 @@ static dr_signal_action_t signal_event(void *drcontext, dr_siginfo_t *siginfo) {
// since we are throwing.
if (t->run_until)
pyda_clear_run_until(t);

// Raise an exception in Python +
// Wait for Python to yield back to us
pyda_break(t);
Expand Down Expand Up @@ -388,20 +390,20 @@ void python_main_thread(void *arg) {
python_init();

if (!PyGILState_Check()) {
fprintf(stderr, "[Pyda] Error: GIL expected\n");
dr_fprintf(STDERR, "[Pyda] Error: GIL expected\n");
dr_abort();
}

DEBUG_PRINTF("Running script...\n");

if (!script_name) {
fprintf(stderr, "[Pyda] Error: Script not specified\n");
dr_fprintf(STDERR, "[Pyda] Error: Script not specified\n");
goto python_exit;
}

FILE *f = fopen(script_name, "r");
if (!f) {
fprintf(stderr, "[Pyda] Error: could not open %s\n", script_name);
dr_fprintf(STDERR, "[Pyda] Error: could not open %s\n", script_name);
goto python_exit;
}

Expand All @@ -412,6 +414,7 @@ void python_main_thread(void *arg) {

if (PyRun_SimpleFile(f, script_name) == -1) {
// python exception
dr_fprintf(STDERR, "[Pyda] Script raised exception, see above.\n");
}

fclose(f);
Expand Down

0 comments on commit 73d5a94

Please sign in to comment.