From ef010b44b77807f8dc56798dee0c66739522564b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 18 Oct 2019 08:44:17 -0700 Subject: [PATCH] Fix nondeterminism in the preopen order. We iterate over the preopens to present them to the WASI program, so storing them in a `HashMap` means this order is nondeterministic. Switch to a `Vec` of tuples instead. This means we don't eliminate duplicates, but they should be rare. --- src/ctx.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ctx.rs b/src/ctx.rs index 434dcedf2c..c56ee1f6ea 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -11,7 +11,7 @@ use std::path::{Path, PathBuf}; /// A builder allowing customizable construction of `WasiCtx` instances. pub struct WasiCtxBuilder { fds: HashMap, - preopens: HashMap, + preopens: Vec<(PathBuf, File)>, args: Vec, env: HashMap, } @@ -21,7 +21,7 @@ impl WasiCtxBuilder { pub fn new() -> Result { let mut builder = Self { fds: HashMap::new(), - preopens: HashMap::new(), + preopens: Vec::new(), args: vec![], env: HashMap::new(), }; @@ -98,7 +98,7 @@ impl WasiCtxBuilder { /// Add a preopened directory. pub fn preopened_dir>(mut self, dir: File, guest_path: P) -> Self { - self.preopens.insert(guest_path.as_ref().to_owned(), dir); + self.preopens.push((guest_path.as_ref().to_owned(), dir)); self }