From 05b532a4a48cc92e8e7b0e3cf4892dd171d89907 Mon Sep 17 00:00:00 2001 From: Mohanson Date: Tue, 5 Mar 2024 16:41:59 +0800 Subject: [PATCH] Implement close (#4) --- script/src/v2_scheduler.rs | 10 ++++++++++ script/src/v2_syscalls.rs | 8 ++++++-- script/src/v2_types.rs | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/script/src/v2_scheduler.rs b/script/src/v2_scheduler.rs index 631c83e385..5f768ff99d 100644 --- a/script/src/v2_scheduler.rs +++ b/script/src/v2_scheduler.rs @@ -492,6 +492,16 @@ impl { + self.ensure_vms_instantiated(&[vm_id])?; + let (_, machine) = self.instantiated.get_mut(&vm_id).unwrap(); + if self.pipes.get(&fd) != Some(&vm_id) { + machine.machine.set_register(A0, INVALID_PIPE as u64); + } else { + self.pipes.remove(&fd); + machine.machine.set_register(A0, SUCCESS as u64); + } + } } } Ok(()) diff --git a/script/src/v2_syscalls.rs b/script/src/v2_syscalls.rs index cff7a0722d..6b70e70b0c 100644 --- a/script/src/v2_syscalls.rs +++ b/script/src/v2_syscalls.rs @@ -474,8 +474,12 @@ impl(&mut self, machine: &mut Mac) -> Result<(), Error> { - // TODO - unimplemented!() + let pipe = PipeId(machine.registers()[A0].to_u64()); + self.message_box + .lock() + .expect("lock") + .push(Message::Close(self.id, pipe)); + Err(Error::External("YIELD".to_string())) } } diff --git a/script/src/v2_types.rs b/script/src/v2_types.rs index 1e48eb2319..1f7967371d 100644 --- a/script/src/v2_types.rs +++ b/script/src/v2_types.rs @@ -100,6 +100,7 @@ pub enum Message { PipeRead(VmId, PipeIoArgs), PipeWrite(VmId, PipeIoArgs), InheritedFileDescriptor(VmId, PipeIoArgs), + Close(VmId, PipeId), } #[derive(Clone, Debug, PartialEq, Eq, Hash)]