From 6040822c4e20fb46638ecaaad543fc56f6ec2b0f Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Mon, 30 Jul 2018 15:46:40 +0000 Subject: Make timespecadd(3) and friends public The timespecadd(3) family of macros were imported from NetBSD back in r35029. However, they were initially guarded by #ifdef _KERNEL. In the meantime, we have grown at least 28 syscalls that use timespecs in some way, leading many programs both inside and outside of the base system to redefine those macros. It's better just to make the definitions public. Our kernel currently defines two-argument versions of timespecadd and timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define three-argument versions. Solaris also defines a three-argument version, but only in its kernel. This revision changes our definition to match the common three-argument version. Bump _FreeBSD_version due to the breaking KPI change. Discussed with: cem, jilles, ian, bde Differential Revision: https://reviews.freebsd.org/D14725 --- sys/compat/linux/linux_event.c | 16 ++++++++-------- sys/compat/linux/linux_futex.c | 4 ++-- sys/compat/linux/linux_misc.c | 4 ++-- sys/compat/linux/linux_socket.c | 4 ++-- sys/compat/linuxkpi/common/include/linux/time.h | 4 +--- 5 files changed, 15 insertions(+), 17 deletions(-) (limited to 'sys/compat') diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c index ae6cb83c9e7a..bb4825574ed5 100644 --- a/sys/compat/linux/linux_event.c +++ b/sys/compat/linux/linux_event.c @@ -1183,7 +1183,7 @@ linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots) linux_timerfd_clocktime(tfd, &cts); *ots = tfd->tfd_time; if (ots->it_value.tv_sec != 0 || ots->it_value.tv_nsec != 0) { - timespecsub(&ots->it_value, &cts); + timespecsub(&ots->it_value, &cts, &ots->it_value); if (ots->it_value.tv_sec < 0 || (ots->it_value.tv_sec == 0 && ots->it_value.tv_nsec == 0)) { @@ -1265,9 +1265,10 @@ linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args linux_timerfd_clocktime(tfd, &cts); ts = nts.it_value; if ((args->flags & LINUX_TFD_TIMER_ABSTIME) == 0) { - timespecadd(&tfd->tfd_time.it_value, &cts); + timespecadd(&tfd->tfd_time.it_value, &cts, + &tfd->tfd_time.it_value); } else { - timespecsub(&ts, &cts); + timespecsub(&ts, &cts, &ts); } TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), @@ -1303,13 +1304,13 @@ linux_timerfd_expire(void *arg) if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) { if (timespecisset(&tfd->tfd_time.it_interval)) timespecadd(&tfd->tfd_time.it_value, - &tfd->tfd_time.it_interval); + &tfd->tfd_time.it_interval, + &tfd->tfd_time.it_value); else /* single shot timer */ timespecclear(&tfd->tfd_time.it_value); if (timespecisset(&tfd->tfd_time.it_value)) { - ts = tfd->tfd_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&tfd->tfd_time.it_value, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), linux_timerfd_expire, tfd); @@ -1319,8 +1320,7 @@ linux_timerfd_expire(void *arg) selwakeup(&tfd->tfd_sel); wakeup(&tfd->tfd_count); } else if (timespecisset(&tfd->tfd_time.it_value)) { - ts = tfd->tfd_time.it_value; - timespecsub(&ts, &cts); + timespecsub(&tfd->tfd_time.it_value, &cts, &ts); TIMESPEC_TO_TIMEVAL(&tv, &ts); callout_reset(&tfd->tfd_callout, tvtohz(&tv), linux_timerfd_expire, tfd); diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index a82672eaa4f1..7c15af2d89c2 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -290,10 +290,10 @@ futex_copyin_timeout(int op, struct l_timespec *luts, int clockrt, return (error); if (clockrt) { nanotime(&kts); - timespecsub(ts, &kts); + timespecsub(ts, &kts, ts); } else if (op == LINUX_FUTEX_WAIT_BITSET) { nanouptime(&kts); - timespecsub(ts, &kts); + timespecsub(ts, &kts, ts); } return (error); } diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 95a8ab174e9d..516952fac490 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2382,8 +2382,8 @@ linux_ppoll(struct thread *td, struct linux_ppoll_args *args) if (error == 0 && args->tsp != NULL) { if (td->td_retval[0]) { nanotime(&ts1); - timespecsub(&ts1, &ts0); - timespecsub(&uts, &ts1); + timespecsub(&ts1, &ts0, &ts1); + timespecsub(&uts, &ts1, &uts); if (uts.tv_sec < 0) timespecclear(&uts); } else diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 604627048ed0..d4f567b5192f 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1463,7 +1463,7 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args) if (error != 0) return (error); getnanotime(&tts); - timespecadd(&tts, &ts); + timespecadd(&tts, &ts, &tts); } msg = PTRIN(args->msg); @@ -1492,7 +1492,7 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args) */ if (args->timeout) { getnanotime(&ts); - timespecsub(&ts, &tts); + timespecsub(&ts, &tts, &ts); if (!timespecisset(&ts) || ts.tv_sec > 0) break; } diff --git a/sys/compat/linuxkpi/common/include/linux/time.h b/sys/compat/linuxkpi/common/include/linux/time.h index 9f69e95f6bf5..1c07c69a67a6 100644 --- a/sys/compat/linuxkpi/common/include/linux/time.h +++ b/sys/compat/linuxkpi/common/include/linux/time.h @@ -76,9 +76,7 @@ timespec_sub(struct timespec lhs, struct timespec rhs) { struct timespec ts; - ts.tv_sec = lhs.tv_sec; - ts.tv_nsec = lhs.tv_nsec; - timespecsub(&ts, &rhs); + timespecsub(&lhs, &rhs, &ts); return ts; } -- cgit v1.2.3