Skip to content

Commit

Permalink
Add stubs for fork and vfork
Browse files Browse the repository at this point in the history
Progress on shadow#1987
  • Loading branch information
sporksmith committed May 23, 2023
1 parent 9ad9861 commit 983d088
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/host/syscall/handler/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,36 @@ impl SyscallHandler {
)
}

#[log_syscall(/* rv */libc::pid_t)]
pub fn fork(ctx: &mut SyscallContext) -> Result<libc::pid_t, SyscallError> {
// This should be the correct call to `clone_internal`, but `clone_internal`
// will currently return an error.
Self::clone_internal(
ctx,
CloneFlags::empty(),
Some(Signal::SIGCHLD),
ForeignPtr::<()>::null(),
ForeignPtr::<libc::pid_t>::null(),
ForeignPtr::<libc::pid_t>::null(),
0,
)
}

#[log_syscall(/* rv */libc::pid_t)]
pub fn vfork(ctx: &mut SyscallContext) -> Result<libc::pid_t, SyscallError> {
// This should be the correct call to `clone_internal`, but `clone_internal`
// will currently return an error.
Self::clone_internal(
ctx,
CloneFlags::CLONE_VFORK | CloneFlags::CLONE_VM,
Some(Signal::SIGCHLD),
ForeignPtr::<()>::null(),
ForeignPtr::<libc::pid_t>::null(),
ForeignPtr::<libc::pid_t>::null(),
0,
)
}

#[log_syscall(/* rv */libc::pid_t)]
pub fn gettid(ctx: &mut SyscallContext) -> Result<libc::pid_t, SyscallError> {
Ok(libc::pid_t::from(ctx.objs.thread.id()))
Expand Down
2 changes: 2 additions & 0 deletions src/main/host/syscall/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl SyscallHandler {
libc::SYS_eventfd => SyscallHandlerFn::call(Self::eventfd, &mut ctx),
libc::SYS_eventfd2 => SyscallHandlerFn::call(Self::eventfd2, &mut ctx),
libc::SYS_fcntl => SyscallHandlerFn::call(Self::fcntl, &mut ctx),
libc::SYS_fork => SyscallHandlerFn::call(Self::fork, &mut ctx),
libc::SYS_getitimer => SyscallHandlerFn::call(Self::getitimer, &mut ctx),
libc::SYS_getpeername => SyscallHandlerFn::call(Self::getpeername, &mut ctx),
libc::SYS_getrandom => SyscallHandlerFn::call(Self::getrandom, &mut ctx),
Expand Down Expand Up @@ -94,6 +95,7 @@ impl SyscallHandler {
libc::SYS_socket => SyscallHandlerFn::call(Self::socket, &mut ctx),
libc::SYS_socketpair => SyscallHandlerFn::call(Self::socketpair, &mut ctx),
libc::SYS_sysinfo => SyscallHandlerFn::call(Self::sysinfo, &mut ctx),
libc::SYS_vfork => SyscallHandlerFn::call(Self::vfork, &mut ctx),
libc::SYS_write => SyscallHandlerFn::call(Self::write, &mut ctx),
libc::SYS_writev => SyscallHandlerFn::call(Self::writev, &mut ctx),
_ => {
Expand Down
2 changes: 2 additions & 0 deletions src/main/host/syscall_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ SyscallReturn syscallhandler_make_syscall(SysCallHandler* sys, const SysCallArgs
HANDLE_C(fgetxattr);
HANDLE_C(flistxattr);
HANDLE_C(flock);
HANDLE_RUST(fork);
HANDLE_C(fremovexattr);
HANDLE_C(fsetxattr);
HANDLE_C(fstat);
Expand Down Expand Up @@ -466,6 +467,7 @@ SyscallReturn syscallhandler_make_syscall(SysCallHandler* sys, const SysCallArgs
HANDLE_C(uname);
HANDLE_C(unlinkat);
HANDLE_C(utimensat);
HANDLE_RUST(vfork);
HANDLE_RUST(write);
HANDLE_RUST(writev);

Expand Down

0 comments on commit 983d088

Please sign in to comment.