Skip to content

Commit

Permalink
Merge pull request #4016 from YohDeadfall/android-epoll
Browse files Browse the repository at this point in the history
Added epoll and eventfd for Android
  • Loading branch information
RalfJung authored Nov 26, 2024
2 parents 1c6bfbb + 9ed1605 commit 82ed49e
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 22 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
29 changes: 28 additions & 1 deletion src/shims/unix/android/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use rustc_abi::ExternAbi;
use rustc_span::Symbol;

use crate::shims::unix::android::thread::prctl;
use crate::shims::unix::linux::syscall::syscall;
use crate::shims::unix::linux_like::epoll::EvalContextExt as _;
use crate::shims::unix::linux_like::eventfd::EvalContextExt as _;
use crate::shims::unix::linux_like::syscall::syscall;
use crate::*;

pub fn is_dyn_sym(_name: &str) -> bool {
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
2 changes: 1 addition & 1 deletion src/shims/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::rc::{Rc, Weak};
use rustc_abi::Size;

use crate::helpers::check_min_arg_count;
use crate::shims::unix::linux::epoll::EpollReadyEvents;
use crate::shims::unix::linux_like::epoll::EpollReadyEvents;
use crate::shims::unix::*;
use crate::*;

Expand Down
6 changes: 3 additions & 3 deletions src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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 self::shims::unix::linux::mem::EvalContextExt as _;
use self::shims::unix::linux::syscall::syscall;
use self::shims::unix::linux_like::epoll::EvalContextExt as _;
use self::shims::unix::linux_like::eventfd::EvalContextExt as _;
use self::shims::unix::linux_like::syscall::syscall;
use crate::machine::{SIGRTMAX, SIGRTMIN};
use crate::shims::unix::foreign_items::EvalContextExt as _;
use crate::shims::unix::*;
Expand Down
4 changes: 0 additions & 4 deletions src/shims/unix/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
pub mod epoll;
pub mod eventfd;
pub mod foreign_items;
pub mod mem;
pub mod sync;
pub mod syscall;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::ErrorKind;

use crate::concurrency::VClock;
use crate::shims::unix::fd::{FileDescriptionRef, WeakFileDescriptionRef};
use crate::shims::unix::linux::epoll::{EpollReadyEvents, EvalContextExt as _};
use crate::shims::unix::linux_like::epoll::{EpollReadyEvents, EvalContextExt as _};
use crate::shims::unix::*;
use crate::*;

Expand Down 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
4 changes: 4 additions & 0 deletions src/shims/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod epoll;
pub mod eventfd;
pub mod sync;
pub mod syscall;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol;

use self::shims::unix::linux::eventfd::EvalContextExt as _;
use crate::helpers::check_min_arg_count;
use crate::shims::unix::linux::sync::futex;
use crate::shims::unix::linux_like::eventfd::EvalContextExt as _;
use crate::shims::unix::linux_like::sync::futex;
use crate::*;

pub fn syscall<'tcx>(
Expand Down
3 changes: 2 additions & 1 deletion src/shims/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ mod unnamed_socket;
mod android;
mod freebsd;
mod linux;
mod linux_like;
mod macos;
mod solarish;

// All the Unix-specific extension traits
pub use self::env::{EvalContextExt as _, UnixEnvVars};
pub use self::fd::{EvalContextExt as _, FdTable, FileDescription};
pub use self::fs::{DirTable, EvalContextExt as _};
pub use self::linux::epoll::EpollInterestTable;
pub use self::linux_like::epoll::EpollInterestTable;
pub use self::mem::EvalContextExt as _;
pub use self::sync::EvalContextExt as _;
pub use self::thread::{EvalContextExt as _, ThreadNameResult};
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/unnamed_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_abi::Size;

use crate::concurrency::VClock;
use crate::shims::unix::fd::{FileDescriptionRef, WeakFileDescriptionRef};
use crate::shims::unix::linux::epoll::{EpollReadyEvents, EvalContextExt as _};
use crate::shims::unix::linux_like::epoll::{EpollReadyEvents, EvalContextExt as _};
use crate::shims::unix::*;
use crate::*;

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
//@only-target: linux android
// ensure deterministic schedule
//@compile-flags: -Zmiri-preemption-rate=0

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
//@only-target: linux android
// 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
//@only-target: linux android

use std::convert::TryInto;

Expand Down
2 changes: 1 addition & 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
//@only-target: linux 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 82ed49e

Please sign in to comment.