Skip to content

Add timerfd APIs for illumos and NetBSD. #4333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libc-test/semver/illumos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ POSIX_FADV_RANDOM
POSIX_FADV_SEQUENTIAL
POSIX_FADV_WILLNEED
POSIX_SPAWN_SETSID
TFD_CLOEXEC
TFD_NONBLOCK
TFD_TIMER_ABSTIME
TFD_TIMER_CANCEL_ON_SET
posix_fadvise
posix_fallocate
posix_spawn_file_actions_addfchdir_np
Expand All @@ -23,3 +27,6 @@ pthread_attr_getstackaddr
pthread_attr_setstack
ptsname_r
syncfs
timerfd_create
timerfd_gettime
timerfd_settime
7 changes: 7 additions & 0 deletions libc-test/semver/netbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,10 @@ TCP_KEEPINIT
TCP_KEEPINTVL
TCP_MAXSEG
TCP_MD5SIG
TFD_CLOEXEC
TFD_NONBLOCK
TFD_TIMER_ABSTIME
TFD_TIMER_CANCEL_ON_SET
THOUSEP
TIMER_ABSTIME
TIME_DEL
Expand Down Expand Up @@ -1613,6 +1617,9 @@ timer_getoverrun
timer_gettime
timer_settime
timer_t
timerfd_create
timerfd_gettime
timerfd_settime
timex
truncate
ttyname_r
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,12 @@ pub const RTA_TAG: c_int = 0x100;
pub const RTAX_TAG: c_int = 8;
pub const RTAX_MAX: c_int = 9;

// sys/timerfd.h
pub const TFD_CLOEXEC: i32 = crate::O_CLOEXEC;
pub const TFD_NONBLOCK: i32 = crate::O_NONBLOCK;
pub const TFD_TIMER_ABSTIME: i32 = crate::O_WRONLY;
pub const TFD_TIMER_CANCEL_ON_SET: i32 = crate::O_RDWR;

const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
Expand Down Expand Up @@ -2853,6 +2859,16 @@ extern "C" {
#[link_name = "__getmntinfo13"]
pub fn getmntinfo(mntbufp: *mut *mut crate::statvfs, flags: c_int) -> c_int;
pub fn getvfsstat(buf: *mut statvfs, bufsize: size_t, flags: c_int) -> c_int;

// Added in `NetBSD` 10.0
pub fn timerfd_create(clockid: crate::clockid_t, flags: c_int) -> c_int;
pub fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int;
pub fn timerfd_settime(
fd: c_int,
flags: c_int,
new_value: *const itimerspec,
old_value: *mut itimerspec,
) -> c_int;
}

#[link(name = "rt")]
Expand Down
15 changes: 15 additions & 0 deletions src/unix/solarish/illumos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ pub const B4000000: crate::speed_t = 31;
// sys/systeminfo.h
pub const SI_ADDRESS_WIDTH: c_int = 520;

// sys/timerfd.h
pub const TFD_CLOEXEC: i32 = 0o2000000;
pub const TFD_NONBLOCK: i32 = 0o4000;
pub const TFD_TIMER_ABSTIME: i32 = 1 << 0;
pub const TFD_TIMER_CANCEL_ON_SET: i32 = 1 << 1;

extern "C" {
pub fn eventfd(init: c_uint, flags: c_int) -> c_int;

Expand Down Expand Up @@ -353,4 +359,13 @@ extern "C" {
n: size_t,
loc: crate::locale_t,
) -> c_int;

pub fn timerfd_create(clockid: c_int, flags: c_int) -> c_int;
pub fn timerfd_gettime(fd: c_int, curr_value: *mut crate::itimerspec) -> c_int;
pub fn timerfd_settime(
fd: c_int,
flags: c_int,
new_value: *const crate::itimerspec,
old_value: *mut crate::itimerspec,
) -> c_int;
}
Loading