Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Add support for SYS_clone3. #119

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 20 additions & 1 deletion src/intercept.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,25 @@ get_syscall_in_context(struct context *context, struct syscall_desc *sys)
sys->args[5] = context->r9;
}

/*
* is_clone_syscall
* Checks if the specified syscall is SYS_clone or SYS_clone3 on platforms
* that support clone3.
*/
static bool
is_clone_syscall(long syscall_number)
{
if (syscall_number == SYS_clone)
return true;

#ifdef SYS_clone3
if (syscall_number == SYS_clone3)
return true;
#endif

return false;
}

/*
* intercept_routine(...)
* This is the function called from the asm wrappers,
Expand Down Expand Up @@ -675,7 +694,7 @@ intercept_routine(struct context *context)
* the clone_child_intercept_routine instead, executing
* it on the new child threads stack, then returns to libc.
*/
if (desc.nr == SYS_clone && desc.args[1] != 0)
if (is_clone_syscall(desc.nr) && desc.args[1] != 0)
Copy link
Collaborator

@en4bz en4bz Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arguments are not the same here. desc.args[1] is the stack pointer in clone. The stack pointer for clone3 is desc.args[0]->stack.

#ifdef SYS_clone3
else if(desc.nr == SYS_clone3 && ((struct clone_args*) desc.args[0])->stack != 0) {
    return (struct wrapper_ret){
				.rax = context->rax, .rdx = 2 };
}
#endif

return (struct wrapper_ret){
.rax = context->rax, .rdx = 2 };
else
Expand Down