2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Roman Divacky
5 * Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/imgact.h>
37 #include <sys/kernel.h>
38 #include <sys/limits.h>
40 #include <sys/mutex.h>
41 #include <sys/callout.h>
42 #include <sys/capsicum.h>
43 #include <sys/types.h>
46 #include <sys/filedesc.h>
47 #include <sys/filio.h>
48 #include <sys/errno.h>
49 #include <sys/event.h>
52 #include <sys/selinfo.h>
53 #include <sys/specialfd.h>
55 #include <sys/syscallsubr.h>
56 #include <sys/timespec.h>
57 #include <sys/eventfd.h>
60 #include <machine/../linux32/linux.h>
61 #include <machine/../linux32/linux32_proto.h>
63 #include <machine/../linux/linux.h>
64 #include <machine/../linux/linux_proto.h>
67 #include <compat/linux/linux_emul.h>
68 #include <compat/linux/linux_event.h>
69 #include <compat/linux/linux_file.h>
70 #include <compat/linux/linux_timer.h>
71 #include <compat/linux/linux_util.h>
73 typedef uint64_t epoll_udata_t;
79 #if defined(__amd64__)
80 __attribute__((packed))
84 #define LINUX_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))
86 static int epoll_to_kevent(struct thread *td, int fd,
87 struct epoll_event *l_event, struct kevent *kevent,
89 static void kevent_to_epoll(struct kevent *kevent, struct epoll_event *l_event);
90 static int epoll_kev_copyout(void *arg, struct kevent *kevp, int count);
91 static int epoll_kev_copyin(void *arg, struct kevent *kevp, int count);
92 static int epoll_register_kevent(struct thread *td, struct file *epfp,
93 int fd, int filter, unsigned int flags);
94 static int epoll_fd_registered(struct thread *td, struct file *epfp,
96 static int epoll_delete_all_events(struct thread *td, struct file *epfp,
99 struct epoll_copyin_args {
100 struct kevent *changelist;
103 struct epoll_copyout_args {
104 struct epoll_event *leventlist;
111 typedef uint64_t timerfd_t;
113 static fo_rdwr_t timerfd_read;
114 static fo_ioctl_t timerfd_ioctl;
115 static fo_poll_t timerfd_poll;
116 static fo_kqfilter_t timerfd_kqfilter;
117 static fo_stat_t timerfd_stat;
118 static fo_close_t timerfd_close;
119 static fo_fill_kinfo_t timerfd_fill_kinfo;
121 static struct fileops timerfdops = {
122 .fo_read = timerfd_read,
123 .fo_write = invfo_rdwr,
124 .fo_truncate = invfo_truncate,
125 .fo_ioctl = timerfd_ioctl,
126 .fo_poll = timerfd_poll,
127 .fo_kqfilter = timerfd_kqfilter,
128 .fo_stat = timerfd_stat,
129 .fo_close = timerfd_close,
130 .fo_chmod = invfo_chmod,
131 .fo_chown = invfo_chown,
132 .fo_sendfile = invfo_sendfile,
133 .fo_fill_kinfo = timerfd_fill_kinfo,
134 .fo_flags = DFLAG_PASSABLE
137 static void filt_timerfddetach(struct knote *kn);
138 static int filt_timerfdread(struct knote *kn, long hint);
140 static struct filterops timerfd_rfiltops = {
142 .f_detach = filt_timerfddetach,
143 .f_event = filt_timerfdread
147 clockid_t tfd_clockid;
148 struct itimerspec tfd_time;
149 struct callout tfd_callout;
152 struct selinfo tfd_sel;
156 static void linux_timerfd_expire(void *);
157 static void linux_timerfd_curval(struct timerfd *, struct itimerspec *);
160 epoll_create_common(struct thread *td, int flags)
163 return (kern_kqueue(td, flags, NULL));
166 #ifdef LINUX_LEGACY_SYSCALLS
168 linux_epoll_create(struct thread *td, struct linux_epoll_create_args *args)
172 * args->size is unused. Linux just tests it
173 * and then forgets it as well.
178 return (epoll_create_common(td, 0));
183 linux_epoll_create1(struct thread *td, struct linux_epoll_create1_args *args)
187 if ((args->flags & ~(LINUX_O_CLOEXEC)) != 0)
191 if ((args->flags & LINUX_O_CLOEXEC) != 0)
194 return (epoll_create_common(td, flags));
197 /* Structure converting function from epoll to kevent. */
199 epoll_to_kevent(struct thread *td, int fd, struct epoll_event *l_event,
200 struct kevent *kevent, int *nkevents)
202 uint32_t levents = l_event->events;
203 struct linux_pemuldata *pem;
205 unsigned short kev_flags = EV_ADD | EV_ENABLE;
207 /* flags related to how event is registered */
208 if ((levents & LINUX_EPOLLONESHOT) != 0)
209 kev_flags |= EV_DISPATCH;
210 if ((levents & LINUX_EPOLLET) != 0)
211 kev_flags |= EV_CLEAR;
212 if ((levents & LINUX_EPOLLERR) != 0)
213 kev_flags |= EV_ERROR;
214 if ((levents & LINUX_EPOLLRDHUP) != 0)
217 /* flags related to what event is registered */
218 if ((levents & LINUX_EPOLL_EVRD) != 0) {
219 EV_SET(kevent, fd, EVFILT_READ, kev_flags, 0, 0, 0);
220 kevent->ext[0] = l_event->data;
224 if ((levents & LINUX_EPOLL_EVWR) != 0) {
225 EV_SET(kevent, fd, EVFILT_WRITE, kev_flags, 0, 0, 0);
226 kevent->ext[0] = l_event->data;
230 /* zero event mask is legal */
231 if ((levents & (LINUX_EPOLL_EVRD | LINUX_EPOLL_EVWR)) == 0) {
232 EV_SET(kevent++, fd, EVFILT_READ, EV_ADD|EV_DISABLE, 0, 0, 0);
236 if ((levents & ~(LINUX_EPOLL_EVSUP)) != 0) {
240 KASSERT(pem != NULL, ("epoll proc emuldata not found.\n"));
242 LINUX_PEM_XLOCK(pem);
243 if ((pem->flags & LINUX_XUNSUP_EPOLL) == 0) {
244 pem->flags |= LINUX_XUNSUP_EPOLL;
245 LINUX_PEM_XUNLOCK(pem);
246 linux_msg(td, "epoll_ctl unsupported flags: 0x%x",
249 LINUX_PEM_XUNLOCK(pem);
257 * Structure converting function from kevent to epoll. In a case
258 * this is called on error in registration we store the error in
259 * event->data and pick it up later in linux_epoll_ctl().
262 kevent_to_epoll(struct kevent *kevent, struct epoll_event *l_event)
265 l_event->data = kevent->ext[0];
267 if ((kevent->flags & EV_ERROR) != 0) {
268 l_event->events = LINUX_EPOLLERR;
272 /* XXX EPOLLPRI, EPOLLHUP */
273 switch (kevent->filter) {
275 l_event->events = LINUX_EPOLLIN;
276 if ((kevent->flags & EV_EOF) != 0)
277 l_event->events |= LINUX_EPOLLRDHUP;
280 l_event->events = LINUX_EPOLLOUT;
286 * Copyout callback used by kevent. This converts kevent
287 * events to epoll events and copies them back to the
288 * userspace. This is also called on error on registering
292 epoll_kev_copyout(void *arg, struct kevent *kevp, int count)
294 struct epoll_copyout_args *args;
295 struct epoll_event *eep;
298 args = (struct epoll_copyout_args*) arg;
299 eep = malloc(sizeof(*eep) * count, M_EPOLL, M_WAITOK | M_ZERO);
301 for (i = 0; i < count; i++)
302 kevent_to_epoll(&kevp[i], &eep[i]);
304 error = copyout(eep, args->leventlist, count * sizeof(*eep));
306 args->leventlist += count;
307 args->count += count;
308 } else if (args->error == 0)
316 * Copyin callback used by kevent. This copies already
317 * converted filters from kernel memory to the kevent
318 * internal kernel memory. Hence the memcpy instead of
322 epoll_kev_copyin(void *arg, struct kevent *kevp, int count)
324 struct epoll_copyin_args *args;
326 args = (struct epoll_copyin_args*) arg;
328 memcpy(kevp, args->changelist, count * sizeof(*kevp));
329 args->changelist += count;
335 * Load epoll filter, convert it to kevent filter
336 * and load it into kevent subsystem.
339 linux_epoll_ctl(struct thread *td, struct linux_epoll_ctl_args *args)
341 struct file *epfp, *fp;
342 struct epoll_copyin_args ciargs;
343 struct kevent kev[2];
344 struct kevent_copyops k_ops = { &ciargs,
347 struct epoll_event le;
352 if (args->op != LINUX_EPOLL_CTL_DEL) {
353 error = copyin(args->event, &le, sizeof(le));
358 error = fget(td, args->epfd,
359 cap_rights_init_one(&rights, CAP_KQUEUE_CHANGE), &epfp);
362 if (epfp->f_type != DTYPE_KQUEUE) {
367 /* Protect user data vector from incorrectly supplied fd. */
368 error = fget(td, args->fd,
369 cap_rights_init_one(&rights, CAP_POLL_EVENT), &fp);
373 /* Linux disallows spying on himself */
379 ciargs.changelist = kev;
381 if (args->op != LINUX_EPOLL_CTL_DEL) {
382 error = epoll_to_kevent(td, args->fd, &le, kev, &nchanges);
388 case LINUX_EPOLL_CTL_MOD:
389 error = epoll_delete_all_events(td, epfp, args->fd);
394 case LINUX_EPOLL_CTL_ADD:
395 if (epoll_fd_registered(td, epfp, args->fd)) {
401 case LINUX_EPOLL_CTL_DEL:
402 /* CTL_DEL means unregister this fd with this epoll */
403 error = epoll_delete_all_events(td, epfp, args->fd);
411 error = kern_kevent_fp(td, epfp, nchanges, 0, &k_ops, NULL);
422 * Wait for a filter to be triggered on the epoll file descriptor.
425 linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
426 int maxevents, int timeout, sigset_t *uset)
428 struct epoll_copyout_args coargs;
429 struct kevent_copyops k_ops = { &coargs,
432 struct timespec ts, *tsp;
438 if (maxevents <= 0 || maxevents > LINUX_MAX_EVENTS)
441 error = fget(td, epfd,
442 cap_rights_init_one(&rights, CAP_KQUEUE_EVENT), &epfp);
445 if (epfp->f_type != DTYPE_KQUEUE) {
450 error = kern_sigprocmask(td, SIG_SETMASK, uset,
454 td->td_pflags |= TDP_OLDMASK;
456 * Make sure that ast() is called on return to
457 * usermode and TDP_OLDMASK is cleared, restoring old
461 td->td_flags |= TDF_ASTPENDING;
465 coargs.leventlist = events;
466 coargs.p = td->td_proc;
471 * Linux epoll_wait(2) man page states that timeout of -1 causes caller
472 * to block indefinitely. Real implementation does it if any negative
473 * timeout value is passed.
476 /* Convert from milliseconds to timespec. */
477 ts.tv_sec = timeout / 1000;
478 ts.tv_nsec = (timeout % 1000) * 1000000;
484 error = kern_kevent_fp(td, epfp, 0, maxevents, &k_ops, tsp);
485 if (error == 0 && coargs.error != 0)
486 error = coargs.error;
489 * kern_kevent might return ENOMEM which is not expected from epoll_wait.
490 * Maybe we should translate that but I don't think it matters at all.
493 td->td_retval[0] = coargs.count;
496 error = kern_sigprocmask(td, SIG_SETMASK, &omask,
503 #ifdef LINUX_LEGACY_SYSCALLS
505 linux_epoll_wait(struct thread *td, struct linux_epoll_wait_args *args)
508 return (linux_epoll_wait_common(td, args->epfd, args->events,
509 args->maxevents, args->timeout, NULL));
514 linux_epoll_pwait(struct thread *td, struct linux_epoll_pwait_args *args)
516 sigset_t mask, *pmask;
520 if (args->mask != NULL) {
521 if (args->sigsetsize != sizeof(l_sigset_t))
523 error = copyin(args->mask, &lmask, sizeof(l_sigset_t));
526 linux_to_bsd_sigset(&lmask, &mask);
530 return (linux_epoll_wait_common(td, args->epfd, args->events,
531 args->maxevents, args->timeout, pmask));
535 epoll_register_kevent(struct thread *td, struct file *epfp, int fd, int filter,
538 struct epoll_copyin_args ciargs;
540 struct kevent_copyops k_ops = { &ciargs,
544 ciargs.changelist = &kev;
545 EV_SET(&kev, fd, filter, flags, 0, 0, 0);
547 return (kern_kevent_fp(td, epfp, 1, 0, &k_ops, NULL));
551 epoll_fd_registered(struct thread *td, struct file *epfp, int fd)
554 * Set empty filter flags to avoid accidental modification of already
555 * registered events. In the case of event re-registration:
556 * 1. If event does not exists kevent() does nothing and returns ENOENT
557 * 2. If event does exists, it's enabled/disabled state is preserved
558 * but fflags, data and udata fields are overwritten. So we can not
559 * set socket lowats and store user's context pointer in udata.
561 if (epoll_register_kevent(td, epfp, fd, EVFILT_READ, 0) != ENOENT ||
562 epoll_register_kevent(td, epfp, fd, EVFILT_WRITE, 0) != ENOENT)
569 epoll_delete_all_events(struct thread *td, struct file *epfp, int fd)
573 error1 = epoll_register_kevent(td, epfp, fd, EVFILT_READ, EV_DELETE);
574 error2 = epoll_register_kevent(td, epfp, fd, EVFILT_WRITE, EV_DELETE);
576 /* return 0 if at least one result positive */
577 return (error1 == 0 ? 0 : error2);
580 #ifdef LINUX_LEGACY_SYSCALLS
582 linux_eventfd(struct thread *td, struct linux_eventfd_args *args)
584 struct specialfd_eventfd ae;
586 bzero(&ae, sizeof(ae));
587 ae.initval = args->initval;
588 return (kern_specialfd(td, SPECIALFD_EVENTFD, &ae));
593 linux_eventfd2(struct thread *td, struct linux_eventfd2_args *args)
595 struct specialfd_eventfd ae;
598 if ((args->flags & ~(LINUX_O_CLOEXEC | LINUX_O_NONBLOCK |
599 LINUX_EFD_SEMAPHORE)) != 0)
602 if ((args->flags & LINUX_O_CLOEXEC) != 0)
603 flags |= EFD_CLOEXEC;
604 if ((args->flags & LINUX_O_NONBLOCK) != 0)
605 flags |= EFD_NONBLOCK;
606 if ((args->flags & LINUX_EFD_SEMAPHORE) != 0)
607 flags |= EFD_SEMAPHORE;
609 bzero(&ae, sizeof(ae));
611 ae.initval = args->initval;
612 return (kern_specialfd(td, SPECIALFD_EVENTFD, &ae));
616 linux_timerfd_create(struct thread *td, struct linux_timerfd_create_args *args)
621 int fflags, fd, error;
623 if ((args->flags & ~LINUX_TFD_CREATE_FLAGS) != 0)
626 error = linux_to_native_clockid(&clockid, args->clockid);
629 if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC)
633 if ((args->flags & LINUX_TFD_CLOEXEC) != 0)
636 error = falloc(td, &fp, &fd, fflags);
640 tfd = malloc(sizeof(*tfd), M_EPOLL, M_WAITOK | M_ZERO);
641 tfd->tfd_clockid = clockid;
642 mtx_init(&tfd->tfd_lock, "timerfd", NULL, MTX_DEF);
644 callout_init_mtx(&tfd->tfd_callout, &tfd->tfd_lock, 0);
645 knlist_init_mtx(&tfd->tfd_sel.si_note, &tfd->tfd_lock);
648 if ((args->flags & LINUX_O_NONBLOCK) != 0)
651 finit(fp, fflags, DTYPE_LINUXTFD, tfd, &timerfdops);
654 td->td_retval[0] = fd;
659 timerfd_close(struct file *fp, struct thread *td)
664 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
667 timespecclear(&tfd->tfd_time.it_value);
668 timespecclear(&tfd->tfd_time.it_interval);
670 callout_drain(&tfd->tfd_callout);
672 seldrain(&tfd->tfd_sel);
673 knlist_destroy(&tfd->tfd_sel.si_note);
675 fp->f_ops = &badfileops;
676 mtx_destroy(&tfd->tfd_lock);
683 timerfd_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
684 int flags, struct thread *td)
691 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
694 if (uio->uio_resid < sizeof(timerfd_t))
698 mtx_lock(&tfd->tfd_lock);
700 if (tfd->tfd_canceled) {
702 mtx_unlock(&tfd->tfd_lock);
705 if (tfd->tfd_count == 0) {
706 if ((fp->f_flag & FNONBLOCK) != 0) {
707 mtx_unlock(&tfd->tfd_lock);
710 error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock, PCATCH, "ltfdrd", 0);
715 count = tfd->tfd_count;
717 mtx_unlock(&tfd->tfd_lock);
718 error = uiomove(&count, sizeof(timerfd_t), uio);
720 mtx_unlock(&tfd->tfd_lock);
726 timerfd_poll(struct file *fp, int events, struct ucred *active_cred,
733 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
736 mtx_lock(&tfd->tfd_lock);
737 if ((events & (POLLIN|POLLRDNORM)) && tfd->tfd_count > 0)
738 revents |= events & (POLLIN|POLLRDNORM);
740 selrecord(td, &tfd->tfd_sel);
741 mtx_unlock(&tfd->tfd_lock);
747 timerfd_kqfilter(struct file *fp, struct knote *kn)
752 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
755 if (kn->kn_filter == EVFILT_READ)
756 kn->kn_fop = &timerfd_rfiltops;
761 knlist_add(&tfd->tfd_sel.si_note, kn, 0);
767 filt_timerfddetach(struct knote *kn)
769 struct timerfd *tfd = kn->kn_hook;
771 mtx_lock(&tfd->tfd_lock);
772 knlist_remove(&tfd->tfd_sel.si_note, kn, 1);
773 mtx_unlock(&tfd->tfd_lock);
777 filt_timerfdread(struct knote *kn, long hint)
779 struct timerfd *tfd = kn->kn_hook;
781 return (tfd->tfd_count > 0);
785 timerfd_ioctl(struct file *fp, u_long cmd, void *data,
786 struct ucred *active_cred, struct thread *td)
789 if (fp->f_data == NULL || fp->f_type != DTYPE_LINUXTFD)
802 timerfd_stat(struct file *fp, struct stat *st, struct ucred *active_cred)
809 timerfd_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
812 kif->kf_type = KF_TYPE_UNKNOWN;
817 linux_timerfd_clocktime(struct timerfd *tfd, struct timespec *ts)
820 if (tfd->tfd_clockid == CLOCK_REALTIME)
822 else /* CLOCK_MONOTONIC */
827 linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots)
831 linux_timerfd_clocktime(tfd, &cts);
832 *ots = tfd->tfd_time;
833 if (ots->it_value.tv_sec != 0 || ots->it_value.tv_nsec != 0) {
834 timespecsub(&ots->it_value, &cts, &ots->it_value);
835 if (ots->it_value.tv_sec < 0 ||
836 (ots->it_value.tv_sec == 0 &&
837 ots->it_value.tv_nsec == 0)) {
838 ots->it_value.tv_sec = 0;
839 ots->it_value.tv_nsec = 1;
845 linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
847 struct l_itimerspec lots;
848 struct itimerspec ots;
853 error = fget(td, args->fd, &cap_read_rights, &fp);
857 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
862 mtx_lock(&tfd->tfd_lock);
863 linux_timerfd_curval(tfd, &ots);
864 mtx_unlock(&tfd->tfd_lock);
866 error = native_to_linux_itimerspec(&lots, &ots);
868 error = copyout(&lots, args->old_value, sizeof(lots));
876 linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args)
878 struct l_itimerspec lots;
879 struct itimerspec nts, ots;
880 struct timespec cts, ts;
886 if ((args->flags & ~LINUX_TFD_SETTIME_FLAGS) != 0)
889 error = copyin(args->new_value, &lots, sizeof(lots));
892 error = linux_to_native_itimerspec(&nts, &lots);
896 error = fget(td, args->fd, &cap_write_rights, &fp);
900 if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
905 mtx_lock(&tfd->tfd_lock);
906 if (!timespecisset(&nts.it_value))
907 timespecclear(&nts.it_interval);
908 if (args->old_value != NULL)
909 linux_timerfd_curval(tfd, &ots);
913 if (timespecisset(&nts.it_value)) {
914 linux_timerfd_clocktime(tfd, &cts);
916 if ((args->flags & LINUX_TFD_TIMER_ABSTIME) == 0) {
917 timespecadd(&tfd->tfd_time.it_value, &cts,
918 &tfd->tfd_time.it_value);
920 timespecsub(&ts, &cts, &ts);
922 TIMESPEC_TO_TIMEVAL(&tv, &ts);
923 callout_reset(&tfd->tfd_callout, tvtohz(&tv),
924 linux_timerfd_expire, tfd);
925 tfd->tfd_canceled = false;
927 tfd->tfd_canceled = true;
928 callout_stop(&tfd->tfd_callout);
930 mtx_unlock(&tfd->tfd_lock);
932 if (args->old_value != NULL) {
933 error = native_to_linux_itimerspec(&lots, &ots);
935 error = copyout(&lots, args->old_value, sizeof(lots));
944 linux_timerfd_expire(void *arg)
946 struct timespec cts, ts;
950 tfd = (struct timerfd *)arg;
952 linux_timerfd_clocktime(tfd, &cts);
953 if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) {
954 if (timespecisset(&tfd->tfd_time.it_interval))
955 timespecadd(&tfd->tfd_time.it_value,
956 &tfd->tfd_time.it_interval,
957 &tfd->tfd_time.it_value);
959 /* single shot timer */
960 timespecclear(&tfd->tfd_time.it_value);
961 if (timespecisset(&tfd->tfd_time.it_value)) {
962 timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
963 TIMESPEC_TO_TIMEVAL(&tv, &ts);
964 callout_reset(&tfd->tfd_callout, tvtohz(&tv),
965 linux_timerfd_expire, tfd);
968 KNOTE_LOCKED(&tfd->tfd_sel.si_note, 0);
969 selwakeup(&tfd->tfd_sel);
970 wakeup(&tfd->tfd_count);
971 } else if (timespecisset(&tfd->tfd_time.it_value)) {
972 timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
973 TIMESPEC_TO_TIMEVAL(&tv, &ts);
974 callout_reset(&tfd->tfd_callout, tvtohz(&tv),
975 linux_timerfd_expire, tfd);