From f4c31edab044f1271b76dff92a01e2126e21b214 Mon Sep 17 00:00:00 2001 From: Harry Cheng Date: Sun, 28 Jul 2019 23:57:35 +0800 Subject: [PATCH] Add `dup` syscall --- kernel/src/syscall/fs.rs | 8 ++++++++ kernel/src/syscall/mod.rs | 1 + 2 files changed, 9 insertions(+) diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index 640e2c6..2566626 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -520,6 +520,14 @@ impl Syscall<'_> { 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( &mut self, fd: usize, diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 0317b14..b7c5c92 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -137,6 +137,7 @@ impl Syscall<'_> { SYS_FCHOWN => self.unimplemented("fchown", 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_DUP => self.sys_dup(args[0]), 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_UTIMENSAT => self.unimplemented("utimensat", Ok(0)),