summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-03-20 03:37:08 +0000
committercheloha <cheloha@openbsd.org>2020-03-20 03:37:08 +0000
commit375723add634b352ea99cdf4dff635a8389e8913 (patch)
treedc0d0f7a08d1c282c1bdd4745e8f5844206c4dfa /sys/kern/kern_synch.c
parentReturn when create_solver() returns NULL to prevent null pointer dereference (diff)
downloadwireguard-openbsd-375723add634b352ea99cdf4dff635a8389e8913.tar.xz
wireguard-openbsd-375723add634b352ea99cdf4dff635a8389e8913.zip
tsleep_nsec(9): add MAXTSLP macro, the maximum sleep duration
This macro will be useful for truncating durations below INFSLP (UINT64_MAX) when converting from a timespec or timeval to a count of nanoseconds before calling tsleep_nsec(9), msleep_nsec(9), or rwsleep_nsec(9). A relative timespec can hold many more nanoseconds than a uint64_t can. TIMESPEC_TO_NSEC() and TIMEVAL_TO_NSEC() check for overflow, returning UINT64_MAX if the conversion would overflow a uint64_t. Thus, MAXTSLP will make it easy to avoid inadvertently passing INFSLP to tsleep_nsec(9) et al. when the caller intended to set a timeout. The code in such a case might look something like this: uint64_t nsecs = MIN(TIMESPEC_TO_NSEC(&ts), MAXTSLP); The macro may also be useful for rejecting intervals that are "too large", e.g. for sockets with timeouts, if the timeout duration is to be stored as a uint64_t in an object in the kernel. The code in such a case might look something like this: case SIOCTIMEOUT: { struct timeval *tv = (struct timeval *)data; uint64_t nsecs; if (tv->tv_sec < 0 || !timerisvalid(tv)) return EINVAL; nsecs = TIMEVAL_TO_NSEC(tv); if (nsecs > MAXTSLP) return EOVERFLOW; obj.timeout = nsecs; break; } Idea suggested by visa@. ok visa@
Diffstat (limited to 'sys/kern/kern_synch.c')
0 files changed, 0 insertions, 0 deletions