Auto merge of #3836 - tiif:einval_ctl, r=oli-obk
epoll: Add a EINVAL case In ``epoll_ctl`` documentation, it is mentioned that: > EINVAL epfd is not an epoll file descriptor, or fd is the same as epfd, or the requested operation op is not supported by this interface. So I added this EINVAL case for ``epfd == fd`` in ``epoll_ctl``
This commit is contained in:
commit
3a9e63c765
@ -251,6 +251,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
|
|||||||
throw_unsup_format!("epoll_ctl: encountered unknown unsupported operation {:#x}", op);
|
throw_unsup_format!("epoll_ctl: encountered unknown unsupported operation {:#x}", op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throw EINVAL if epfd and fd have the same value.
|
||||||
|
if epfd_value == fd {
|
||||||
|
let einval = this.eval_libc("EINVAL");
|
||||||
|
this.set_last_error(einval)?;
|
||||||
|
return Ok(Scalar::from_i32(-1));
|
||||||
|
}
|
||||||
|
|
||||||
// Check if epfd is a valid epoll file descriptor.
|
// Check if epfd is a valid epoll file descriptor.
|
||||||
let Some(epfd) = this.machine.fds.get(epfd_value) else {
|
let Some(epfd) = this.machine.fds.get(epfd_value) else {
|
||||||
return Ok(Scalar::from_i32(this.fd_not_found()?));
|
return Ok(Scalar::from_i32(this.fd_not_found()?));
|
||||||
|
@ -21,6 +21,7 @@ fn main() {
|
|||||||
test_socketpair_epollerr();
|
test_socketpair_epollerr();
|
||||||
test_epoll_lost_events();
|
test_epoll_lost_events();
|
||||||
test_ready_list_fetching_logic();
|
test_ready_list_fetching_logic();
|
||||||
|
test_epoll_ctl_epfd_equal_fd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using `as` cast since `EPOLLET` wraps around
|
// Using `as` cast since `EPOLLET` wraps around
|
||||||
@ -630,3 +631,16 @@ fn test_ready_list_fetching_logic() {
|
|||||||
let expected_value1 = fd1 as u64;
|
let expected_value1 = fd1 as u64;
|
||||||
check_epoll_wait::<1>(epfd, &[(expected_event1, expected_value1)]);
|
check_epoll_wait::<1>(epfd, &[(expected_event1, expected_value1)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In epoll_ctl, if the value of epfd equals to fd, EINVAL should be returned.
|
||||||
|
fn test_epoll_ctl_epfd_equal_fd() {
|
||||||
|
// Create an epoll instance.
|
||||||
|
let epfd = unsafe { libc::epoll_create1(0) };
|
||||||
|
assert_ne!(epfd, -1);
|
||||||
|
|
||||||
|
let array_ptr = std::ptr::without_provenance_mut::<libc::epoll_event>(0x100);
|
||||||
|
let res = unsafe { libc::epoll_ctl(epfd, libc::EPOLL_CTL_ADD, epfd, array_ptr) };
|
||||||
|
let e = std::io::Error::last_os_error();
|
||||||
|
assert_eq!(e.raw_os_error(), Some(libc::EINVAL));
|
||||||
|
assert_eq!(res, -1);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user