about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFrank Rehwinkel <frankrehwinkel@gmail.com>2024-10-03 16:07:40 -0400
committerFrank Rehwinkel <frankrehwinkel@gmail.com>2024-10-09 15:56:38 -0400
commit2675f14bef6464eeb107c8a30deec5bdf4ef7b75 (patch)
tree9b8f9cf9edba714e6acd0bb55006d8858a257f4e /src
parentf04d1f64e27dd16c773c0ff353cc825e08f3a8a2 (diff)
downloadrust-2675f14bef6464eeb107c8a30deec5bdf4ef7b75.tar.gz
rust-2675f14bef6464eeb107c8a30deec5bdf4ef7b75.zip
syscall/eventfd2: add support
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/src/shims/unix/linux/foreign_items.rs12
-rw-r--r--src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.rs14
-rw-r--r--src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.stderr15
-rw-r--r--src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs9
4 files changed, 21 insertions, 29 deletions
diff --git a/src/tools/miri/src/shims/unix/linux/foreign_items.rs b/src/tools/miri/src/shims/unix/linux/foreign_items.rs
index 3722cc2f3ca..2a72004378e 100644
--- a/src/tools/miri/src/shims/unix/linux/foreign_items.rs
+++ b/src/tools/miri/src/shims/unix/linux/foreign_items.rs
@@ -122,6 +122,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
 
                 let sys_getrandom = this.eval_libc("SYS_getrandom").to_target_usize(this)?;
                 let sys_futex = this.eval_libc("SYS_futex").to_target_usize(this)?;
+                let sys_eventfd2 = this.eval_libc("SYS_eventfd2").to_target_usize(this)?;
 
                 if args.is_empty() {
                     throw_ub_format!(
@@ -155,6 +156,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
                     id if id == sys_futex => {
                         futex(this, &args[1..], dest)?;
                     }
+                    id if id == sys_eventfd2 => {
+                        let [_, initval, flags, ..] = args else {
+                            throw_ub_format!(
+                                "incorrect number of arguments for `eventfd2` syscall: got {}, expected at least 3",
+                                args.len()
+                            );
+                        };
+
+                        let result = this.eventfd(initval, flags)?;
+                        this.write_int(result.to_i32()?, dest)?;
+                    }
                     id => {
                         this.handle_unsupported_foreign_item(format!(
                             "can't execute syscall with ID {id}"
diff --git a/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.rs b/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.rs
deleted file mode 100644
index fc5a6b37cc0..00000000000
--- a/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-//@only-target: linux
-
-// This is a test for calling eventfd2 through a syscall.
-// But we do not support this.
-fn main() {
-    let initval = 0 as libc::c_uint;
-    let flags = (libc::EFD_CLOEXEC | libc::EFD_NONBLOCK) as libc::c_int;
-
-    let result = unsafe {
-        libc::syscall(libc::SYS_eventfd2, initval, flags) //~ERROR: unsupported operation
-    };
-
-    assert_eq!(result, 3); // The first FD provided would be 3.
-}
diff --git a/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.stderr b/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.stderr
deleted file mode 100644
index d39cea564d6..00000000000
--- a/src/tools/miri/tests/fail-dep/libc/libc_syscall_eventfd2.stderr
+++ /dev/null
@@ -1,15 +0,0 @@
-error: unsupported operation: can't execute syscall with ID 290
-  --> tests/fail-dep/libc/libc_syscall_eventfd2.rs:LL:CC
-   |
-LL |         libc::syscall(libc::SYS_eventfd2, initval, flags)
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't execute syscall with ID 290
-   |
-   = help: if this is a basic API commonly used on this target, please report an issue with Miri
-   = help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
-   = note: BACKTRACE:
-   = note: inside `main` at tests/fail-dep/libc/libc_syscall_eventfd2.rs:LL:CC
-
-note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
-
-error: aborting due to 1 previous error
-
diff --git a/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs
index 1d084194658..c92d9c3fe70 100644
--- a/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs
+++ b/src/tools/miri/tests/pass-dep/libc/libc-eventfd.rs
@@ -10,6 +10,7 @@ use std::thread;
 fn main() {
     test_read_write();
     test_race();
+    test_syscall();
 }
 
 fn read_bytes<const N: usize>(fd: i32, buf: &mut [u8; N]) -> i32 {
@@ -109,3 +110,11 @@ fn test_race() {
     thread::yield_now();
     thread1.join().unwrap();
 }
+
+// This is a test for calling eventfd2 through a syscall.
+fn test_syscall() {
+    let initval = 0 as libc::c_uint;
+    let flags = (libc::EFD_CLOEXEC | libc::EFD_NONBLOCK) as libc::c_int;
+    let fd = unsafe { libc::syscall(libc::SYS_eventfd2, initval, flags) };
+    assert_ne!(fd, -1);
+}