Skip to content

Commit 133c2b3

Browse files
committed
Only use getcwd without isolation
1 parent 6593563 commit 133c2b3

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/shims/env.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
119119
size_op: OpTy<'tcx, Tag>,
120120
) -> InterpResult<'tcx, Scalar<Tag>> {
121121
let this = self.eval_context_mut();
122-
let tcx = &{this.tcx.tcx};
123122

124-
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
125-
let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
126-
// If we cannot get the current directory, we return null
127-
if let Ok(cwd) = env::current_dir() {
128-
// It is not clear what happens with non-utf8 paths here
129-
let mut bytes = cwd.display().to_string().into_bytes();
130-
// If the buffer is smaller than the path, we return null
131-
if bytes.len() as u64 <= size {
132-
// We need `size` bytes exactly
133-
bytes.resize(size as usize, 0);
134-
this.memory_mut().get_mut(buf.alloc_id)?.write_bytes(tcx, buf, &bytes)?;
135-
return Ok(Scalar::Ptr(buf))
123+
if this.machine.communicate {
124+
let tcx = &{this.tcx.tcx};
125+
126+
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
127+
let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
128+
// If we cannot get the current directory, we return null
129+
if let Ok(cwd) = env::current_dir() {
130+
// It is not clear what happens with non-utf8 paths here
131+
let mut bytes = cwd.display().to_string().into_bytes();
132+
// If the buffer is smaller than the path, we return null
133+
if bytes.len() as u64 <= size {
134+
// We need `size` bytes exactly
135+
bytes.resize(size as usize, 0);
136+
this.memory_mut().get_mut(buf.alloc_id)?.write_bytes(tcx, buf, &bytes)?;
137+
return Ok(Scalar::Ptr(buf))
138+
}
136139
}
140+
return Ok(Scalar::ptr_null(&*this.tcx));
137141
}
138-
Ok(Scalar::ptr_null(&*this.tcx))
142+
throw_unsup_format!("Function not available when isolation is enabled")
139143
}
140144
}

tests/run-pass/get_current_dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-windows: TODO the windows hook is not done yet
2+
// compile-flags: -Zmiri-disable-isolation
23

34
fn main() {
45
std::env::current_dir().unwrap();

0 commit comments

Comments
 (0)