summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/time/syscalls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/backend/libc/time/syscalls.rs')
-rw-r--r--vendor/rustix/src/backend/libc/time/syscalls.rs73
1 files changed, 37 insertions, 36 deletions
diff --git a/vendor/rustix/src/backend/libc/time/syscalls.rs b/vendor/rustix/src/backend/libc/time/syscalls.rs
index 9d341d886..14ca22b2d 100644
--- a/vendor/rustix/src/backend/libc/time/syscalls.rs
+++ b/vendor/rustix/src/backend/libc/time/syscalls.rs
@@ -1,20 +1,22 @@
//! libc syscalls supporting `rustix::time`.
-use super::super::c;
-use super::super::conv::ret;
-#[cfg(feature = "time")]
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
-use super::super::time::types::LibcItimerspec;
-use super::super::time::types::LibcTimespec;
-use super::types::Timespec;
+use crate::backend::c;
+use crate::backend::conv::ret;
#[cfg(not(target_os = "wasi"))]
-use super::types::{ClockId, DynamicClockId};
+use crate::clockid::{ClockId, DynamicClockId};
use crate::io;
+#[cfg(all(
+ any(target_arch = "arm", target_arch = "mips", target_arch = "x86"),
+ target_env = "gnu",
+))]
+use crate::timespec::LibcTimespec;
+use crate::timespec::Timespec;
use core::mem::MaybeUninit;
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(feature = "time")]
use {
- super::super::conv::{borrowed_fd, ret_owned_fd},
+ crate::backend::conv::{borrowed_fd, ret_owned_fd},
+ crate::backend::time::types::LibcItimerspec,
crate::fd::{BorrowedFd, OwnedFd},
crate::time::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags},
};
@@ -51,8 +53,6 @@ weak!(fn __timerfd_settime64(c::c_int, c::c_int, *const LibcItimerspec, *mut Lib
#[inline]
#[must_use]
pub(crate) fn clock_getres(id: ClockId) -> Timespec {
- let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
-
// 32-bit gnu version: libc has `clock_getres` but it is not y2038 safe by
// default.
#[cfg(all(
@@ -60,6 +60,8 @@ pub(crate) fn clock_getres(id: ClockId) -> Timespec {
target_env = "gnu",
))]
unsafe {
+ let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
+
if let Some(libc_clock_getres) = __clock_getres64.get() {
ret(libc_clock_getres(id as c::clockid_t, timespec.as_mut_ptr())).unwrap();
timespec.assume_init().into()
@@ -74,6 +76,7 @@ pub(crate) fn clock_getres(id: ClockId) -> Timespec {
target_env = "gnu",
)))]
unsafe {
+ let mut timespec = MaybeUninit::<Timespec>::uninit();
let _ = c::clock_getres(id as c::clockid_t, timespec.as_mut_ptr());
timespec.assume_init()
}
@@ -102,13 +105,13 @@ unsafe fn clock_getres_old(id: ClockId) -> Timespec {
#[inline]
#[must_use]
pub(crate) fn clock_gettime(id: ClockId) -> Timespec {
- let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
-
#[cfg(all(
any(target_arch = "arm", target_arch = "mips", target_arch = "x86"),
target_env = "gnu",
))]
unsafe {
+ let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
+
if let Some(libc_clock_gettime) = __clock_gettime64.get() {
ret(libc_clock_gettime(
id as c::clockid_t,
@@ -130,6 +133,7 @@ pub(crate) fn clock_gettime(id: ClockId) -> Timespec {
target_env = "gnu",
)))]
unsafe {
+ let mut timespec = MaybeUninit::<Timespec>::uninit();
ret(c::clock_gettime(id as c::clockid_t, timespec.as_mut_ptr())).unwrap();
timespec.assume_init()
}
@@ -157,34 +161,33 @@ unsafe fn clock_gettime_old(id: ClockId) -> Timespec {
#[cfg(not(target_os = "wasi"))]
#[inline]
pub(crate) fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> {
- let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
unsafe {
let id: c::clockid_t = match id {
DynamicClockId::Known(id) => id as c::clockid_t,
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
DynamicClockId::Dynamic(fd) => {
use crate::fd::AsRawFd;
const CLOCKFD: i32 = 3;
(!fd.as_raw_fd() << 3) | CLOCKFD
}
- #[cfg(not(any(target_os = "android", target_os = "linux")))]
+ #[cfg(not(linux_kernel))]
DynamicClockId::Dynamic(_fd) => {
// Dynamic clocks are not supported on this platform.
return Err(io::Errno::INVAL);
}
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM,
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
DynamicClockId::Tai => c::CLOCK_TAI,
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(any(linux_kernel, target_os = "openbsd"))]
DynamicClockId::Boottime => c::CLOCK_BOOTTIME,
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
DynamicClockId::BoottimeAlarm => c::CLOCK_BOOTTIME_ALARM,
};
@@ -193,6 +196,8 @@ pub(crate) fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timesp
target_env = "gnu",
))]
{
+ let mut timespec = MaybeUninit::<LibcTimespec>::uninit();
+
if let Some(libc_clock_gettime) = __clock_gettime64.get() {
ret(libc_clock_gettime(
id as c::clockid_t,
@@ -210,6 +215,8 @@ pub(crate) fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timesp
target_env = "gnu",
)))]
{
+ let mut timespec = MaybeUninit::<Timespec>::uninit();
+
ret(c::clock_gettime(id as c::clockid_t, timespec.as_mut_ptr()))?;
Ok(timespec.assume_init())
@@ -277,9 +284,7 @@ pub(crate) fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> {
any(target_arch = "arm", target_arch = "mips", target_arch = "x86"),
target_env = "gnu",
))]
-#[must_use]
unsafe fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> {
- use core::convert::TryInto;
let old_timespec = c::timespec {
tv_sec: timespec
.tv_sec
@@ -290,13 +295,13 @@ unsafe fn clock_settime_old(id: ClockId, timespec: Timespec) -> io::Result<()> {
ret(c::clock_settime(id as c::clockid_t, &old_timespec))
}
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(feature = "time")]
pub(crate) fn timerfd_create(id: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> {
- unsafe { ret_owned_fd(c::timerfd_create(id as c::clockid_t, flags.bits())) }
+ unsafe { ret_owned_fd(c::timerfd_create(id as c::clockid_t, bitflags_bits!(flags))) }
}
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(feature = "time")]
pub(crate) fn timerfd_settime(
fd: BorrowedFd<'_>,
@@ -313,7 +318,7 @@ pub(crate) fn timerfd_settime(
if let Some(libc_timerfd_settime) = __timerfd_settime64.get() {
ret(libc_timerfd_settime(
borrowed_fd(fd),
- flags.bits(),
+ bitflags_bits!(flags),
&new_value.clone().into(),
result.as_mut_ptr(),
))?;
@@ -330,7 +335,7 @@ pub(crate) fn timerfd_settime(
unsafe {
ret(c::timerfd_settime(
borrowed_fd(fd),
- flags.bits(),
+ bitflags_bits!(flags),
new_value,
result.as_mut_ptr(),
))?;
@@ -338,7 +343,7 @@ pub(crate) fn timerfd_settime(
}
}
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(all(
any(target_arch = "arm", target_arch = "mips", target_arch = "x86"),
target_env = "gnu",
@@ -349,8 +354,6 @@ unsafe fn timerfd_settime_old(
flags: TimerfdTimerFlags,
new_value: &Itimerspec,
) -> io::Result<Itimerspec> {
- use core::convert::TryInto;
-
let mut old_result = MaybeUninit::<c::itimerspec>::uninit();
// Convert `new_value` to the old `itimerspec` format.
@@ -383,7 +386,7 @@ unsafe fn timerfd_settime_old(
ret(c::timerfd_settime(
borrowed_fd(fd),
- flags.bits(),
+ bitflags_bits!(flags),
&old_new_value,
old_result.as_mut_ptr(),
))?;
@@ -409,7 +412,7 @@ unsafe fn timerfd_settime_old(
})
}
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(feature = "time")]
pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
let mut result = MaybeUninit::<LibcItimerspec>::uninit();
@@ -437,15 +440,13 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
}
}
-#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(all(
any(target_arch = "arm", target_arch = "mips", target_arch = "x86"),
target_env = "gnu",
))]
#[cfg(feature = "time")]
unsafe fn timerfd_gettime_old(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
- use core::convert::TryInto;
-
let mut old_result = MaybeUninit::<c::itimerspec>::uninit();
ret(c::timerfd_gettime(borrowed_fd(fd), old_result.as_mut_ptr()))?;