1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 08:06:17 +04:00

Run code format

This commit is contained in:
Jiajie Chen 2019-11-18 13:59:07 +08:00
parent 0a1e422cac
commit 52afd05946
8 changed files with 113 additions and 114 deletions

View File

@ -1,11 +1,11 @@
use alloc::{collections::BTreeMap, collections::BTreeSet};
use crate::syscall::{SysError, SysResult};
use core::slice;
use crate::sync::{Condvar, SpinNoIrqLock};
use crate::memory::MemorySet;
use core::mem::size_of;
use crate::process::Process;
use crate::fs::FileLike;
use crate::memory::MemorySet;
use crate::process::Process;
use crate::sync::{Condvar, SpinNoIrqLock};
use crate::syscall::{SysError, SysResult};
use alloc::{collections::BTreeMap, collections::BTreeSet};
use core::mem::size_of;
use core::slice;
pub struct EpollInstance {
pub events: BTreeMap<usize, EpollEvent>,
@ -22,10 +22,10 @@ impl Clone for EpollInstance {
impl EpollInstance {
pub fn new(flags: usize) -> Self {
return EpollInstance {
events: BTreeMap::new(),
events: BTreeMap::new(),
readyList: Default::default(),
newCtlList: Default::default(),
}
};
}
pub fn control(&mut self, op: usize, fd: usize, event: &EpollEvent) -> SysResult {
@ -40,7 +40,6 @@ impl EpollInstance {
self.events.remove(&fd);
self.events.insert(fd, event.clone());
self.newCtlList.lock().insert(fd);
} else {
return Err(SysError::EPERM);
}
@ -52,7 +51,6 @@ impl EpollInstance {
} else {
return Err(SysError::EPERM);
}
}
_ => {
return Err(SysError::EPERM);
@ -62,9 +60,6 @@ impl EpollInstance {
}
}
#[derive(Clone, Copy)]
pub struct EpollData {
ptr: u64,
@ -73,12 +68,11 @@ pub struct EpollData {
#[repr(packed)]
#[derive(Clone)]
pub struct EpollEvent {
pub events: u32, /* Epoll events */
pub data: EpollData, /* User data variable */
pub events: u32, /* Epoll events */
pub data: EpollData, /* User data variable */
}
impl EpollEvent{
impl EpollEvent {
pub const EPOLLIN: u32 = 0x001;
pub const EPOLLOUT: u32 = 0x004;
pub const EPOLLERR: u32 = 0x008;
@ -95,7 +89,6 @@ impl EpollEvent{
pub const EPOLLWAKEUP: u32 = 1 << 29;
pub const EPOLLONESHOT: u32 = 1 << 30;
pub const EPOLLET: u32 = 1 << 31;
pub fn contains(&self, events: u32) -> bool {
if (self.events & events) == 0 {
@ -107,13 +100,12 @@ impl EpollEvent{
}
pub struct EPollCtlOp;
impl EPollCtlOp{
const ADD: i32 = 1; /* Add a file descriptor to the interface. */
const DEL: i32 = 2; /* Remove a file descriptor from the interface. */
const MOD: i32 = 3; /* Change file descriptor epoll_event structure. */
impl EPollCtlOp {
const ADD: i32 = 1; /* Add a file descriptor to the interface. */
const DEL: i32 = 2; /* Remove a file descriptor from the interface. */
const MOD: i32 = 3; /* Change file descriptor epoll_event structure. */
}
impl Process {
pub fn get_epoll_instance_mut(&mut self, fd: usize) -> Result<&mut EpollInstance, SysError> {
match self.get_file_like(fd)? {
@ -124,16 +116,13 @@ impl Process {
pub fn get_epoll_instance(&self, fd: usize) -> Result<&EpollInstance, SysError> {
match self.files.get(&fd) {
Some(file_like) => {
match file_like {
FileLike::EpollInstance(instance) => Ok(&instance),
_ => Err(SysError::EPERM),
}
}
Some(file_like) => match file_like {
FileLike::EpollInstance(instance) => Ok(&instance),
_ => Err(SysError::EPERM),
},
None => {
return Err(SysError::EPERM);
}
}
}
}
}

View File

@ -4,11 +4,11 @@ use super::ioctl::*;
use super::FileHandle;
use crate::fs::epoll::EpollInstance;
use crate::net::Socket;
use crate::sync::Condvar;
use crate::syscall::{SysError, SysResult};
use alloc::boxed::Box;
use rcore_fs::vfs::PollStatus;
use crate::sync::Condvar;
use alloc::vec::Vec;
use rcore_fs::vfs::PollStatus;
// TODO: merge FileLike to FileHandle ?
// TODO: fix dup and remove Clone
@ -52,7 +52,7 @@ impl FileLike {
socket.ioctl(request, arg1, arg2, arg3)?;
}
FileLike::EpollInstance(instance) => {
return Err(SysError::ENOSYS);
return Err(SysError::ENOSYS);
}
}
Ok(0)
@ -79,14 +79,10 @@ impl FileLike {
FileLike::Socket(socket) => {
//TODO
}
FileLike::EpollInstance(instance) => {
}
FileLike::EpollInstance(instance) => {}
}
Ok(0)
}
}
impl fmt::Debug for FileLike {

View File

@ -6,9 +6,9 @@ use core::any::Any;
use rcore_fs::vfs::*;
use super::ioctl::*;
use crate::process::Process;
use crate::sync::Condvar;
use crate::sync::SpinNoIrqLock as Mutex;
use crate::process::Process;
#[derive(Default)]
pub struct Stdin {
@ -44,8 +44,6 @@ impl Stdin {
pub fn can_read(&self) -> bool {
return self.buf.lock().len() > 0;
}
}
#[derive(Default)]

View File

@ -1,10 +1,10 @@
use super::*;
use crate::process::{processor, current_thread};
use crate::process::Process;
use crate::process::{current_thread, processor};
use crate::thread;
use alloc::collections::VecDeque;
use alloc::sync::Arc;
use alloc::vec::Vec;
use crate::process::Process;
use rcore_thread::std_thread::Thread;
pub struct RegisteredProcess {
@ -106,7 +106,6 @@ impl Condvar {
}
}
pub fn notify_all(&self) {
let queue = self.wait_queue.lock();
for t in queue.iter() {
@ -130,20 +129,28 @@ impl Condvar {
count
}
pub fn register_epoll_list(&self, proc: Arc<SpinNoIrqLock<Process>>, tid :usize, epfd: usize, fd: usize){
self.epoll_queue.lock().push_back(RegisteredProcess{
pub fn register_epoll_list(
&self,
proc: Arc<SpinNoIrqLock<Process>>,
tid: usize,
epfd: usize,
fd: usize,
) {
self.epoll_queue.lock().push_back(RegisteredProcess {
proc: proc,
tid: tid,
epfd: epfd,
fd: fd,
}
);
});
}
pub fn unregister_epoll_list(&self, tid :usize, epfd: usize, fd: usize) -> bool{
pub fn unregister_epoll_list(&self, tid: usize, epfd: usize, fd: usize) -> bool {
let mut epoll_list = self.epoll_queue.lock();
for idx in 0..epoll_list.len(){
if epoll_list[idx].tid == tid && epoll_list[idx].epfd == epfd && epoll_list[idx].fd == fd{
for idx in 0..epoll_list.len() {
if epoll_list[idx].tid == tid
&& epoll_list[idx].epfd == epfd
&& epoll_list[idx].fd == fd
{
epoll_list.remove(idx);
return true;
}
@ -168,5 +175,4 @@ impl Condvar {
}
}
}
}

View File

@ -6,21 +6,21 @@ use core::mem::size_of;
use rcore_fs::vfs::Timespec;
use crate::drivers::SOCKET_ACTIVITY;
use crate::trap::TICK_ACTIVITY;
use crate::fs::*;
use crate::memory::MemorySet;
use crate::sync::{Condvar, SpinNoIrqLock};
use crate::trap::TICK_ACTIVITY;
use alloc::{collections::BTreeMap, collections::BTreeSet};
use bitvec::prelude::{BitSlice, BitVec, LittleEndian};
use super::*;
use bitflags::_core::task::Poll;
use alloc::collections::VecDeque;
use rcore_fs::vfs::PollStatus;
use crate::fs::epoll::EpollInstance;
use crate::net::server;
use crate::process::Process;
use crate::fs::epoll::EpollInstance;
use alloc::collections::VecDeque;
use bitflags::_core::task::Poll;
use rcore_fs::vfs::PollStatus;
impl Syscall<'_> {
pub fn sys_read(&mut self, fd: usize, base: *mut u8, len: usize) -> SysResult {
@ -113,7 +113,7 @@ impl Syscall<'_> {
drop(proc);
let begin_time_ms = crate::trap::uptime_msec();
Condvar::wait_events(condvars.as_slice(), move || {
Condvar::wait_events(condvars.as_slice(), move || {
use PollEvents as PE;
let proc = self.process();
let mut events = 0;
@ -211,9 +211,9 @@ impl Syscall<'_> {
let proc = self.process();
let mut events = 0;
for (&fd, file_like) in proc.files.iter() {
// if fd >= nfds {
// continue;
// }
// if fd >= nfds {
// continue;
// }
if !err_fds.contains(fd) && !read_fds.contains(fd) && !write_fds.contains(fd) {
continue;
}
@ -256,24 +256,16 @@ impl Syscall<'_> {
})
}
pub fn sys_epoll_create(
&mut self,
size: usize,
) -> SysResult {
pub fn sys_epoll_create(&mut self, size: usize) -> SysResult {
info!("epoll_create: size: {:?}", size);
if (size as i32) < 0 {
return Err(SysError::EINVAL);
}
self.sys_epoll_create1(0)
}
pub fn sys_epoll_create1(
&mut self,
flags: usize,
) -> SysResult {
pub fn sys_epoll_create1(&mut self, flags: usize) -> SysResult {
info!("epoll_create1: flags: {:?}", flags);
let mut proc = self.process();
let epollInstance = EpollInstance::new(flags);
@ -288,7 +280,6 @@ impl Syscall<'_> {
fd: usize,
event: *mut EpollEvent,
) -> SysResult {
let mut proc = self.process();
if !proc.pid.is_init() {
// we trust pid 0 process
@ -297,7 +288,7 @@ impl Syscall<'_> {
let _event = unsafe { self.vm().check_read_ptr(event)? };
if proc.files.get(&fd).is_none(){
if proc.files.get(&fd).is_none() {
return Err(SysError::EPERM);
}
@ -308,7 +299,7 @@ impl Syscall<'_> {
}
};
let ret = epollInstance.control(op, fd, & _event)?;
let ret = epollInstance.control(op, fd, &_event)?;
return Ok(ret);
}
@ -333,23 +324,26 @@ impl Syscall<'_> {
info!("epoll_pwait: epfd: {}, timeout: {:?}", epfd, timeout_msecs);
let mut proc = self.process();
let events = unsafe { self.vm().check_write_array(events, maxevents)? };
let events = unsafe { self.vm().check_write_array(events, maxevents)? };
let epollInstance = proc.get_epoll_instance(epfd)?;
// add new fds which are registered by epoll_ctl after latest epoll_pwait
epollInstance.readyList.lock().clear();
epollInstance.readyList.lock().extend(epollInstance.newCtlList.lock().clone());
epollInstance
.readyList
.lock()
.extend(epollInstance.newCtlList.lock().clone());
epollInstance.newCtlList.lock().clear();
// if registered fd has data to handle and its mode isn't epollet, we need
// to add it to the list.
let keys: Vec<_> = epollInstance.events.keys().cloned().collect();
for (k, v) in epollInstance.events.iter(){
for (k, v) in epollInstance.events.iter() {
if !v.contains(EpollEvent::EPOLLET) {
match &proc.files.get(k) {
None => {
// return Err(SysError::EINVAL);
},
// return Err(SysError::EINVAL);
}
Some(file_like) => {
let status = file_like.poll()?;
if status.write || status.read || status.error {
@ -362,29 +356,36 @@ impl Syscall<'_> {
}
drop(proc);
let mut callbacks = alloc::vec![];
for fd in &keys {
let mut proc = self.process();
match proc.files.get(&fd){
match proc.files.get(&fd) {
Some(file_like) => {
match file_like{
match file_like {
FileLike::File(file) => {
&crate::fs::STDIN.pushed.register_epoll_list(self.thread.proc.clone(),
thread::current().id(), epfd, *fd);
callbacks.push((0, thread::current().id(), epfd, *fd));
},
&crate::fs::STDIN.pushed.register_epoll_list(
self.thread.proc.clone(),
thread::current().id(),
epfd,
*fd,
);
callbacks.push((0, thread::current().id(), epfd, *fd));
}
FileLike::Socket(socket) => {
&(*crate::drivers::SOCKET_ACTIVITY).register_epoll_list(self.thread.proc.clone(),
thread::current().id(), epfd, *fd);
callbacks.push((1, thread::current().id(), epfd, *fd));
},
&(*crate::drivers::SOCKET_ACTIVITY).register_epoll_list(
self.thread.proc.clone(),
thread::current().id(),
epfd,
*fd,
);
callbacks.push((1, thread::current().id(), epfd, *fd));
}
FileLike::EpollInstance(instance) => {
return Err(SysError::EINVAL);
}
};
},
None => {},
}
None => {}
}
drop(proc);
}
@ -449,7 +450,7 @@ impl Syscall<'_> {
}
{
let epollInstance = match proc.get_epoll_instance_mut(epfd) {
let epollInstance = match proc.get_epoll_instance_mut(epfd) {
Ok(ins) => ins,
Err(err) => {
return Some(Err(err));
@ -475,9 +476,11 @@ impl Syscall<'_> {
let num = Condvar::wait_events(condvars.as_slice(), condition).unwrap();
for cb in callbacks.iter(){
for cb in callbacks.iter() {
match cb.0 {
0 => &crate::fs::STDIN.pushed.unregister_epoll_list(cb.1, cb.2, cb.3),
0 => &crate::fs::STDIN
.pushed
.unregister_epoll_list(cb.1, cb.2, cb.3),
1 => &(*crate::drivers::SOCKET_ACTIVITY).unregister_epoll_list(cb.1, cb.2, cb.3),
_ => panic!("cb error"),
};
@ -1775,8 +1778,5 @@ impl FdSet {
}
}
/// Pathname is interpreted relative to the current working directory(CWD)
const AT_FDCWD: usize = -100isize as usize;

View File

@ -10,12 +10,12 @@ use rcore_memory::VMError;
use crate::arch::cpu;
use crate::arch::interrupt::TrapFrame;
use crate::arch::syscall::*;
use crate::fs::epoll::EpollEvent;
use crate::memory::{copy_from_user, MemorySet};
use crate::process::*;
use crate::sync::{Condvar, MutexGuard, SpinNoIrq};
use crate::thread;
use crate::util;
use crate::fs::epoll::EpollEvent;
pub use self::custom::*;
pub use self::fs::*;
@ -166,11 +166,18 @@ impl Syscall<'_> {
SYS_PPOLL => {
self.sys_ppoll(args[0] as *mut PollFd, args[1], args[2] as *const TimeSpec)
} // ignore sigmask
SYS_EPOLL_CREATE1 => self.sys_epoll_create1(args[0]),
SYS_EPOLL_CTL => self.sys_epoll_ctl(args[0], args[1], args[2], args[3] as *mut EpollEvent),
SYS_EPOLL_PWAIT => self.sys_epoll_pwait(args[0], args[1] as *mut EpollEvent,
args[2], args[3], args[4]),
SYS_EVENTFD2=> self.unimplemented("eventfd2", Err(SysError::EACCES)),
SYS_EPOLL_CREATE1 => self.sys_epoll_create1(args[0]),
SYS_EPOLL_CTL => {
self.sys_epoll_ctl(args[0], args[1], args[2], args[3] as *mut EpollEvent)
}
SYS_EPOLL_PWAIT => self.sys_epoll_pwait(
args[0],
args[1] as *mut EpollEvent,
args[2],
args[3],
args[4],
),
SYS_EVENTFD2 => self.unimplemented("eventfd2", Err(SysError::EACCES)),
SYS_SOCKETPAIR => self.unimplemented("socketpair", Err(SysError::EACCES)),
// file system
@ -429,7 +436,9 @@ impl Syscall<'_> {
_ => return None,
},
SYS_EPOLL_CREATE => self.sys_epoll_create(args[0]),
SYS_EPOLL_WAIT =>self.sys_epoll_wait(args[0], args[1] as *mut EpollEvent, args[2], args[3]),
SYS_EPOLL_WAIT => {
self.sys_epoll_wait(args[0], args[1] as *mut EpollEvent, args[2], args[3])
}
_ => return None,
};
@ -467,7 +476,9 @@ impl Syscall<'_> {
SYS_ARCH_PRCTL => self.sys_arch_prctl(args[0] as i32, args[1]),
SYS_TIME => self.sys_time(args[0] as *mut u64),
SYS_EPOLL_CREATE => self.sys_epoll_create(args[0]),
SYS_EPOLL_WAIT =>self.sys_epoll_wait(args[0], args[1] as *mut EpollEvent, args[2], args[3]),
SYS_EPOLL_WAIT => {
self.sys_epoll_wait(args[0], args[1] as *mut EpollEvent, args[2], args[3])
}
_ => return None,
};
Some(ret)

View File

@ -1,9 +1,9 @@
use crate::arch::cpu;
use crate::arch::interrupt::TrapFrame;
use crate::process::*;
use log::*;
use crate::sync::Condvar;
use crate::consts::INFORM_PER_MSEC;
use crate::process::*;
use crate::sync::Condvar;
use log::*;
pub static mut TICK: usize = 0;
@ -11,7 +11,6 @@ lazy_static! {
pub static ref TICK_ACTIVITY: Condvar = Condvar::new();
}
pub fn uptime_msec() -> usize {
unsafe { crate::trap::TICK * crate::consts::USEC_PER_TICK / 1000 }
}
@ -20,7 +19,7 @@ pub fn timer() {
if cpu::id() == 0 {
unsafe {
TICK += 1;
if uptime_msec() % INFORM_PER_MSEC == 0 {
if uptime_msec() % INFORM_PER_MSEC == 0 {
TICK_ACTIVITY.notify_all();
}
}

2
user

@ -1 +1 @@
Subproject commit 3ae3a840bf39bbd6628892842688c8720273546d
Subproject commit 653effaf38bfecedf38eba350ac8a589b80ea2d3