Skip to content

Commit

Permalink
Added epoll and eventfd for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Nov 25, 2024
1 parent 1c6bfbb commit da77926
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ case $HOST_TARGET in
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random threadname pthread fs libc-pipe
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random sync threadname pthread
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random sync threadname pthread epoll eventfd
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
Expand Down
27 changes: 27 additions & 0 deletions src/shims/unix/android/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol;

use self::shims::unix::linux::epoll::EvalContextExt as _;
use self::shims::unix::linux::eventfd::EvalContextExt as _;
use crate::shims::unix::android::thread::prctl;
use crate::shims::unix::linux::syscall::syscall;
use crate::*;
Expand All @@ -20,6 +22,31 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx, EmulateItemResult> {
let this = self.eval_context_mut();
match link_name.as_str() {
// epoll, eventfd
"epoll_create1" => {
let [flag] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.epoll_create1(flag)?;
this.write_scalar(result, dest)?;
}
"epoll_ctl" => {
let [epfd, op, fd, event] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.epoll_ctl(epfd, op, fd, event)?;
this.write_scalar(result, dest)?;
}
"epoll_wait" => {
let [epfd, events, maxevents, timeout] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.epoll_wait(epfd, events, maxevents, timeout, dest)?;
}
"eventfd" => {
let [val, flag] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.eventfd(val, flag)?;
this.write_scalar(result, dest)?;
}

// Miscellaneous
"__errno" => {
let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
Expand Down
3 changes: 0 additions & 3 deletions src/shims/unix/linux/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn eventfd(&mut self, val: &OpTy<'tcx>, flags: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

// eventfd is Linux specific.
this.assert_target_os("linux", "eventfd");

let val = this.read_scalar(val)?.to_u32()?;
let mut flags = this.read_scalar(flags)?.to_i32()?;

Expand Down
1 change: 1 addition & 0 deletions tests/fail-dep/libc/libc-epoll-data-race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! and therefore still report a data race for things that need to see the second event
//! to be considered synchronized.
//@only-target: linux
//@only-target: android
// ensure deterministic schedule
//@compile-flags: -Zmiri-preemption-rate=0

Expand Down
1 change: 1 addition & 0 deletions tests/pass-dep/libc/libc-epoll-blocking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@only-target: linux
//@only-target: android
// test_epoll_block_then_unblock and test_epoll_race depend on a deterministic schedule.
//@compile-flags: -Zmiri-preemption-rate=0

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

use std::convert::TryInto;

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

Expand Down

0 comments on commit da77926

Please sign in to comment.