Skip to content

Commit 459c65a

Browse files
committed
Add method to consume io::Error
1 parent 887d748 commit 459c65a

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/shims/env.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
137137
if (bytes.len() as u64) < size {
138138
// We add a `/0` terminator
139139
bytes.push(0);
140-
// This is ok because the buffer is larger than the path with terminatorhe null terminator.
140+
// This is ok because the buffer is larger than the path with the null terminator.
141141
this.memory_mut()
142142
.get_mut(buf.alloc_id)?
143143
.write_bytes(tcx, buf, &bytes)?;
@@ -146,10 +146,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
146146
let erange = this.eval_libc("ERANGE")?;
147147
this.set_last_error(erange)?;
148148
}
149-
Err(e) => this.set_last_error(Scalar::from_int(
150-
e.raw_os_error().unwrap(),
151-
Size::from_bits(32),
152-
))?,
149+
Err(e) => this.consume_io_error(e)?,
153150
}
154151
Ok(Scalar::ptr_null(&*this.tcx))
155152
}
@@ -173,10 +170,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
173170
match env::set_current_dir(path) {
174171
Ok(()) => Ok(0),
175172
Err(e) => {
176-
this.set_last_error(Scalar::from_int(
177-
e.raw_os_error().unwrap(),
178-
Size::from_bits(32),
179-
))?;
173+
this.consume_io_error(e)?;
180174
Ok(-1)
181175
}
182176
}

src/shims/foreign_items.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
987987
self.eval_libc(name).and_then(|scalar| scalar.to_i32())
988988
}
989989

990-
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, ()> {
990+
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
991991
let this = self.eval_context_mut();
992992
let tcx = &{ this.tcx.tcx };
993993
let errno_ptr = this.machine.last_error.unwrap();
@@ -1008,6 +1008,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10081008
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
10091009
.not_undef()
10101010
}
1011+
1012+
fn consume_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
1013+
self.eval_context_mut().set_last_error(Scalar::from_int(
1014+
e.raw_os_error().unwrap(),
1015+
Size::from_bits(32),
1016+
))
1017+
}
10111018
}
10121019

10131020
// Shims the linux 'getrandom()' syscall.

src/shims/io.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
264264
match result {
265265
Ok(ok) => Ok(ok),
266266
Err(e) => {
267-
self.eval_context_mut().set_last_error(Scalar::from_int(
268-
e.raw_os_error().unwrap(),
269-
Size::from_bits(32),
270-
))?;
267+
self.eval_context_mut().consume_io_error(e)?;
271268
Ok((-1).into())
272269
}
273270
}

0 commit comments

Comments
 (0)