|
|
@ -50,22 +50,49 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|
|
|
// See https://filippo.io/linux-syscall-table/
|
|
|
|
// See https://filippo.io/linux-syscall-table/
|
|
|
|
// And https://fedora.juszkiewicz.com.pl/syscalls.html.
|
|
|
|
// And https://fedora.juszkiewicz.com.pl/syscalls.html.
|
|
|
|
let ret = match id {
|
|
|
|
let ret = match id {
|
|
|
|
// file
|
|
|
|
// 0
|
|
|
|
SYS_READ => sys_read(args[0], args[1] as *mut u8, args[2]),
|
|
|
|
SYS_READ => sys_read(args[0], args[1] as *mut u8, args[2]),
|
|
|
|
SYS_WRITE => sys_write(args[0], args[1] as *const u8, args[2]),
|
|
|
|
SYS_WRITE => sys_write(args[0], args[1] as *const u8, args[2]),
|
|
|
|
SYS_CLOSE => sys_close(args[0]),
|
|
|
|
SYS_CLOSE => sys_close(args[0]),
|
|
|
|
SYS_FSTAT => sys_fstat(args[0], args[1] as *mut Stat),
|
|
|
|
SYS_FSTAT => sys_fstat(args[0], args[1] as *mut Stat),
|
|
|
|
SYS_LSEEK => sys_lseek(args[0], args[1] as i64, args[2] as u8),
|
|
|
|
SYS_LSEEK => sys_lseek(args[0], args[1] as i64, args[2] as u8),
|
|
|
|
SYS_MMAP => sys_mmap(args[0], args[1], args[2], args[3], args[4], args[5]),
|
|
|
|
SYS_MMAP => sys_mmap(args[0], args[1], args[2], args[3], args[4], args[5]),
|
|
|
|
|
|
|
|
// 10
|
|
|
|
SYS_MPROTECT => sys_mprotect(args[0], args[1], args[2]),
|
|
|
|
SYS_MPROTECT => sys_mprotect(args[0], args[1], args[2]),
|
|
|
|
SYS_MUNMAP => sys_munmap(args[0], args[1]),
|
|
|
|
SYS_MUNMAP => sys_munmap(args[0], args[1]),
|
|
|
|
|
|
|
|
SYS_BRK => {
|
|
|
|
|
|
|
|
warn!("sys_brk is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_RT_SIGACTION => {
|
|
|
|
|
|
|
|
warn!("sys_sigaction is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_RT_SIGPROCMASK => {
|
|
|
|
|
|
|
|
warn!("sys_sigprocmask is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_IOCTL => {
|
|
|
|
|
|
|
|
warn!("sys_ioctl is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
SYS_PREAD64 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]),
|
|
|
|
SYS_PREAD64 => sys_pread(args[0], args[1] as *mut u8, args[2], args[3]),
|
|
|
|
SYS_PWRITE64 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]),
|
|
|
|
SYS_PWRITE64 => sys_pwrite(args[0], args[1] as *const u8, args[2], args[3]),
|
|
|
|
SYS_READV => sys_readv(args[0], args[1] as *const IoVec, args[2]),
|
|
|
|
SYS_READV => sys_readv(args[0], args[1] as *const IoVec, args[2]),
|
|
|
|
|
|
|
|
// 20
|
|
|
|
SYS_WRITEV => sys_writev(args[0], args[1] as *const IoVec, args[2]),
|
|
|
|
SYS_WRITEV => sys_writev(args[0], args[1] as *const IoVec, args[2]),
|
|
|
|
SYS_SCHED_YIELD => sys_yield(),
|
|
|
|
SYS_SCHED_YIELD => sys_yield(),
|
|
|
|
|
|
|
|
SYS_MADVISE => {
|
|
|
|
|
|
|
|
warn!("sys_madvise is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
SYS_NANOSLEEP => sys_nanosleep(args[0] as *const TimeSpec),
|
|
|
|
SYS_NANOSLEEP => sys_nanosleep(args[0] as *const TimeSpec),
|
|
|
|
|
|
|
|
SYS_SETITIMER => {
|
|
|
|
|
|
|
|
warn!("sys_setitimer is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
SYS_GETPID => sys_getpid(),
|
|
|
|
SYS_GETPID => sys_getpid(),
|
|
|
|
|
|
|
|
// 40
|
|
|
|
SYS_SENDFILE => sys_sendfile(args[0], args[1], args[3] as *mut usize, args[4]),
|
|
|
|
SYS_SENDFILE => sys_sendfile(args[0], args[1], args[3] as *mut usize, args[4]),
|
|
|
|
SYS_SOCKET => sys_socket(args[0], args[1], args[2]),
|
|
|
|
SYS_SOCKET => sys_socket(args[0], args[1], args[2]),
|
|
|
|
SYS_CONNECT => sys_connect(args[0], args[1] as *const SockAddr, args[2]),
|
|
|
|
SYS_CONNECT => sys_connect(args[0], args[1] as *const SockAddr, args[2]),
|
|
|
@ -76,6 +103,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|
|
|
// SYS_RECVMSG => sys_recvmsg(),
|
|
|
|
// SYS_RECVMSG => sys_recvmsg(),
|
|
|
|
SYS_SHUTDOWN => sys_shutdown(args[0], args[1]),
|
|
|
|
SYS_SHUTDOWN => sys_shutdown(args[0], args[1]),
|
|
|
|
SYS_BIND => sys_bind(args[0], args[1] as *const SockAddr, args[2]),
|
|
|
|
SYS_BIND => sys_bind(args[0], args[1] as *const SockAddr, args[2]),
|
|
|
|
|
|
|
|
// 50
|
|
|
|
SYS_LISTEN => sys_listen(args[0], args[1]),
|
|
|
|
SYS_LISTEN => sys_listen(args[0], args[1]),
|
|
|
|
SYS_GETSOCKNAME => sys_getsockname(args[0], args[1] as *mut SockAddr, args[2] as *mut u32),
|
|
|
|
SYS_GETSOCKNAME => sys_getsockname(args[0], args[1] as *mut SockAddr, args[2] as *mut u32),
|
|
|
|
SYS_GETPEERNAME => sys_getpeername(args[0], args[1] as *mut SockAddr, args[2] as *mut u32),
|
|
|
|
SYS_GETPEERNAME => sys_getpeername(args[0], args[1] as *mut SockAddr, args[2] as *mut u32),
|
|
|
@ -83,79 +111,30 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|
|
|
SYS_GETSOCKOPT => sys_getsockopt(args[0], args[1], args[2], args[3] as *mut u8, args[4] as *mut u32),
|
|
|
|
SYS_GETSOCKOPT => sys_getsockopt(args[0], args[1], args[2], args[3] as *mut u8, args[4] as *mut u32),
|
|
|
|
SYS_CLONE => sys_clone(args[0], args[1], args[2] as *mut u32, args[3] as *mut u32, args[4], tf),
|
|
|
|
SYS_CLONE => sys_clone(args[0], args[1], args[2] as *mut u32, args[3] as *mut u32, args[4], tf),
|
|
|
|
SYS_EXECVE => sys_exec(args[0] as *const u8, args[1] as *const *const u8, args[2] as *const *const u8, tf),
|
|
|
|
SYS_EXECVE => sys_exec(args[0] as *const u8, args[1] as *const *const u8, args[2] as *const *const u8, tf),
|
|
|
|
|
|
|
|
// 60
|
|
|
|
SYS_EXIT => sys_exit(args[0] as usize),
|
|
|
|
SYS_EXIT => sys_exit(args[0] as usize),
|
|
|
|
SYS_WAIT4 => sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4
|
|
|
|
SYS_WAIT4 => sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4
|
|
|
|
SYS_KILL => sys_kill(args[0], args[1]),
|
|
|
|
SYS_KILL => sys_kill(args[0], args[1]),
|
|
|
|
SYS_UNAME => sys_uname(args[0] as *mut u8),
|
|
|
|
SYS_UNAME => sys_uname(args[0] as *mut u8),
|
|
|
|
|
|
|
|
SYS_FCNTL => {
|
|
|
|
|
|
|
|
warn!("sys_fcntl is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
SYS_FSYNC => sys_fsync(args[0]),
|
|
|
|
SYS_FSYNC => sys_fsync(args[0]),
|
|
|
|
SYS_FDATASYNC => sys_fdatasync(args[0]),
|
|
|
|
SYS_FDATASYNC => sys_fdatasync(args[0]),
|
|
|
|
SYS_TRUNCATE => sys_truncate(args[0] as *const u8, args[1]),
|
|
|
|
SYS_TRUNCATE => sys_truncate(args[0] as *const u8, args[1]),
|
|
|
|
SYS_FTRUNCATE => sys_ftruncate(args[0], args[1]),
|
|
|
|
SYS_FTRUNCATE => sys_ftruncate(args[0], args[1]),
|
|
|
|
SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]),
|
|
|
|
SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]),
|
|
|
|
|
|
|
|
// 80
|
|
|
|
SYS_CHDIR => sys_chdir(args[0] as *const u8),
|
|
|
|
SYS_CHDIR => sys_chdir(args[0] as *const u8),
|
|
|
|
SYS_GETTIMEOFDAY => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8),
|
|
|
|
SYS_GETTIMEOFDAY => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8),
|
|
|
|
// SYS_GETRLIMIT => sys_getrlimit(),
|
|
|
|
|
|
|
|
SYS_GETRUSAGE => sys_getrusage(args[0], args[1] as *mut RUsage),
|
|
|
|
|
|
|
|
SYS_SYSINFO => sys_sysinfo(args[0] as *mut SysInfo),
|
|
|
|
|
|
|
|
SYS_GETPPID => sys_getppid(),
|
|
|
|
|
|
|
|
SYS_SETPRIORITY => sys_set_priority(args[0]),
|
|
|
|
|
|
|
|
// SYS_SETRLIMIT => sys_setrlimit(),
|
|
|
|
|
|
|
|
SYS_SYNC => sys_sync(),
|
|
|
|
|
|
|
|
SYS_REBOOT => sys_reboot(args[0] as u32, args[1] as u32, args[2] as u32, args[3] as *const u8),
|
|
|
|
|
|
|
|
SYS_GETTID => sys_gettid(),
|
|
|
|
|
|
|
|
SYS_FUTEX => sys_futex(args[0], args[1] as u32, args[2] as i32, args[3] as *const TimeSpec),
|
|
|
|
|
|
|
|
SYS_SCHED_GETAFFINITY => sys_sched_getaffinity(args[0], args[1], args[2] as *mut u32),
|
|
|
|
|
|
|
|
SYS_GETDENTS64 => sys_getdents64(args[0], args[1] as *mut LinuxDirent64, args[2]),
|
|
|
|
|
|
|
|
SYS_CLOCK_GETTIME => sys_clock_gettime(args[0], args[1] as *mut TimeSpec),
|
|
|
|
|
|
|
|
SYS_EXIT_GROUP => sys_exit_group(args[0]),
|
|
|
|
|
|
|
|
SYS_OPENAT => sys_open(args[1] as *const u8, args[2], args[3]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
SYS_MKDIRAT => sys_mkdir(args[1] as *const u8, args[2]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
// SYS_MKNODAT => sys_mknod(),
|
|
|
|
|
|
|
|
SYS_NEWFSTATAT => sys_stat(args[1] as *const u8, args[2] as *mut Stat), // TODO: handle `dfd`, `flag`
|
|
|
|
|
|
|
|
SYS_UNLINKAT => sys_unlink(args[1] as *const u8), // TODO: handle `dfd`, `flag`
|
|
|
|
|
|
|
|
SYS_RENAMEAT => sys_rename(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`
|
|
|
|
|
|
|
|
SYS_LINKAT => sys_link(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`, `flags`
|
|
|
|
|
|
|
|
SYS_FACCESSAT => sys_access(args[1] as *const u8, args[2]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
SYS_ACCEPT4 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4
|
|
|
|
|
|
|
|
SYS_DUP3 => sys_dup2(args[0], args[1]), // TODO: handle `flags`
|
|
|
|
|
|
|
|
SYS_PIPE2 => sys_pipe(args[0] as *mut u32), // TODO: handle `flags`
|
|
|
|
|
|
|
|
// custom temporary syscall
|
|
|
|
|
|
|
|
SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]),
|
|
|
|
|
|
|
|
SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for musl: empty impl
|
|
|
|
|
|
|
|
SYS_BRK => {
|
|
|
|
|
|
|
|
warn!("sys_brk is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_RT_SIGACTION => {
|
|
|
|
|
|
|
|
warn!("sys_sigaction is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_RT_SIGPROCMASK => {
|
|
|
|
|
|
|
|
warn!("sys_sigprocmask is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_IOCTL => {
|
|
|
|
|
|
|
|
warn!("sys_ioctl is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_MADVISE => {
|
|
|
|
|
|
|
|
warn!("sys_madvise is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_SETITIMER => {
|
|
|
|
|
|
|
|
warn!("sys_setitimer is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_FCNTL => {
|
|
|
|
|
|
|
|
warn!("sys_fcntl is unimplemented");
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_UMASK => {
|
|
|
|
SYS_UMASK => {
|
|
|
|
warn!("sys_umask is unimplemented");
|
|
|
|
warn!("sys_umask is unimplemented");
|
|
|
|
Ok(0o777)
|
|
|
|
Ok(0o777)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SYS_GETRLIMIT => sys_getrlimit(),
|
|
|
|
|
|
|
|
SYS_GETRUSAGE => sys_getrusage(args[0], args[1] as *mut RUsage),
|
|
|
|
|
|
|
|
SYS_SYSINFO => sys_sysinfo(args[0] as *mut SysInfo),
|
|
|
|
SYS_GETUID => {
|
|
|
|
SYS_GETUID => {
|
|
|
|
warn!("sys_getuid is unimplemented");
|
|
|
|
warn!("sys_getuid is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
@ -176,6 +155,8 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|
|
|
warn!("sys_getegid is unimplemented");
|
|
|
|
warn!("sys_getegid is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 110
|
|
|
|
|
|
|
|
SYS_GETPPID => sys_getppid(),
|
|
|
|
SYS_SETSID => {
|
|
|
|
SYS_SETSID => {
|
|
|
|
warn!("sys_setsid is unimplemented");
|
|
|
|
warn!("sys_setsid is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
@ -184,22 +165,53 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
|
|
|
warn!("sys_sigaltstack is unimplemented");
|
|
|
|
warn!("sys_sigaltstack is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_FSTATFS => {
|
|
|
|
|
|
|
|
warn!("fstat: not implemented");
|
|
|
|
|
|
|
|
Err(SysError::EACCES)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_SETPRIORITY => sys_set_priority(args[0]),
|
|
|
|
|
|
|
|
// SYS_SETRLIMIT => sys_setrlimit(),
|
|
|
|
|
|
|
|
SYS_SYNC => sys_sync(),
|
|
|
|
|
|
|
|
SYS_REBOOT => sys_reboot(args[0] as u32, args[1] as u32, args[2] as u32, args[3] as *const u8),
|
|
|
|
|
|
|
|
SYS_GETTID => sys_gettid(),
|
|
|
|
|
|
|
|
SYS_FUTEX => sys_futex(args[0], args[1] as u32, args[2] as i32, args[3] as *const TimeSpec),
|
|
|
|
|
|
|
|
SYS_SCHED_GETAFFINITY => sys_sched_getaffinity(args[0], args[1], args[2] as *mut u32),
|
|
|
|
|
|
|
|
SYS_GETDENTS64 => sys_getdents64(args[0], args[1] as *mut LinuxDirent64, args[2]),
|
|
|
|
SYS_SET_TID_ADDRESS => {
|
|
|
|
SYS_SET_TID_ADDRESS => {
|
|
|
|
warn!("sys_set_tid_address is unimplemented");
|
|
|
|
warn!("sys_set_tid_address is unimplemented");
|
|
|
|
Ok(thread::current().id())
|
|
|
|
Ok(thread::current().id())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_CLOCK_GETTIME => sys_clock_gettime(args[0], args[1] as *mut TimeSpec),
|
|
|
|
|
|
|
|
SYS_EXIT_GROUP => sys_exit_group(args[0]),
|
|
|
|
|
|
|
|
SYS_OPENAT => sys_open(args[1] as *const u8, args[2], args[3]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
SYS_MKDIRAT => sys_mkdir(args[1] as *const u8, args[2]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
// SYS_MKNODAT => sys_mknod(),
|
|
|
|
|
|
|
|
SYS_NEWFSTATAT => sys_stat(args[1] as *const u8, args[2] as *mut Stat), // TODO: handle `dfd`, `flag`
|
|
|
|
|
|
|
|
SYS_UNLINKAT => sys_unlink(args[1] as *const u8), // TODO: handle `dfd`, `flag`
|
|
|
|
|
|
|
|
SYS_RENAMEAT => sys_rename(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`
|
|
|
|
|
|
|
|
SYS_LINKAT => sys_link(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`, `flags`
|
|
|
|
|
|
|
|
SYS_FACCESSAT => sys_access(args[1] as *const u8, args[2]), // TODO: handle `dfd`
|
|
|
|
|
|
|
|
// 280
|
|
|
|
SYS_UTIMENSAT => {
|
|
|
|
SYS_UTIMENSAT => {
|
|
|
|
warn!("sys_utimensat is unimplemented");
|
|
|
|
warn!("sys_utimensat is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_ACCEPT4 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4
|
|
|
|
SYS_EPOLL_CREATE1 => {
|
|
|
|
SYS_EPOLL_CREATE1 => {
|
|
|
|
warn!("sys_epoll_create1 is unimplemented");
|
|
|
|
warn!("sys_epoll_create1 is unimplemented");
|
|
|
|
Err(SysError::ENOSYS)
|
|
|
|
Err(SysError::ENOSYS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_DUP3 => sys_dup2(args[0], args[1]), // TODO: handle `flags`
|
|
|
|
|
|
|
|
SYS_PIPE2 => sys_pipe(args[0] as *mut u32), // TODO: handle `flags`
|
|
|
|
SYS_PRLIMIT64 => {
|
|
|
|
SYS_PRLIMIT64 => {
|
|
|
|
warn!("sys_prlimit64 is unimplemented");
|
|
|
|
warn!("sys_prlimit64 is unimplemented");
|
|
|
|
Ok(0)
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// custom temporary syscall
|
|
|
|
|
|
|
|
SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]),
|
|
|
|
|
|
|
|
SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]),
|
|
|
|
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
_ => {
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
let x86_64_ret = x86_64_syscall(id, args, tf);
|
|
|
|
let x86_64_ret = x86_64_syscall(id, args, tf);
|
|
|
|