Skip to content

Commit

Permalink
Auto merge of #3437 - SteveLauC:eventfd_read, r=JohnTitor
Browse files Browse the repository at this point in the history
feat: eventfd_read/write for Android/FreeBSD/Linux

Add

```c
int eventfd_read(int fd, eventfd_t *value);
int eventfd_write(int fd, eventfd_t value);
```

for

* Android
* [FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=eventfd&apropos=0&sektion=2&manpath=FreeBSD+13.2-RELEASE&arch=default&format=html)
* [Linux](https://man7.org/linux/man-pages/man2/eventfd.2.html)
  • Loading branch information
bors committed Nov 12, 2023
2 parents af57553 + da88121 commit 1ec4e59
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3756,3 +3756,5 @@ write
writev
dirname
basename
eventfd_read
eventfd_write
2 changes: 2 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2245,3 +2245,5 @@ dirname
basename
closefrom
close_range
eventfd_read
eventfd_write
2 changes: 2 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3842,3 +3842,5 @@ vhangup
vmsplice
wait4
waitid
eventfd_read
eventfd_write
4 changes: 4 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -5092,6 +5093,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;
Expand Down

0 comments on commit 1ec4e59

Please sign in to comment.