Home | History | Annotate | Line # | Download | only in common
kern_select_50.c revision 1.1.60.1
      1  1.1.60.1  pgoyette /*	$NetBSD: kern_select_50.c,v 1.1.60.1 2018/03/19 21:54:43 pgoyette Exp $	*/
      2       1.1     pooka 
      3       1.1     pooka /*-
      4       1.1     pooka  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
      5       1.1     pooka  * All rights reserved.
      6       1.1     pooka  *
      7       1.1     pooka  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1     pooka  * by Christos Zoulas.
      9       1.1     pooka  *
     10       1.1     pooka  * Redistribution and use in source and binary forms, with or without
     11       1.1     pooka  * modification, are permitted provided that the following conditions
     12       1.1     pooka  * are met:
     13       1.1     pooka  * 1. Redistributions of source code must retain the above copyright
     14       1.1     pooka  *    notice, this list of conditions and the following disclaimer.
     15       1.1     pooka  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     pooka  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     pooka  *    documentation and/or other materials provided with the distribution.
     18       1.1     pooka  *
     19       1.1     pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1     pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1     pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1     pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1     pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1     pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1     pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1     pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1     pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1     pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1     pooka  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1     pooka  */
     31       1.1     pooka #include <sys/cdefs.h>
     32  1.1.60.1  pgoyette __KERNEL_RCSID(0, "$NetBSD: kern_select_50.c,v 1.1.60.1 2018/03/19 21:54:43 pgoyette Exp $");
     33       1.1     pooka 
     34       1.1     pooka #include <sys/param.h>
     35       1.1     pooka #include <sys/event.h>
     36       1.1     pooka #include <sys/poll.h>
     37       1.1     pooka #include <sys/select.h>
     38       1.1     pooka #include <sys/time.h>
     39  1.1.60.1  pgoyette #include <sys/syscall.h>
     40  1.1.60.1  pgoyette #include <sys/syscallvar.h>
     41       1.1     pooka #include <sys/syscallargs.h>
     42       1.1     pooka 
     43       1.1     pooka #include <compat/sys/time.h>
     44  1.1.60.1  pgoyette #include <compat/common/compat_mod.h>
     45  1.1.60.1  pgoyette 
     46  1.1.60.1  pgoyette static const struct syscall_package kern_select_50_syscalls[] = {
     47  1.1.60.1  pgoyette 	{ SYS_compat_50_kevent, 0, (sy_call_t *)compat_50_sys_kevent },
     48  1.1.60.1  pgoyette 	{ SYS_compat_50_select, 0, (sy_call_t *)compat_50_sys_select },
     49  1.1.60.1  pgoyette 	{ SYS_compat_50_pselect, 0, (sy_call_t *)compat_50_sys_pselect },
     50  1.1.60.1  pgoyette 	{ SYS_compat_50_pollts, 0, (sy_call_t *)compat_50_sys_pollts },
     51  1.1.60.1  pgoyette 	{ 0, 0, NULL }
     52  1.1.60.1  pgoyette };
     53       1.1     pooka 
     54       1.1     pooka static int
     55       1.1     pooka compat_50_kevent_fetch_timeout(const void *src, void *dest, size_t length)
     56       1.1     pooka {
     57       1.1     pooka 	struct timespec50 ts50;
     58       1.1     pooka 	int error;
     59       1.1     pooka 
     60       1.1     pooka 	KASSERT(length == sizeof(struct timespec));
     61       1.1     pooka 
     62       1.1     pooka 	error = copyin(src, &ts50, sizeof(ts50));
     63       1.1     pooka 	if (error)
     64       1.1     pooka 		return error;
     65       1.1     pooka 	timespec50_to_timespec(&ts50, (struct timespec *)dest);
     66       1.1     pooka 	return 0;
     67       1.1     pooka }
     68       1.1     pooka 
     69       1.1     pooka int
     70       1.1     pooka compat_50_sys_kevent(struct lwp *l, const struct compat_50_sys_kevent_args *uap,
     71       1.1     pooka     register_t *retval)
     72       1.1     pooka {
     73       1.1     pooka 	/* {
     74       1.1     pooka 		syscallarg(int) fd;
     75       1.1     pooka 		syscallarg(keventp_t) changelist;
     76       1.1     pooka 		syscallarg(size_t) nchanges;
     77       1.1     pooka 		syscallarg(keventp_t) eventlist;
     78       1.1     pooka 		syscallarg(size_t) nevents;
     79       1.1     pooka 		syscallarg(struct timespec50) timeout;
     80       1.1     pooka 	} */
     81       1.1     pooka 	static const struct kevent_ops compat_50_kevent_ops = {
     82       1.1     pooka 		.keo_private = NULL,
     83       1.1     pooka 		.keo_fetch_timeout = compat_50_kevent_fetch_timeout,
     84       1.1     pooka 		.keo_fetch_changes = kevent_fetch_changes,
     85       1.1     pooka 		.keo_put_events = kevent_put_events,
     86       1.1     pooka 	};
     87       1.1     pooka 
     88       1.1     pooka 	return kevent1(retval, SCARG(uap, fd), SCARG(uap, changelist),
     89       1.1     pooka 	    SCARG(uap, nchanges), SCARG(uap, eventlist), SCARG(uap, nevents),
     90       1.1     pooka 	    (const struct timespec *)(const void *)SCARG(uap, timeout),
     91       1.1     pooka 	    &compat_50_kevent_ops);
     92       1.1     pooka }
     93       1.1     pooka 
     94       1.1     pooka int
     95       1.1     pooka compat_50_sys_select(struct lwp *l,
     96       1.1     pooka     const struct compat_50_sys_select_args *uap, register_t *retval)
     97       1.1     pooka {
     98       1.1     pooka 	/* {
     99       1.1     pooka 		syscallarg(int)			nd;
    100       1.1     pooka 		syscallarg(fd_set *)		in;
    101       1.1     pooka 		syscallarg(fd_set *)		ou;
    102       1.1     pooka 		syscallarg(fd_set *)		ex;
    103       1.1     pooka 		syscallarg(struct timeval50 *)	tv;
    104       1.1     pooka 	} */
    105       1.1     pooka 	struct timespec ats, *ts = NULL;
    106       1.1     pooka 	struct timeval50 atv50;
    107       1.1     pooka 	int error;
    108       1.1     pooka 
    109       1.1     pooka 	if (SCARG(uap, tv)) {
    110       1.1     pooka 		error = copyin(SCARG(uap, tv), (void *)&atv50, sizeof(atv50));
    111       1.1     pooka 		if (error)
    112       1.1     pooka 			return error;
    113       1.1     pooka 		ats.tv_sec = atv50.tv_sec;
    114       1.1     pooka 		ats.tv_nsec = atv50.tv_usec * 1000;
    115       1.1     pooka 		ts = &ats;
    116       1.1     pooka 	}
    117       1.1     pooka 
    118       1.1     pooka 	return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
    119       1.1     pooka 	    SCARG(uap, ou), SCARG(uap, ex), ts, NULL);
    120       1.1     pooka }
    121       1.1     pooka 
    122       1.1     pooka int
    123       1.1     pooka compat_50_sys_pselect(struct lwp *l,
    124       1.1     pooka     const struct compat_50_sys_pselect_args *uap, register_t *retval)
    125       1.1     pooka {
    126       1.1     pooka 	/* {
    127       1.1     pooka 		syscallarg(int)				nd;
    128       1.1     pooka 		syscallarg(fd_set *)			in;
    129       1.1     pooka 		syscallarg(fd_set *)			ou;
    130       1.1     pooka 		syscallarg(fd_set *)			ex;
    131       1.1     pooka 		syscallarg(const struct timespec50 *)	ts;
    132       1.1     pooka 		syscallarg(sigset_t *)			mask;
    133       1.1     pooka 	} */
    134       1.1     pooka 	struct timespec50	ats50;
    135       1.1     pooka 	struct timespec	ats, *ts = NULL;
    136       1.1     pooka 	sigset_t	amask, *mask = NULL;
    137       1.1     pooka 	int		error;
    138       1.1     pooka 
    139       1.1     pooka 	if (SCARG(uap, ts)) {
    140       1.1     pooka 		error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
    141       1.1     pooka 		if (error)
    142       1.1     pooka 			return error;
    143       1.1     pooka 		timespec50_to_timespec(&ats50, &ats);
    144       1.1     pooka 		ts = &ats;
    145       1.1     pooka 	}
    146       1.1     pooka 	if (SCARG(uap, mask) != NULL) {
    147       1.1     pooka 		error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
    148       1.1     pooka 		if (error)
    149       1.1     pooka 			return error;
    150       1.1     pooka 		mask = &amask;
    151       1.1     pooka 	}
    152       1.1     pooka 
    153       1.1     pooka 	return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
    154       1.1     pooka 	    SCARG(uap, ou), SCARG(uap, ex), ts, mask);
    155       1.1     pooka }
    156       1.1     pooka 
    157       1.1     pooka int
    158       1.1     pooka compat_50_sys_pollts(struct lwp *l, const struct compat_50_sys_pollts_args *uap,
    159       1.1     pooka     register_t *retval)
    160       1.1     pooka {
    161       1.1     pooka 	/* {
    162       1.1     pooka 		syscallarg(struct pollfd *)		fds;
    163       1.1     pooka 		syscallarg(u_int)			nfds;
    164       1.1     pooka 		syscallarg(const struct timespec50 *)	ts;
    165       1.1     pooka 		syscallarg(const sigset_t *)		mask;
    166       1.1     pooka 	} */
    167       1.1     pooka 	struct timespec	ats, *ts = NULL;
    168       1.1     pooka 	struct timespec50 ats50;
    169       1.1     pooka 	sigset_t	amask, *mask = NULL;
    170       1.1     pooka 	int		error;
    171       1.1     pooka 
    172       1.1     pooka 	if (SCARG(uap, ts)) {
    173       1.1     pooka 		error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
    174       1.1     pooka 		if (error)
    175       1.1     pooka 			return error;
    176       1.1     pooka 		timespec50_to_timespec(&ats50, &ats);
    177       1.1     pooka 		ts = &ats;
    178       1.1     pooka 	}
    179       1.1     pooka 	if (SCARG(uap, mask)) {
    180       1.1     pooka 		error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
    181       1.1     pooka 		if (error)
    182       1.1     pooka 			return error;
    183       1.1     pooka 		mask = &amask;
    184       1.1     pooka 	}
    185       1.1     pooka 
    186       1.1     pooka 	return pollcommon(retval, SCARG(uap, fds), SCARG(uap, nfds), ts, mask);
    187       1.1     pooka }
    188  1.1.60.1  pgoyette 
    189  1.1.60.1  pgoyette int
    190  1.1.60.1  pgoyette kern_select_50_init(void)
    191  1.1.60.1  pgoyette {
    192  1.1.60.1  pgoyette 
    193  1.1.60.1  pgoyette return syscall_establish(NULL, kern_select_50_syscalls);
    194  1.1.60.1  pgoyette }
    195  1.1.60.1  pgoyette 
    196  1.1.60.1  pgoyette int
    197  1.1.60.1  pgoyette kern_select_50_fini(void)
    198  1.1.60.1  pgoyette {
    199  1.1.60.1  pgoyette 
    200  1.1.60.1  pgoyette return syscall_disestablish(NULL, kern_select_50_syscalls);
    201  1.1.60.1  pgoyette }
    202