about summary refs log tree commit diff
path: root/src/time
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-28 18:38:28 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-29 00:16:56 -0400
commite1501091c404a74f3966441dbf8f6b85bae905c2 (patch)
treebbec7513136fed8058e3fb84f050053ca8feeb44 /src/time
parent22276671d031639f1bd55d7dbf817290c321c7bf (diff)
downloadmusl-e1501091c404a74f3966441dbf8f6b85bae905c2.tar.gz
musl-e1501091c404a74f3966441dbf8f6b85bae905c2.tar.xz
musl-e1501091c404a74f3966441dbf8f6b85bae905c2.zip
timer_settime: add support for time64 syscall, decouple 32-bit time_t
time64 syscall is used only if it's the only one defined for the arch,
if either component of the itimerspec does not fit in 32 bits, or if
time_t is 64-bit and the caller requested the old value, in which case
there's a possibility that the old value might not fit in 32 bits. on
current 32-bit archs where time_t is a 32-bit type, this makes it
statically unreachable.

on 64-bit archs, there is no change to the code after preprocessing.
on current 32-bit archs, the time is moved through an intermediate
copy to remove the assumption that time_t is a 32-bit type.
Diffstat (limited to 'src/time')
-rw-r--r--src/time/timer_settime.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/time/timer_settime.c b/src/time/timer_settime.c
index 62631aa4..373f00ce 100644
--- a/src/time/timer_settime.c
+++ b/src/time/timer_settime.c
@@ -2,11 +2,36 @@
 #include <limits.h>
 #include "pthread_impl.h"
 
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+
 int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old)
 {
 	if ((intptr_t)t < 0) {
 		pthread_t td = (void *)((uintptr_t)t << 1);
 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
 	}
+#ifdef SYS_timer_settime64
+	time_t is = val->it_interval.tv_sec, vs = val->it_value.tv_sec;
+	long ins = val->it_interval.tv_nsec, vns = val->it_value.tv_nsec;
+	int r = -ENOSYS;
+	if (SYS_timer_settime == SYS_timer_settime64
+	    || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old))
+		r = __syscall(SYS_timer_settime64, t, flags,
+			((long long[]){is, ins, vs, vns}), old);
+	if (SYS_timer_settime == SYS_timer_settime64 || r!=-ENOSYS)
+		return __syscall_ret(r);
+	if (!IS32BIT(is) || !IS32BIT(vs))
+		return __syscall_ret(-ENOTSUP);
+	long old32[4];
+	r = __syscall(SYS_timer_settime, t, flags,
+		((long[]){is, ins, vs, vns}), old32);
+	if (!r && old) {
+		old->it_interval.tv_sec = old32[0];
+		old->it_interval.tv_nsec = old32[1];
+		old->it_value.tv_sec = old32[2];
+		old->it_value.tv_nsec = old32[3];
+	}
+	return __syscall_ret(r);
+#endif
 	return syscall(SYS_timer_settime, t, flags, val, old);
 }