Skip to content

Commit 78d9f2e

Browse files
committed
Add timerfd APIs for illumos and NetBSD.
illumos and NetBSD >= 10 support Linux-compatble timerfd APIs. This is based on the headers for [illumos] and [NetBSD]. [illumos]: https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/uts/common/sys/timerfd.h#34 [NetBSD]: https://nxr.netbsd.org/xref/src/sys/sys/timerfd.h#44
1 parent c6a3cd6 commit 78d9f2e

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

libc-test/semver/illumos.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ POSIX_FADV_RANDOM
1515
POSIX_FADV_SEQUENTIAL
1616
POSIX_FADV_WILLNEED
1717
POSIX_SPAWN_SETSID
18+
TFD_CLOEXEC
19+
TFD_NONBLOCK
20+
TFD_TIMER_ABSTIME
21+
TFD_TIMER_CANCEL_ON_SET
1822
posix_fadvise
1923
posix_fallocate
2024
posix_spawn_file_actions_addfchdir_np
@@ -23,3 +27,6 @@ pthread_attr_getstackaddr
2327
pthread_attr_setstack
2428
ptsname_r
2529
syncfs
30+
timerfd_create
31+
timerfd_gettime
32+
timerfd_settime

libc-test/semver/netbsd.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ TCP_KEEPINIT
10421042
TCP_KEEPINTVL
10431043
TCP_MAXSEG
10441044
TCP_MD5SIG
1045+
TFD_CLOEXEC
1046+
TFD_NONBLOCK
1047+
TFD_TIMER_ABSTIME
1048+
TFD_TIMER_CANCEL_ON_SET
10451049
THOUSEP
10461050
TIMER_ABSTIME
10471051
TIME_DEL
@@ -1613,6 +1617,9 @@ timer_getoverrun
16131617
timer_gettime
16141618
timer_settime
16151619
timer_t
1620+
timerfd_create
1621+
timerfd_gettime
1622+
timerfd_settime
16161623
timex
16171624
truncate
16181625
ttyname_r

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,12 @@ pub const RTA_TAG: c_int = 0x100;
24092409
pub const RTAX_TAG: c_int = 8;
24102410
pub const RTAX_MAX: c_int = 9;
24112411

2412+
// sys/timerfd.h
2413+
pub const TFD_CLOEXEC: i32 = crate::O_CLOEXEC;
2414+
pub const TFD_NONBLOCK: i32 = crate::O_NONBLOCK;
2415+
pub const TFD_TIMER_ABSTIME: i32 = crate::O_WRONLY;
2416+
pub const TFD_TIMER_CANCEL_ON_SET: i32 = crate::O_RDWR;
2417+
24122418
const_fn! {
24132419
{const} fn _ALIGN(p: usize) -> usize {
24142420
(p + _ALIGNBYTES) & !_ALIGNBYTES
@@ -2853,6 +2859,16 @@ extern "C" {
28532859
#[link_name = "__getmntinfo13"]
28542860
pub fn getmntinfo(mntbufp: *mut *mut crate::statvfs, flags: c_int) -> c_int;
28552861
pub fn getvfsstat(buf: *mut statvfs, bufsize: size_t, flags: c_int) -> c_int;
2862+
2863+
// Added in `NetBSD` 10.0
2864+
pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int;
2865+
pub fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int;
2866+
pub fn timerfd_settime(
2867+
fd: c_int,
2868+
flags: c_int,
2869+
new_value: *const itimerspec,
2870+
old_value: *mut itimerspec,
2871+
) -> c_int;
28562872
}
28572873

28582874
#[link(name = "rt")]

src/unix/solarish/illumos.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ pub const B4000000: crate::speed_t = 31;
286286
// sys/systeminfo.h
287287
pub const SI_ADDRESS_WIDTH: c_int = 520;
288288

289+
// sys/timerfd.h
290+
pub const TFD_CLOEXEC: i32 = 0o2000000;
291+
pub const TFD_NONBLOCK: i32 = 0o4000;
292+
pub const TFD_TIMER_ABSTIME: i32 = 1 << 0;
293+
pub const TFD_TIMER_CANCEL_ON_SET: i32 = 1 << 1;
294+
289295
extern "C" {
290296
pub fn eventfd(init: c_uint, flags: c_int) -> c_int;
291297

@@ -353,4 +359,13 @@ extern "C" {
353359
n: size_t,
354360
loc: crate::locale_t,
355361
) -> c_int;
362+
363+
pub fn timerfd_create(clockid: c_int, flags: c_int) -> c_int;
364+
pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int;
365+
pub fn timerfd_settime(
366+
fd: c_int,
367+
flags: c_int,
368+
new_value: *const crate::itimerspec,
369+
old_value: *mut crate::itimerspec,
370+
) -> c_int;
356371
}

0 commit comments

Comments
 (0)