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

Add syscall arguments to clone hooks #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions include/libsyscall_intercept_hook_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ extern int (*intercept_hook_point)(long syscall_number,
long arg2, long arg3,
long arg4, long arg5,
long *result);

extern void (*intercept_hook_point_clone_child)(void);
extern void (*intercept_hook_point_clone_parent)(long pid);
extern void (*intercept_hook_point_clone_child)(
unsigned long flags, void *child_stack,
int *ptid, int *ctid, long newtls);
extern void (*intercept_hook_point_clone_parent)(
unsigned long flags, void *child_stack,
int *ptid, int *ctid, long newtls,
long returned_pid);

/*
* syscall_no_intercept - syscall without interception
Expand Down
29 changes: 25 additions & 4 deletions src/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ int (*intercept_hook_point)(long syscall_number,
long *result)
__attribute__((visibility("default")));

void (*intercept_hook_point_clone_child)(void)
void (*intercept_hook_point_clone_child)(
unsigned long flags, void *child_stack,
int *ptid, int *ctid,
long newtls)
__attribute__((visibility("default")));
void (*intercept_hook_point_clone_parent)(long)

void (*intercept_hook_point_clone_parent)(
unsigned long flags, void *child_stack,
int *ptid, int *ctid,
long newtls, long returned_pid)
__attribute__((visibility("default")));

bool debug_dumps_on;
Expand Down Expand Up @@ -670,12 +677,26 @@ intercept_routine(struct context *context)
struct wrapper_ret
intercept_routine_post_clone(struct context *context)
{
struct syscall_desc desc;
get_syscall_in_context(context, &desc);

if (context->rax == 0) {
if (intercept_hook_point_clone_child != NULL)
intercept_hook_point_clone_child();
intercept_hook_point_clone_child(
(unsigned long)desc.args[0],
(void *)desc.args[1],
(int *)desc.args[2],
(int *)desc.args[3],
desc.args[4]);
} else {
if (intercept_hook_point_clone_parent != NULL)
intercept_hook_point_clone_parent(context->rax);
intercept_hook_point_clone_parent(
(unsigned long)desc.args[0],
(void *)desc.args[1],
(int *)desc.args[2],
(int *)desc.args[3],
desc.args[4],
context->rax);
}

return (struct wrapper_ret){.rax = context->rax, .rdx = 1 };
Expand Down
12 changes: 11 additions & 1 deletion test/test_clone_thread_preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,18 @@ hook(long syscall_number,
* of the clone syscall.
*/
static void
hook_child(void)
hook_child(unsigned long clone_flags,
void *child_stack,
int *ptid,
int *ctid,
long newtls)
{
(void) clone_flags;
(void) child_stack;
(void) ptid;
(void) ctid;
(void) newtls;

static const char msg[] = "clone_hook_child called\n";

assert(flags != -1);
Expand Down