summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2019-01-23 21:53:43 +0000
committercheloha <cheloha@cvs.openbsd.org>2019-01-23 21:53:43 +0000
commite35ba46f51831db4454fac1caa441b6c937cc7bb (patch)
tree02d37c5a893ddf188f7c712db640355729e19d93
parentc99fc7b3c42fb829d37a1ec8f19464459457b1de (diff)
Sprinkle a pinch of timerisvalid/timespecisvalid over the rest of sys/kern
-rw-r--r--sys/kern/kern_sig.c4
-rw-r--r--sys/kern/kern_synch.c4
-rw-r--r--sys/kern/kern_time.c18
-rw-r--r--sys/kern/sys_futex.c4
4 files changed, 14 insertions, 16 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 4c9b3451dae..0993d8aa810 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.226 2018/12/17 14:51:57 visa Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.227 2019/01/23 21:53:42 cheloha Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -1717,7 +1717,7 @@ sys___thrsigdivert(struct proc *p, void *v, register_t *retval)
if (KTRPOINT(p, KTR_STRUCT))
ktrreltimespec(p, &ts);
#endif
- if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000)
+ if (!timespecisvalid(&ts))
timeinvalid = 1;
else {
to_ticks = (uint64_t)hz * ts.tv_sec +
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 684624428db..8405b83aa66 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.146 2018/05/31 02:16:22 guenther Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.147 2019/01/23 21:53:42 cheloha Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -612,7 +612,7 @@ sys___thrsleep(struct proc *p, void *v, register_t *retval)
*retval = error;
return 0;
}
- if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000) {
+ if (!timespecisvalid(&ts)) {
*retval = EINVAL;
return 0;
}
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index bea703e8d7d..8e00465657b 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.108 2019/01/18 20:55:19 cheloha Exp $ */
+/* $OpenBSD: kern_time.c,v 1.109 2019/01/23 21:53:42 cheloha Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -193,7 +193,7 @@ sys_clock_settime(struct proc *p, void *v, register_t *retval)
clock_id = SCARG(uap, clock_id);
switch (clock_id) {
case CLOCK_REALTIME:
- if (ats.tv_nsec < 0 || ats.tv_nsec >= 1000000000)
+ if (!timespecisvalid(&ats))
return (EINVAL);
if ((error = settime(&ats)) != 0)
return (error);
@@ -273,8 +273,7 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval)
ktrreltimespec(p, &request);
#endif
- if (request.tv_sec < 0 || request.tv_nsec < 0 ||
- request.tv_nsec >= 1000000000)
+ if (request.tv_sec < 0 || !timespecisvalid(&request))
return (EINVAL);
do {
@@ -284,9 +283,11 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval)
getnanouptime(&stop);
timespecsub(&stop, &start, &elapsed);
timespecsub(&request, &elapsed, &request);
+ if (request.tv_sec < 0)
+ timespecclear(&request);
if (error != EWOULDBLOCK)
break;
- } while (request.tv_sec >= 0 && timespecisset(&request));
+ } while (timespecisset(&request));
if (error == ERESTART)
error = EINTR;
@@ -296,9 +297,6 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval)
if (rmtp) {
memset(&remainder, 0, sizeof(remainder));
remainder = request;
- if (remainder.tv_sec < 0)
- timespecclear(&remainder);
-
copyout_error = copyout(&remainder, rmtp, sizeof(remainder));
if (copyout_error)
error = copyout_error;
@@ -367,7 +365,7 @@ sys_settimeofday(struct proc *p, void *v, register_t *retval)
if (tv) {
struct timespec ts;
- if (atv.tv_usec < 0 || atv.tv_usec >= 1000000)
+ if (!timerisvalid(&atv))
return (EINVAL);
TIMEVAL_TO_TIMESPEC(&atv, &ts);
if ((error = settime(&ts)) != 0)
@@ -442,7 +440,7 @@ sys_adjtime(struct proc *p, void *v, register_t *retval)
if ((error = copyin(delta, &atv, sizeof(struct timeval))))
return (error);
- if (atv.tv_usec < 0 || atv.tv_usec >= 1000000)
+ if (!timerisvalid(&atv))
return (EINVAL);
/* XXX Check for overflow? */
diff --git a/sys/kern/sys_futex.c b/sys/kern/sys_futex.c
index 0434e16acf1..13c4b563fc1 100644
--- a/sys/kern/sys_futex.c
+++ b/sys/kern/sys_futex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_futex.c,v 1.10 2019/01/18 05:06:38 cheloha Exp $ */
+/* $OpenBSD: sys_futex.c,v 1.11 2019/01/23 21:53:42 cheloha Exp $ */
/*
* Copyright (c) 2016-2017 Martin Pieuchot
@@ -242,7 +242,7 @@ futex_wait(uint32_t *uaddr, uint32_t val, const struct timespec *timeout,
if (KTRPOINT(p, KTR_STRUCT))
ktrabstimespec(p, &ts);
#endif
- if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000)
+ if (ts.tv_sec < 0 || !timespecisvalid(&ts))
return EINVAL;
to_ticks = (uint64_t)hz * ts.tv_sec +
(ts.tv_nsec + tick * 1000 - 1) / (tick * 1000) + 1;