From c3563192b5f9cc7fd9ecc7297626f8156596e87b Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 8 Mar 2019 19:04:39 +0800 Subject: [PATCH] fix SysResult::Ok(isize -> usize) --- kernel/src/syscall/fs.rs | 22 +++++++++++----------- kernel/src/syscall/mem.rs | 2 +- kernel/src/syscall/mod.rs | 6 +++--- kernel/src/syscall/net.rs | 26 +++++++++++++------------- kernel/src/syscall/proc.rs | 24 ++++++++++++------------ kernel/src/syscall/time.rs | 2 +- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index e86159e..cb3a424 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -43,7 +43,7 @@ pub fn sys_pread(fd: usize, base: *mut u8, len: usize, offset: usize) -> SysResu let slice = unsafe { slice::from_raw_parts_mut(base, len) }; let len = proc.get_file(fd)?.read_at(offset, slice)?; - Ok(len as isize) + Ok(len) } pub fn sys_pwrite(fd: usize, base: *const u8, len: usize, offset: usize) -> SysResult { @@ -53,19 +53,19 @@ pub fn sys_pwrite(fd: usize, base: *const u8, len: usize, offset: usize) -> SysR let slice = unsafe { slice::from_raw_parts(base, len) }; let len = proc.get_file(fd)?.write_at(offset, slice)?; - Ok(len as isize) + Ok(len) } pub fn sys_read_file(proc: &mut Process, fd: usize, base: *mut u8, len: usize) -> SysResult { let slice = unsafe { slice::from_raw_parts_mut(base, len) }; let len = proc.get_file(fd)?.read(slice)?; - Ok(len as isize) + Ok(len) } pub fn sys_write_file(proc: &mut Process, fd: usize, base: *const u8, len: usize) -> SysResult { let slice = unsafe { slice::from_raw_parts(base, len) }; let len = proc.get_file(fd)?.write(slice)?; - Ok(len as isize) + Ok(len) } pub fn sys_poll(ufds: *mut PollFd, nfds: usize, timeout_msecs: usize) -> SysResult { @@ -120,7 +120,7 @@ pub fn sys_poll(ufds: *mut PollFd, nfds: usize, timeout_msecs: usize) -> SysResu drop(proc); if events > 0 { - return Ok(events as isize); + return Ok(events); } let current_time_ms = crate::trap::uptime_msec(); @@ -244,7 +244,7 @@ pub fn sys_select(nfds: usize, read: *mut u32, write: *mut u32, err: *mut u32, t drop(proc); if events > 0 { - return Ok(events as isize); + return Ok(events); } let current_time_ms = crate::trap::uptime_msec(); @@ -267,7 +267,7 @@ pub fn sys_readv(fd: usize, iov_ptr: *const IoVec, iov_count: usize) -> SysResul let len = file.read(buf.as_mut_slice())?; // copy data to user iovs.write_all_from_slice(&buf[..len]); - Ok(len as isize) + Ok(len) } pub fn sys_writev(fd: usize, iov_ptr: *const IoVec, iov_count: usize) -> SysResult { @@ -320,7 +320,7 @@ pub fn sys_open(path: *const u8, flags: usize, mode: usize) -> SysResult { let file = FileHandle::new(inode, flags.to_options()); proc.files.insert(fd, FileLike::File(file)); - Ok(fd as isize) + Ok(fd) } pub fn sys_close(fd: usize) -> SysResult { @@ -396,7 +396,7 @@ pub fn sys_lseek(fd: usize, offset: i64, whence: u8) -> SysResult { let mut proc = process(); let file = proc.get_file(fd)?; let offset = file.seek(pos)?; - Ok(offset as isize) + Ok(offset as usize) } pub fn sys_fsync(fd: usize) -> SysResult { @@ -444,7 +444,7 @@ pub fn sys_getdents64(fd: usize, buf: *mut LinuxDirent64, buf_size: usize) -> Sy let ok = writer.try_write(0, 0, &name); if !ok { break; } } - Ok(writer.written_size as isize) + Ok(writer.written_size) } pub fn sys_dup2(fd1: usize, fd2: usize) -> SysResult { @@ -459,7 +459,7 @@ pub fn sys_dup2(fd1: usize, fd2: usize) -> SysResult { Some(FileLike::File(file)) => { let new_file = FileLike::File(file.clone()); proc.files.insert(fd2, new_file); - Ok(fd2 as isize) + Ok(fd2) }, Some(FileLike::Socket(wrapper)) => { let new_wrapper = wrapper.clone(); diff --git a/kernel/src/syscall/mem.rs b/kernel/src/syscall/mem.rs index 8088239..0e5317e 100644 --- a/kernel/src/syscall/mem.rs +++ b/kernel/src/syscall/mem.rs @@ -33,7 +33,7 @@ pub fn sys_mmap(mut addr: usize, mut len: usize, prot: usize, flags: usize, fd: return Err(SysError::EINVAL); } proc.memory_set.push(addr, addr + len, prot.to_attr(), Delay::new(GlobalFrameAlloc), "mmap"); - return Ok(addr as isize); + return Ok(addr); } unimplemented!() } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 006ca2c..6e3245f 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -173,7 +173,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { } 218 => { warn!("sys_set_tid_address is unimplemented"); - Ok(thread::current().id() as isize) + Ok(thread::current().id()) } 231 => { warn!("sys_exit_group is unimplemented"); @@ -198,12 +198,12 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { }; debug!("{}:{} syscall id {} ret with {:x?}", pid, tid, id, ret); match ret { - Ok(code) => code, + Ok(code) => code as isize, Err(err) => -(err as isize), } } -pub type SysResult = Result; +pub type SysResult = Result; #[allow(dead_code)] #[repr(isize)] diff --git a/kernel/src/syscall/net.rs b/kernel/src/syscall/net.rs index 3bf2893..e1f8cfc 100644 --- a/kernel/src/syscall/net.rs +++ b/kernel/src/syscall/net.rs @@ -55,7 +55,7 @@ pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResu }), ); - Ok(fd as isize) + Ok(fd) } SOCK_DGRAM => { let fd = proc.get_free_inode(); @@ -75,7 +75,7 @@ pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResu }), ); - Ok(fd as isize) + Ok(fd) } SOCK_RAW => { let fd = proc.get_free_inode(); @@ -99,7 +99,7 @@ pub fn sys_socket(domain: usize, socket_type: usize, protocol: usize) -> SysResu socket_type: SocketType::Raw, }), ); - Ok(fd as isize) + Ok(fd) } _ => Err(SysError::EINVAL), }, @@ -229,7 +229,7 @@ pub fn sys_write_socket(proc: &mut Process, fd: usize, base: *const u8, len: usi drop(sockets); iface.poll(); - Ok(size as isize) + Ok(size) } Err(err) => Err(SysError::ENOBUFS), } @@ -260,7 +260,7 @@ pub fn sys_read_socket(proc: &mut Process, fd: usize, base: *mut u8, len: usize) drop(sockets); iface.poll(); - return Ok(size as isize); + return Ok(size); } } else { return Err(SysError::ENOTCONN); @@ -284,7 +284,7 @@ pub fn sys_read_socket(proc: &mut Process, fd: usize, base: *mut u8, len: usize) drop(sockets); iface.poll(); - return Ok(size as isize); + return Ok(size); } } else { return Err(SysError::ENOTCONN); @@ -349,7 +349,7 @@ pub fn sys_sendto( drop(sockets); iface.poll(); - Ok(len as isize) + Ok(len) } else { unimplemented!("ip type") } @@ -376,7 +376,7 @@ pub fn sys_sendto( drop(sockets); iface.poll(); - Ok(len as isize) + Ok(len) } else { unimplemented!("socket type") } @@ -431,7 +431,7 @@ pub fn sys_recvfrom( unsafe { sockaddr_in.write_to(addr, addr_len); } } - return Ok(size as isize); + return Ok(size); } // avoid deadlock @@ -451,7 +451,7 @@ pub fn sys_recvfrom( unsafe { sockaddr_in.write_to(addr, addr_len); } } - return Ok(size as isize); + return Ok(size); } // avoid deadlock @@ -471,7 +471,7 @@ pub fn sys_recvfrom( unsafe { sockaddr_in.write_to(addr, addr_len); } } - return Ok(size as isize); + return Ok(size); } // avoid deadlock @@ -622,7 +622,7 @@ pub fn sys_accept(fd: usize, addr: *mut SockaddrIn, addr_len: *mut u32) -> SysRe let sockaddr_in = SockaddrIn::from(remote_endpoint); unsafe { sockaddr_in.write_to(addr, addr_len); } } - return Ok(new_fd as isize); + return Ok(new_fd); } // avoid deadlock @@ -749,7 +749,7 @@ pub fn sys_dup2_socket(proc: &mut Process, wrapper: SocketWrapper, fd: usize) -> fd, FileLike::Socket(wrapper), ); - Ok(fd as isize) + Ok(fd) } #[repr(C)] diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 0bf6917..4e91636 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -7,15 +7,15 @@ pub fn sys_fork(tf: &TrapFrame) -> SysResult { let context = current_thread().fork(tf); let pid = processor().manager().add(context, thread::current().id()); info!("fork: {} -> {}", thread::current().id(), pid); - Ok(pid as isize) + Ok(pid) } /// Wait the process exit. /// Return the PID. Store exit code to `code` if it's not null. -pub fn sys_wait4(pid: isize, code: *mut i32) -> SysResult { - info!("wait4: pid: {}, code: {:?}", pid, code); - if !code.is_null() { - process().memory_set.check_mut_ptr(code)?; +pub fn sys_wait4(pid: isize, wstatus: *mut i32) -> SysResult { + info!("wait4: pid: {}, code: {:?}", pid, wstatus); + if !wstatus.is_null() { + process().memory_set.check_mut_ptr(wstatus)?; } #[derive(Debug)] enum WaitFor { @@ -48,14 +48,14 @@ pub fn sys_wait4(pid: isize, code: *mut i32) -> SysResult { for pid in wait_procs { match processor().manager().get_status(pid) { Some(Status::Exited(exit_code)) => { - if !code.is_null() { - unsafe { code.write(exit_code as i32); } + if !wstatus.is_null() { + unsafe { wstatus.write(exit_code as i32); } } processor().manager().remove(pid); info!("wait: {} -> {}", thread::current().id(), pid); - return Ok(pid as isize); + return Ok(pid); } - None => return Ok(-1), + None => return Err(SysError::ECHILD), _ => {} } } @@ -134,20 +134,20 @@ pub fn sys_kill(pid: usize) -> SysResult { /// Get the current process id pub fn sys_getpid() -> SysResult { - Ok(thread::current().id() as isize) + Ok(thread::current().id()) } /// Get the current thread id pub fn sys_gettid() -> SysResult { // use pid as tid for now - Ok(thread::current().id() as isize) + Ok(thread::current().id()) } /// Get the parent process id pub fn sys_getppid() -> SysResult { let pid = thread::current().id(); let ppid = processor().manager().get_parent(pid); - Ok(ppid as isize) + Ok(ppid) } /// Exit the current process diff --git a/kernel/src/syscall/time.rs b/kernel/src/syscall/time.rs index d379f78..6eef594 100644 --- a/kernel/src/syscall/time.rs +++ b/kernel/src/syscall/time.rs @@ -105,5 +105,5 @@ pub fn sys_time(time: *mut u64) -> SysResult { time.write(sec as u64); } } - Ok(sec as isize) + Ok(sec as usize) }