Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illumos: Added epoll and eventfd #4136

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use rustc_span::Symbol;
use rustc_target::callconv::{Conv, FnAbi};

use crate::shims::unix::foreign_items::EvalContextExt as _;
use crate::shims::unix::linux_like::epoll::EvalContextExt as _;
use crate::shims::unix::linux_like::eventfd::EvalContextExt as _;
use crate::shims::unix::*;
use crate::*;

Expand All @@ -21,6 +23,32 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx, EmulateItemResult> {
let this = self.eval_context_mut();
match link_name.as_str() {
// epoll, eventfd (NOT available on Solaris!)
"epoll_create1" => {
this.assert_target_os("illumos", "epoll_create1");
let [flag] = this.check_shim(abi, Conv::C, link_name, args)?;
let result = this.epoll_create1(flag)?;
this.write_scalar(result, dest)?;
}
"epoll_ctl" => {
this.assert_target_os("illumos", "epoll_ctl");
let [epfd, op, fd, event] = this.check_shim(abi, Conv::C, link_name, args)?;
let result = this.epoll_ctl(epfd, op, fd, event)?;
this.write_scalar(result, dest)?;
}
"epoll_wait" => {
this.assert_target_os("illumos", "epoll_wait");
let [epfd, events, maxevents, timeout] =
this.check_shim(abi, Conv::C, link_name, args)?;
this.epoll_wait(epfd, events, maxevents, timeout, dest)?;
}
"eventfd" => {
this.assert_target_os("illumos", "eventfd");
let [val, flag] = this.check_shim(abi, Conv::C, link_name, args)?;
let result = this.eventfd(val, flag)?;
this.write_scalar(result, dest)?;
}

// Threading
"pthread_setname_np" => {
let [thread, name] = this.check_shim(abi, Conv::C, link_name, args)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/fail-dep/libc/eventfd_block_read_twice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos
//~^ERROR: deadlocked
//~^^ERROR: deadlocked
//@compile-flags: -Zmiri-preemption-rate=0
Expand Down
2 changes: 1 addition & 1 deletion tests/fail-dep/libc/eventfd_block_write_twice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos
//~^ERROR: deadlocked
//~^^ERROR: deadlocked
//@compile-flags: -Zmiri-preemption-rate=0
Expand Down
2 changes: 1 addition & 1 deletion tests/fail-dep/libc/libc-epoll-data-race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! and we only read one of them, we do not synchronize with the other events
//! and therefore still report a data race for things that need to see the second event
//! to be considered synchronized.
//@only-target: linux android
//@only-target: linux android illumos
// ensure deterministic schedule
//@compile-flags: -Zmiri-preemption-rate=0

Expand Down
2 changes: 1 addition & 1 deletion tests/fail-dep/libc/libc_epoll_block_two_thread.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@compile-flags: -Zmiri-preemption-rate=0
//~^ERROR: deadlocked
//~^^ERROR: deadlocked
//@only-target: linux
//@only-target: linux android illumos
//@error-in-other-file: deadlock

use std::convert::TryInto;
Expand Down
2 changes: 1 addition & 1 deletion tests/fail-dep/libc/libc_epoll_unsupported_fd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos

// This is a test for registering unsupported fd with epoll.
// Register epoll fd with epoll is allowed in real system, but we do not support this.
Expand Down
2 changes: 1 addition & 1 deletion tests/pass-dep/libc/libc-epoll-blocking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos
// test_epoll_block_then_unblock and test_epoll_race depend on a deterministic schedule.
//@compile-flags: -Zmiri-preemption-rate=0

Expand Down
2 changes: 1 addition & 1 deletion tests/pass-dep/libc/libc-epoll-no-blocking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos

use std::convert::TryInto;

Expand Down
7 changes: 6 additions & 1 deletion tests/pass-dep/libc/libc-eventfd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@only-target: linux android
//@only-target: linux android illumos
// test_race, test_blocking_read and test_blocking_write depend on a deterministic schedule.
//@compile-flags: -Zmiri-preemption-rate=0

Expand All @@ -10,7 +10,10 @@ use std::thread;
fn main() {
test_read_write();
test_race();

#[cfg(not(target_os = "illumos"))]
test_syscall();

test_blocking_read();
test_blocking_write();
test_two_threads_blocked_on_eventfd();
Expand Down Expand Up @@ -115,6 +118,8 @@ fn test_race() {
}

// This is a test for calling eventfd2 through a syscall.
// Illumos supports eventfd, but it has no entry to call it through syscall.
#[cfg(not(target_os = "illumos"))]
fn test_syscall() {
let initval = 0 as libc::c_uint;
let flags = (libc::EFD_CLOEXEC | libc::EFD_NONBLOCK) as libc::c_int;
Expand Down
Loading