From da88121b7e03f1ce9ce145386abeb431b8bc4708 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Sun, 12 Nov 2023 17:55:32 +0800 Subject: [PATCH] feat: eventfd_read/write for Android/FreeBSD/Linux --- libc-test/build.rs | 4 ++++ libc-test/semver/android.txt | 2 ++ libc-test/semver/freebsd.txt | 2 ++ libc-test/semver/linux.txt | 2 ++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 4 ++++ src/unix/linux_like/android/mod.rs | 4 ++++ src/unix/linux_like/linux/mod.rs | 4 ++++ 7 files changed, 22 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 2da88a6dcbce8..85e92ebb34f07 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2417,6 +2417,8 @@ fn test_freebsd(target: &str) { // the struct "__kvm" is quite tricky to bind so since we only use a pointer to it // for now, it doesn't matter too much... "kvm_t" => true, + // `eventfd(2)` and things come with it are added in FreeBSD 13 + "eventfd_t" if Some(13) > freebsd_ver => true, _ => false, } @@ -2494,6 +2496,8 @@ fn test_freebsd(target: &str) { | "aio_readv" | "aio_writev" | "copy_file_range" + | "eventfd_read" + | "eventfd_write" if Some(13) > freebsd_ver => { true diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index bc8f673b15d08..6ab9ec6d49a6a 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -3756,3 +3756,5 @@ write writev dirname basename +eventfd_read +eventfd_write diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 43de5c8ccdb8c..b9fc7a6a5773e 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -2245,3 +2245,5 @@ dirname basename closefrom close_range +eventfd_read +eventfd_write diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 1957a7d657d7c..52127c1d05312 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3611,3 +3611,5 @@ vhangup vmsplice wait4 waitid +eventfd_read +eventfd_write diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index c654ae42ef44a..feaabc5b9b78b 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -48,6 +48,8 @@ pub type cpusetid_t = ::c_int; pub type sctp_assoc_t = u32; +pub type eventfd_t = u64; + #[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))] #[repr(u32)] pub enum devstat_support_flags { @@ -5383,6 +5385,8 @@ extern "C" { pub fn setaudit(auditinfo: *const auditinfo_t) -> ::c_int; pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; + pub fn eventfd_read(fd: ::c_int, value: *mut eventfd_t) -> ::c_int; + pub fn eventfd_write(fd: ::c_int, value: eventfd_t) -> ::c_int; pub fn fdatasync(fd: ::c_int) -> ::c_int; diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 1f12dffa1100d..1bc484d690262 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -46,6 +46,8 @@ pub type Elf64_Off = u64; pub type Elf64_Word = u32; pub type Elf64_Xword = u64; +pub type eventfd_t = u64; + s! { pub struct stack_t { pub ss_sp: *mut ::c_void, @@ -3566,6 +3568,8 @@ extern "C" { flags: ::c_uint, ) -> ::ssize_t; pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; + pub fn eventfd_read(fd: ::c_int, value: *mut eventfd_t) -> ::c_int; + pub fn eventfd_write(fd: ::c_int, value: eventfd_t) -> ::c_int; pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int; pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int; pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 07e6e420d3532..185f25edaad06 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -52,6 +52,7 @@ pub type iconv_t = *mut ::c_void; // linux/sctp.h pub type sctp_assoc_t = ::__s32; +pub type eventfd_t = u64; #[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // FIXME: fill this out with a struct impl ::Copy for fpos64_t {} @@ -4805,6 +4806,9 @@ extern "C" { flags: ::c_uint, ) -> ::ssize_t; pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; + pub fn eventfd_read(fd: ::c_int, value: *mut eventfd_t) -> ::c_int; + pub fn eventfd_write(fd: ::c_int, value: eventfd_t) -> ::c_int; + pub fn sched_rr_get_interval(pid: ::pid_t, tp: *mut ::timespec) -> ::c_int; pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int; pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int;