Skip to content

Commit

Permalink
Implement close
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Mar 5, 2024
1 parent 8bc4175 commit a005407
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions script/src/v2_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
.store64(&length_addr, &actual_length)?;
machine.machine.set_register(A0, SUCCESS as u64);
}
Message::Close(vm_id, fd) => {
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(())
Expand Down
8 changes: 6 additions & 2 deletions script/src/v2_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,12 @@ impl<DL: CellDataProvider + HeaderProvider + ExtensionProvider + Send + Sync + C
}

fn close<Mac: SupportMachine>(&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()))
}
}

Expand Down
1 change: 1 addition & 0 deletions script/src/v2_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit a005407

Please sign in to comment.