fix SysResult::Ok(isize -> usize)

toolchain_update
WangRunji 6 years ago
parent b590545375
commit c3563192b5

@ -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();

@ -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!()
}

@ -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<isize, SysError>;
pub type SysResult = Result<usize, SysError>;
#[allow(dead_code)]
#[repr(isize)]

@ -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)]

@ -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

@ -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)
}

Loading…
Cancel
Save