Skip to content

Commit a1fc187

Browse files
committed
Refactor: directly write to MPlaceTy inside fn epoll_wait
1 parent 61c5206 commit a1fc187

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/shims/unix/linux/epoll.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
378378
events_op: &OpTy<'tcx>,
379379
maxevents: &OpTy<'tcx>,
380380
timeout: &OpTy<'tcx>,
381-
) -> InterpResult<'tcx, Scalar> {
381+
place: &MPlaceTy<'tcx>,
382+
) -> InterpResult<'tcx> {
382383
let this = self.eval_context_mut();
383384

384385
let epfd = this.read_scalar(epfd)?.to_i32()?;
@@ -392,15 +393,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
392393
if epfd <= 0 {
393394
let einval = this.eval_libc("EINVAL");
394395
this.set_last_error(einval)?;
395-
return Ok(Scalar::from_i32(-1));
396+
this.write_scalar(Scalar::from_i32(-1), place)?;
397+
return Ok(());
396398
}
397399
// FIXME: Implement blocking support
398400
if timeout != 0 {
399401
throw_unsup_format!("epoll_wait: timeout value can only be 0");
400402
}
401403

402404
let Some(epfd) = this.machine.fds.get_ref(epfd) else {
403-
return Ok(Scalar::from_i32(this.fd_not_found()?));
405+
let result_value = this.fd_not_found()?;
406+
this.write_scalar(Scalar::from_i32(result_value), place)?;
407+
return Ok(());
404408
};
405409
let mut binding = epfd.borrow_mut();
406410
let epoll_file_description = &mut binding
@@ -431,7 +435,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
431435
}
432436
}
433437
}
434-
Ok(Scalar::from_i32(num_of_events))
438+
this.write_scalar(Scalar::from_i32(num_of_events), place)?;
439+
Ok(())
435440
}
436441
/// For a specific unique file descriptor id, get its ready events and update
437442
/// the corresponding ready list. This function is called whenever a file description

src/shims/unix/linux/foreign_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6262
"epoll_wait" => {
6363
let [epfd, events, maxevents, timeout] =
6464
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
65-
let result = this.epoll_wait(epfd, events, maxevents, timeout)?;
66-
this.write_scalar(result, dest)?;
65+
this.epoll_wait(epfd, events, maxevents, timeout, dest)?;
6766
}
6867
"eventfd" => {
6968
let [val, flag] =

0 commit comments

Comments
 (0)