Skip to content

Commit 146a8a9

Browse files
committed
WIP implement shim for epoll_ctl
1 parent abaa446 commit 146a8a9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/shims/unix/foreign_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6565
let result = this.epoll_create1(flag)?;
6666
this.write_scalar(Scalar::from_i32(result), dest)?;
6767
}
68+
"epoll_ctl" => {
69+
let [epfd, op, fd, event] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
70+
let result = this.epoll_ctl(epfd, op, fd, event)?;
71+
this.write_scalar(Scalar::from_i32(result), dest)?;
72+
}
6873
"eventfd" => {
6974
let [initval, flag] = this.check_shim(abi, Abi::C {unwind: false }, link_name, args)?;
7075
let result = this.eventfd(initval, flag)?;

src/shims/unix/fs.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,39 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
778778
Ok(fd)
779779
}
780780

781+
fn epoll_ctl(
782+
&mut self,
783+
_epfd: &OpTy<'tcx, Tag>,
784+
op: &OpTy<'tcx, Tag>,
785+
fd: &OpTy<'tcx, Tag>,
786+
_event: &OpTy<'tcx, Tag>,
787+
) -> InterpResult<'tcx, i32> {
788+
let this = self.eval_context_mut();
789+
790+
let values = this.read_scalar(op)?.to_i32()?;
791+
let fd = this.read_scalar(fd)?.to_i32()?;
792+
793+
let epoll_ctl_add = this.eval_libc_i32("EPOLL_CTL_ADD")?;
794+
let epoll_ctl_mod = this.eval_libc_i32("EPOLL_CTL_MOD")?;
795+
let epoll_ctl_del = this.eval_libc_i32("EPOLL_CTL_DEL")?;
796+
797+
if values == epoll_ctl_add {
798+
if let Some(_file_descriptor) = this.machine.file_handler.handles.get(&fd) {
799+
return Ok(-1);
800+
} else {
801+
return this.handle_not_found();
802+
}
803+
} else if values == epoll_ctl_mod {
804+
} else if values == epoll_ctl_del {
805+
} else {
806+
let einval = this.eval_libc("EINVAL")?;
807+
this.set_last_error(einval)?;
808+
return Ok(-1);
809+
}
810+
811+
Ok(0)
812+
}
813+
781814
fn eventfd(
782815
&mut self,
783816
_initval: &OpTy<'tcx, Tag>,

0 commit comments

Comments
 (0)