Skip to content

Commit

Permalink
WIP implement shim for epoll_ctl
Browse files Browse the repository at this point in the history
  • Loading branch information
DebugSteven committed Jul 18, 2022
1 parent 358aa7d commit f5cb51d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let result = this.epoll_create1(flag)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"epoll_ctl" => {
let [epfd, op, fd, event] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let result = this.epoll_ctl(epfd, op, fd, event)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"eventfd" => {
let [initval, flag] = this.check_shim(abi, Abi::C {unwind: false }, link_name, args)?;
let result = this.eventfd(initval, flag)?;
Expand Down
33 changes: 33 additions & 0 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,39 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(fd)
}

fn epoll_ctl(
&mut self,
_epfd: &OpTy<'tcx, Tag>,
op: &OpTy<'tcx, Tag>,
fd: &OpTy<'tcx, Tag>,
_event: &OpTy<'tcx, Tag>,
) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();

let values = this.read_scalar(op)?.to_i32()?;
let fd = this.read_scalar(fd)?.to_i32()?;

let epoll_ctl_add = this.eval_libc_i32("EPOLL_CTL_ADD")?;
let epoll_ctl_mod = this.eval_libc_i32("EPOLL_CTL_MOD")?;
let epoll_ctl_del = this.eval_libc_i32("EPOLL_CTL_DEL")?;

if values == epoll_ctl_add {
if let Some(_file_descriptor) = this.machine.file_handler.handles.get(&fd) {
return Ok(-1);
} else {
return this.handle_not_found();
}
} else if values == epoll_ctl_mod {
} else if values == epoll_ctl_del {
} else {
let einval = this.eval_libc("EINVAL")?;
this.set_last_error(einval)?;
return Ok(-1);
}

Ok(0)
}

fn eventfd(
&mut self,
_initval: &OpTy<'tcx, Tag>,
Expand Down

0 comments on commit f5cb51d

Please sign in to comment.