Skip to content

Commit ae6df79

Browse files
krobelustgross35
authored andcommitted
Define eventfd on NetBSD
Like FreeBSD but unlike OpenBSD, NetBSD supports eventfd since version 10 (September 2021, see http://netbsd.org/changes/changes-10.0.html). I don't know enough about NetBSD to know whether all systems running 10 can be expected to have eventfd, but it's probably fine. Our GitHub actions CI only tests NetBSD 10.1. Ref: https://man.netbsd.org/eventfd.2 Ref: https://github.com/NetBSD/src/blob/d04b0c735abc997743bb3faa74464524cbe7becd/sys/sys/eventfd.h (backport <#4830>) (cherry picked from commit 3e82c57)
1 parent 03b7438 commit ae6df79

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

libc-test/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@ fn test_netbsd(target: &str) {
13651365
"mqueue.h",
13661366
"netinet/dccp.h",
13671367
"sys/event.h",
1368+
(!netbsd9, "sys/eventfd.h"),
13681369
"sys/quota.h",
13691370
"sys/reboot.h",
13701371
"sys/shm.h",
@@ -1411,6 +1412,7 @@ fn test_netbsd(target: &str) {
14111412
"sighandler_t" => true,
14121413
// Incomplete type in C
14131414
"cpuset_t" => true,
1415+
"eventfd_t" if netbsd9 => true,
14141416
_ => false,
14151417
}
14161418
});
@@ -1474,6 +1476,8 @@ fn test_netbsd(target: &str) {
14741476
// FIXME(netbsd): Look into setting `_POSIX_C_SOURCE` to enable this
14751477
"qsort_r" => true,
14761478

1479+
"eventfd" | "eventfd_read" | "eventfd_write" if netbsd9 => true,
1480+
14771481
_ => false,
14781482
}
14791483
});

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
};
88

99
pub type blksize_t = i32;
10+
pub type eventfd_t = u64;
1011
pub type fsblkcnt_t = u64;
1112
pub type fsfilcnt_t = u64;
1213
pub type idtype_t = c_int;
@@ -1743,6 +1744,11 @@ pub const RTA_TAG: c_int = 0x100;
17431744
pub const RTAX_TAG: c_int = 8;
17441745
pub const RTAX_MAX: c_int = 9;
17451746

1747+
// For eventfd
1748+
pub const EFD_SEMAPHORE: c_int = crate::O_RDWR;
1749+
pub const EFD_NONBLOCK: c_int = crate::O_NONBLOCK;
1750+
pub const EFD_CLOEXEC: c_int = crate::O_CLOEXEC;
1751+
17461752
// sys/timerfd.h
17471753
pub const TFD_CLOEXEC: i32 = crate::O_CLOEXEC;
17481754
pub const TFD_NONBLOCK: i32 = crate::O_NONBLOCK;
@@ -2198,6 +2204,10 @@ extern "C" {
21982204
pub fn getmntinfo(mntbufp: *mut *mut crate::statvfs, flags: c_int) -> c_int;
21992205
pub fn getvfsstat(buf: *mut crate::statvfs, bufsize: size_t, flags: c_int) -> c_int;
22002206

2207+
pub fn eventfd(val: c_uint, flags: c_int) -> c_int;
2208+
pub fn eventfd_read(efd: c_int, valp: *mut eventfd_t) -> c_int;
2209+
pub fn eventfd_write(efd: c_int, val: eventfd_t) -> c_int;
2210+
22012211
// Added in `NetBSD` 10.0
22022212
pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int;
22032213
pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int;

0 commit comments

Comments
 (0)