From f40a7c1c8eeb8466a3db01964893c19141f90f58 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Sat, 17 Aug 2024 13:22:09 -0400 Subject: [PATCH] Linux: add `getitimer()`/`setitimer()` --- libc-test/build.rs | 3 +++ libc-test/semver/linux.txt | 4 ++++ src/unix/linux_like/linux/mod.rs | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 26b1c550de22..f01830059676 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3648,6 +3648,9 @@ fn test_linux(target: &str) { // in the `linux_elf.rs` file. "Elf64_Phdr" | "Elf32_Phdr" => true, + // musl doesn't define these; instead, it uses a raw int for getitimer/setitimer + "__itimer_which" | "__itimer_which_t" if musl => true, + // On Linux, the type of `ut_tv` field of `struct utmpx` // can be an anonymous struct, so an extra struct, // which is absent in glibc, has to be defined. diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index c93940b82e48..2a61cdd2bd95 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3475,6 +3475,8 @@ __c_anonymous_sockaddr_can_j1939 __c_anonymous_sockaddr_can_tp __errno_location __exit_status +__itimer_which +__itimer_which_t __s16 __s32 __u16 @@ -3591,6 +3593,7 @@ getgrnam_r getgrouplist gethostid getifaddrs +getitimer getline getmntent getnameinfo @@ -3892,6 +3895,7 @@ setfsuid setgrent setgroups sethostname +setitimer setmntent setns setpriority diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 2ce09ed168df..10c75699ae0e 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -73,6 +73,21 @@ missing! { pub enum fpos64_t {} // FIXME: fill this out with a struct } +cfg_if! { + if #[cfg(not(target_env = "musl"))] { + pub type __itimer_which_t = ::__itimer_which; + + e! { + #[repr(i32)] + pub enum __itimer_which { + ITIMER_REAL = 0, + ITIMER_VIRTUAL = 1, + ITIMER_PROF = 2, + } + } + } +} + e! { pub enum tpacket_versions { TPACKET_V1, @@ -6129,6 +6144,28 @@ extern "C" { pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int; } +cfg_if! { + if #[cfg(target_env = "musl")] { + extern "C" { + pub fn getitimer(which: ::c_int, value: *mut ::itimerval) -> ::c_int; + pub fn setitimer( + which: ::c_int, + new: *const ::itimerval, + old: *mut ::itimerval, + ) -> ::c_int; + } + } else { + extern "C" { + pub fn getitimer(which: ::__itimer_which_t, value: *mut ::itimerval) -> ::c_int; + pub fn setitimer( + which: ::__itimer_which_t, + new: *const ::itimerval, + old: *mut ::itimerval, + ) -> ::c_int; + } + } +} + // LFS64 extensions // // * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones