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#95: Detach on Linux #6513

Merged
merged 46 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e1b9e53
feat: enable detachment on Linux
onroadmuwl Dec 18, 2023
e96b744
feat: use the drconfig frontend for detachment
onroadmuwl Dec 18, 2023
34ce6b3
test: add and modify test case for detachment on Linux and Windows
onroadmuwl Dec 18, 2023
8fe8c24
docs: update the documentation to include detachment on Linux
onroadmuwl Dec 18, 2023
d6d2acb
fix: remove extra space
onroadmuwl Dec 18, 2023
d3589ea
fix: extra space
onroadmuwl Dec 18, 2023
51d2b86
fix: extra space
onroadmuwl Dec 18, 2023
1956e11
fix: modify format
onroadmuwl Dec 18, 2023
8221e5b
fix: test can't be finished
onroadmuwl Dec 18, 2023
0f05ee1
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
cf4cde6
fix: modify the format of conditional macro
onroadmuwl Dec 18, 2023
8a75c73
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
7c0b21b
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
cea79a5
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
30ddfe1
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
892b75b
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
3a00052
fix: add conditional macro ifdef LINUX
onroadmuwl Dec 18, 2023
c54f5b1
test again
onroadmuwl Dec 18, 2023
0caa3ef
Merge branch 'master' into detach
onroadmuwl Dec 19, 2023
35faf43
resume attach test
onroadmuwl Dec 19, 2023
ba45b75
Merge branch 'master' into detach
onroadmuwl Dec 19, 2023
70f137d
debug git test suite
onroadmuwl Dec 20, 2023
0de122f
Merge branch 'master' into detach
onroadmuwl Dec 20, 2023
da9e31c
Merge branch 'detach' of github.com:onroadmuwl/dynamorio into detach
onroadmuwl Dec 20, 2023
2d6fa39
debug git test suite
onroadmuwl Dec 20, 2023
12b244f
add is_detach_external
onroadmuwl Dec 20, 2023
f8fa6a4
ignore on aarch64-native(like attach_test)
onroadmuwl Dec 20, 2023
0442427
remove extra comment and macro
onroadmuwl Dec 20, 2023
11e53e8
Merge branch 'master' into detach
onroadmuwl Dec 21, 2023
77a180d
fix: modify the frontend
onroadmuwl Dec 22, 2023
4be80a7
fix: modify the frontend
onroadmuwl Dec 22, 2023
824efb1
fix: modify the code on detach
onroadmuwl Dec 22, 2023
e18c728
fix: modify the frontend
onroadmuwl Dec 22, 2023
c7ff3ca
fix: add helper functions
onroadmuwl Dec 22, 2023
32306ca
fix: modify format
onroadmuwl Dec 22, 2023
270a3e3
fix: add _IF_WINDOWS inside helper functions
onroadmuwl Dec 22, 2023
33c74be
fix: modify format
onroadmuwl Dec 22, 2023
f97f6e2
fix: modify format
onroadmuwl Dec 22, 2023
dcd7280
fix: modify the test suite
onroadmuwl Dec 22, 2023
a871d8a
fix: modify the test suite
onroadmuwl Dec 22, 2023
eeb6ad2
Merge branch 'master' into detach
onroadmuwl Dec 23, 2023
9eea0c4
style: modfiy detach helpers
onroadmuwl Dec 30, 2023
36b9f94
kill background process forcely
onroadmuwl Dec 30, 2023
b150436
rollback: kill background process forcely
onroadmuwl Dec 30, 2023
351b0e0
modify the test suite
onroadmuwl Dec 30, 2023
05c4481
test again
onroadmuwl Dec 30, 2023
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
6 changes: 6 additions & 0 deletions api/docs/deployment.dox
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ with this command:
% echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
\endcode

Then, you can also detach DynamoRIO from the target process
without affecting the normal execution of the application.
\code
% bin32/drconfig -detach <target_pid>
\endcode

Run \c drrun with no options to get a list of the options and
environment variable shortcuts it supports. To disable following across
child execve calls, use the \ref op_children "-no_follow_children" runtime
Expand Down
4 changes: 2 additions & 2 deletions core/lib/globals_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,9 @@ enum {
#else
NUDGE_NUDGER_FREE_STACK = 0x02, /* nudger will free the nudge thread's stack so the
* nudge thread itself shouldn't */
NUDGE_FREE_ARG = 0x04, /* nudge arg is in a separate allocation and should
* be freed by the nudge thread */
#endif
NUDGE_FREE_ARG = 0x04, /* nudge arg is in a separate allocation and should
* be freed by the nudge thread */
};

typedef struct {
Expand Down
24 changes: 23 additions & 1 deletion core/nudge.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#else
#endif /* WINDOWS */

#ifdef LINUX
# include "synch.h"
#endif

#ifdef HOT_PATCHING_INTERFACE
# include "hotpatch.h" /* for hotp_nudge_update() */
#endif
Expand Down Expand Up @@ -430,12 +434,30 @@ handle_nudge(dcontext_t *dcontext, nudge_arg_t *arg)
SYSLOG_INTERNAL_WARNING("nudge reset ignored since resets are disabled");
}
}
#ifdef WINDOWS
#if defined(WINDOWS) || defined(LINUX)
/* The detach handler is last since in the common case it doesn't return. */
if (TEST(NUDGE_GENERIC(detach), nudge_action_mask)) {
# ifdef WINDOWS
dcontext->free_app_stack = false;
nudge_action_mask &= ~NUDGE_GENERIC(detach);
detach_helper(DETACH_NORMAL_TYPE);
# else
nudge_action_mask &= ~NUDGE_GENERIC(detach);
/* This is not using stack_alloc() because we can't have this being cleaned up
* via normal cleanup paths. */
heap_error_code_t error_code_reserve, error_code_commit;
void *d_r_detachstack =
os_heap_reserve(NULL, DYNAMORIO_STACK_SIZE, &error_code_reserve, false);
/* XXX: This memory is not freed. */
if (!os_heap_commit(d_r_detachstack, DYNAMORIO_STACK_SIZE,
onroadmuwl marked this conversation as resolved.
Show resolved Hide resolved
onroadmuwl marked this conversation as resolved.
Show resolved Hide resolved
MEMPROT_READ | MEMPROT_WRITE, &error_code_commit)) {
ASSERT_NOT_REACHED();
}
call_switch_stack(dcontext,
(byte *)((ptr_uint_t)d_r_detachstack + DYNAMORIO_STACK_SIZE),
(void (*)(void *))detach_externally_on_new_stack, NULL, true);
ASSERT_NOT_REACHED();
# endif
}
#endif
}
Expand Down
10 changes: 8 additions & 2 deletions core/os_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,21 @@ is_thread_currently_native(thread_record_t *tr);
*/
bool
thread_get_mcontext(thread_record_t *tr, priv_mcontext_t *mc);

#ifdef LINUX
bool
thread_get_nudged_mcontext(thread_record_t *tr, priv_mcontext_t *mc);
#endif

bool
thread_set_mcontext(thread_record_t *tr, priv_mcontext_t *mc);

/* Takes an os-specific context. Does not return. */
void
thread_set_self_context(void *cxt);
thread_set_self_context(void *cxt, bool is_detach_external);
/* Only sets the priv_mcontext_t state. Does not return. */
void
thread_set_self_mcontext(priv_mcontext_t *mc);
thread_set_self_mcontext(priv_mcontext_t *mc, bool is_detach_external);

/* Assumes target thread is suspended */
bool
Expand Down
Loading
Loading