diff --git a/src/main.rs b/src/main.rs index 2b85fb6..e4063e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use parking_lot::RwLock; struct Serv { fs_map: RwLock>, mount_list: RwLock>, + process_stdio: RwLock; 3]>>, } impl vfs_rpc::Server for Serv { @@ -61,12 +62,23 @@ impl vfs_rpc::Server for Serv { Ok(()) } } + + fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()> { + self.process_stdio.write().insert(pid, stdio); + Ok(()) + } + + fn get_stdio(&self, from: u64) -> [Option<(u64, u64)>; 3] { + let stdio = self.process_stdio.read().get(&from).copied().unwrap_or([None; 3]); + stdio + } } fn main() { vfs_rpc::register_server(Box::new(Serv { fs_map: RwLock::new(HashMap::new()), mount_list: RwLock::new(HashMap::new()), + process_stdio: RwLock::new(HashMap::new()), })); syscalls::register(0); loop { diff --git a/vfs_rpc/src/lib.rs b/vfs_rpc/src/lib.rs index 1eb3b76..408d64e 100644 --- a/vfs_rpc/src/lib.rs +++ b/vfs_rpc/src/lib.rs @@ -16,6 +16,8 @@ pub trait Server: Send + Sync { fn mount(&self, dev: &Path, kind: &str, path: &Path) -> Result<(), ()>; fn open(&self, path: &Path) -> Result<(u64, u64), ()>; fn unmount(&self, path: &Path) -> Result<(), ()>; + fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()>; + fn get_stdio(&self, from: u64) -> [Option<(u64, u64)>; 3]; } #[derive(Copy, Clone)] @@ -65,6 +67,32 @@ impl Client { ) .unwrap() } + + pub fn set_stdio(&self, pid: u64, stdio: [Option<(u64, u64)>; 3]) -> Result<(), ()> { + postcard::from_bytes( + &rpc::send_call( + self.0, + PROTO, + 4, + &postcard::to_stdvec(&(pid, stdio)).unwrap(), + ) + .get_return(), + ) + .unwrap() + } + + pub fn get_stdio(&self) -> [Option<(u64, u64)>; 3] { + postcard::from_bytes( + &rpc::send_call( + self.0, + PROTO, + 5, + &[], + ) + .get_return(), + ) + .unwrap() + } } pub fn register_server(server: Box) { @@ -96,5 +124,12 @@ fn callback(call: IncomingCall) { let path = postcard::from_bytes(call.args()).unwrap(); let ret = postcard::to_stdvec(&server.unmount(path)).unwrap(); call.send_return(&ret); + } else if call.func == 4 { + let (pid, stdio) = postcard::from_bytes(call.args()).unwrap(); + let ret = postcard::to_stdvec(&server.set_stdio(pid, stdio)).unwrap(); + call.send_return(&ret); + } else if call.func == 5 { + let ret = postcard::to_stdvec(&server.get_stdio(call.from)).unwrap(); + call.send_return(&ret); } }