use virtual stdio

which works except for the lifetime issues, i think the trap still holds
an Rc to the store?
This commit is contained in:
Pat Hickey
2020-12-11 18:22:13 -08:00
parent 0572b40f58
commit 1b8f9fd377
2 changed files with 86 additions and 47 deletions

View File

@@ -69,31 +69,48 @@ impl WasiCtxBuilder {
pub fn build(self) -> Result<WasiCtx, Error> {
Ok(self.0)
}
pub fn arg(&mut self, arg: &str) -> Result<&mut Self, StringArrayError> {
self.0.args.push(arg.to_owned())?;
Ok(self)
}
pub fn inherit_stdio(&mut self) -> &mut Self {
pub fn stdin(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
self.0.insert_file(
0,
Box::new(crate::stdio::stdin()),
FileCaps::READ,
f,
FileCaps::READ, // XXX probably more rights are ok
FileCaps::READ,
);
self
}
pub fn stdout(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
self.0.insert_file(
1,
Box::new(crate::stdio::stdout()),
FileCaps::WRITE,
FileCaps::WRITE,
);
self.0.insert_file(
2,
Box::new(crate::stdio::stderr()),
FileCaps::WRITE,
f,
FileCaps::WRITE, // XXX probably more rights are ok
FileCaps::WRITE,
);
self
}
pub fn stderr(&mut self, f: Box<dyn WasiFile>) -> &mut Self {
self.0.insert_file(
2,
f,
FileCaps::WRITE, // XXX probably more rights are ok
FileCaps::WRITE,
);
self
}
pub fn inherit_stdio(&mut self) -> &mut Self {
self.stdin(Box::new(crate::stdio::stdin()))
.stdout(Box::new(crate::stdio::stdout()))
.stderr(Box::new(crate::stdio::stderr()))
}
pub fn preopened_dir(
&mut self,
dir: Box<dyn WasiDir>,