Skip to content

Commit 54559ab

Browse files
committed
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
1 parent c627f83 commit 54559ab

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
@@ -1278,6 +1278,7 @@ fn test_netbsd(target: &str) {
12781278
"mqueue.h",
12791279
"netinet/dccp.h",
12801280
"sys/event.h",
1281+
(!netbsd9, "sys/eventfd.h"),
12811282
"sys/quota.h",
12821283
"sys/reboot.h",
12831284
"sys/shm.h",
@@ -1323,6 +1324,7 @@ fn test_netbsd(target: &str) {
13231324
"sighandler_t" => true,
13241325
// Incomplete type in C
13251326
"cpuset_t" => true,
1327+
"eventfd_t" if netbsd9 => true,
13261328
_ => false,
13271329
}
13281330
});
@@ -1382,6 +1384,8 @@ fn test_netbsd(target: &str) {
13821384
// FIXME(netbsd): Look into setting `_POSIX_C_SOURCE` to enable this
13831385
"qsort_r" => true,
13841386

1387+
"eventfd" | "eventfd_read" | "eventfd_write" if netbsd9 => true,
1388+
13851389
_ => false,
13861390
}
13871391
});

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;
@@ -1742,6 +1743,11 @@ pub const RTA_TAG: c_int = 0x100;
17421743
pub const RTAX_TAG: c_int = 8;
17431744
pub const RTAX_MAX: c_int = 9;
17441745

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

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

0 commit comments

Comments
 (0)