about summary refs log tree commit diff
path: root/src/sched
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-28 23:26:38 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-29 12:31:20 -0400
commit1d4471b1fdfaa042ac48e9d8bcf00842dc529418 (patch)
treeb21b1f3f4ae1a1741b7cf532798ac5a229c4d3dd /src/sched
parent244858553e7eaacd135de5c1cdb49489796b6d02 (diff)
downloadmusl-1d4471b1fdfaa042ac48e9d8bcf00842dc529418.tar.gz
musl-1d4471b1fdfaa042ac48e9d8bcf00842dc529418.tar.xz
musl-1d4471b1fdfaa042ac48e9d8bcf00842dc529418.zip
sched_rr_get_interval: don't assume time_t is 32-bit on 32-bit archs
as with clock_getres, the time64 syscall for this is not necessary or
useful, this time since scheduling timeslices are not on the order 68
years. if there's a 32-bit syscall, use it and expand the result into
timespec; otherwise there is only one syscall and it does the right
thing to store to timespec directly.

on 64-bit archs, there is no change to the code after preprocessing.
Diffstat (limited to 'src/sched')
-rw-r--r--src/sched/sched_rr_get_interval.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/sched/sched_rr_get_interval.c b/src/sched/sched_rr_get_interval.c
index 4b01028f..33a3d1ae 100644
--- a/src/sched/sched_rr_get_interval.c
+++ b/src/sched/sched_rr_get_interval.c
@@ -3,5 +3,19 @@
 
 int sched_rr_get_interval(pid_t pid, struct timespec *ts)
 {
+#ifdef SYS_sched_rr_get_interval_time64
+	/* On a 32-bit arch, use the old syscall if it exists. */
+	if (SYS_sched_rr_get_interval != SYS_sched_rr_get_interval_time64) {
+		long ts32[2];
+		int r = __syscall(SYS_sched_rr_get_interval, pid, ts32);
+		if (!r) {
+			ts->tv_sec = ts32[0];
+			ts->tv_nsec = ts32[1];
+		}
+		return __syscall_ret(r);
+	}
+#endif
+	/* If reaching this point, it's a 64-bit arch or time64-only
+	 * 32-bit arch and we can get result directly into timespec. */
 	return syscall(SYS_sched_rr_get_interval, pid, ts);
 }