Add `dup` syscall

master
Harry Cheng 5 years ago
parent 804d6254f9
commit f4c31edab0

@ -520,6 +520,14 @@ impl Syscall<'_> {
Ok(fd2) Ok(fd2)
} }
pub fn sys_dup(&mut self, fd1: usize) -> SysResult {
let mut proc = self.process();
let file_like = proc.get_file_like(fd1)?.clone();
let fd2 = proc.add_file(file_like);
info!("dup: from {} to {}", fd1, fd2);
Ok(fd2)
}
pub fn sys_ioctl( pub fn sys_ioctl(
&mut self, &mut self,
fd: usize, fd: usize,

@ -137,6 +137,7 @@ impl Syscall<'_> {
SYS_FCHOWN => self.unimplemented("fchown", Ok(0)), SYS_FCHOWN => self.unimplemented("fchown", Ok(0)),
SYS_FCHOWNAT => self.unimplemented("fchownat", Ok(0)), SYS_FCHOWNAT => self.unimplemented("fchownat", Ok(0)),
SYS_FACCESSAT => self.sys_faccessat(args[0], args[1] as *const u8, args[2], args[3]), SYS_FACCESSAT => self.sys_faccessat(args[0], args[1] as *const u8, args[2], args[3]),
SYS_DUP => self.sys_dup(args[0]),
SYS_DUP3 => self.sys_dup2(args[0], args[1]), // TODO: handle `flags` SYS_DUP3 => self.sys_dup2(args[0], args[1]), // TODO: handle `flags`
SYS_PIPE2 => self.sys_pipe(args[0] as *mut u32), // TODO: handle `flags` SYS_PIPE2 => self.sys_pipe(args[0] as *mut u32), // TODO: handle `flags`
SYS_UTIMENSAT => self.unimplemented("utimensat", Ok(0)), SYS_UTIMENSAT => self.unimplemented("utimensat", Ok(0)),

Loading…
Cancel
Save