kern_select_50.c revision 1.2 1 1.2 pgoyette /* $NetBSD: kern_select_50.c,v 1.2 2019/01/27 02:08:39 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.2 pgoyette __KERNEL_RCSID(0, "$NetBSD: kern_select_50.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $");
33 1.2 pgoyette
34 1.2 pgoyette #if defined(_KERNEL_OPT)
35 1.2 pgoyette #include "opt_compat_netbsd.h"
36 1.2 pgoyette #endif
37 1.1 pooka
38 1.1 pooka #include <sys/param.h>
39 1.1 pooka #include <sys/event.h>
40 1.1 pooka #include <sys/poll.h>
41 1.1 pooka #include <sys/select.h>
42 1.1 pooka #include <sys/time.h>
43 1.2 pgoyette #include <sys/syscall.h>
44 1.2 pgoyette #include <sys/syscallvar.h>
45 1.1 pooka #include <sys/syscallargs.h>
46 1.1 pooka
47 1.1 pooka #include <compat/sys/time.h>
48 1.2 pgoyette #include <compat/common/compat_mod.h>
49 1.2 pgoyette
50 1.2 pgoyette static const struct syscall_package kern_select_50_syscalls[] = {
51 1.2 pgoyette { SYS_compat_50_kevent, 0, (sy_call_t *)compat_50_sys_kevent },
52 1.2 pgoyette { SYS_compat_50_select, 0, (sy_call_t *)compat_50_sys_select },
53 1.2 pgoyette { SYS_compat_50_pselect, 0, (sy_call_t *)compat_50_sys_pselect },
54 1.2 pgoyette { SYS_compat_50_pollts, 0, (sy_call_t *)compat_50_sys_pollts },
55 1.2 pgoyette { 0, 0, NULL }
56 1.2 pgoyette };
57 1.1 pooka
58 1.1 pooka static int
59 1.1 pooka compat_50_kevent_fetch_timeout(const void *src, void *dest, size_t length)
60 1.1 pooka {
61 1.1 pooka struct timespec50 ts50;
62 1.1 pooka int error;
63 1.1 pooka
64 1.1 pooka KASSERT(length == sizeof(struct timespec));
65 1.1 pooka
66 1.1 pooka error = copyin(src, &ts50, sizeof(ts50));
67 1.1 pooka if (error)
68 1.1 pooka return error;
69 1.1 pooka timespec50_to_timespec(&ts50, (struct timespec *)dest);
70 1.1 pooka return 0;
71 1.1 pooka }
72 1.1 pooka
73 1.1 pooka int
74 1.1 pooka compat_50_sys_kevent(struct lwp *l, const struct compat_50_sys_kevent_args *uap,
75 1.1 pooka register_t *retval)
76 1.1 pooka {
77 1.1 pooka /* {
78 1.1 pooka syscallarg(int) fd;
79 1.1 pooka syscallarg(keventp_t) changelist;
80 1.1 pooka syscallarg(size_t) nchanges;
81 1.1 pooka syscallarg(keventp_t) eventlist;
82 1.1 pooka syscallarg(size_t) nevents;
83 1.1 pooka syscallarg(struct timespec50) timeout;
84 1.1 pooka } */
85 1.1 pooka static const struct kevent_ops compat_50_kevent_ops = {
86 1.1 pooka .keo_private = NULL,
87 1.1 pooka .keo_fetch_timeout = compat_50_kevent_fetch_timeout,
88 1.1 pooka .keo_fetch_changes = kevent_fetch_changes,
89 1.1 pooka .keo_put_events = kevent_put_events,
90 1.1 pooka };
91 1.1 pooka
92 1.1 pooka return kevent1(retval, SCARG(uap, fd), SCARG(uap, changelist),
93 1.1 pooka SCARG(uap, nchanges), SCARG(uap, eventlist), SCARG(uap, nevents),
94 1.1 pooka (const struct timespec *)(const void *)SCARG(uap, timeout),
95 1.1 pooka &compat_50_kevent_ops);
96 1.1 pooka }
97 1.1 pooka
98 1.1 pooka int
99 1.1 pooka compat_50_sys_select(struct lwp *l,
100 1.1 pooka const struct compat_50_sys_select_args *uap, register_t *retval)
101 1.1 pooka {
102 1.1 pooka /* {
103 1.1 pooka syscallarg(int) nd;
104 1.1 pooka syscallarg(fd_set *) in;
105 1.1 pooka syscallarg(fd_set *) ou;
106 1.1 pooka syscallarg(fd_set *) ex;
107 1.1 pooka syscallarg(struct timeval50 *) tv;
108 1.1 pooka } */
109 1.1 pooka struct timespec ats, *ts = NULL;
110 1.1 pooka struct timeval50 atv50;
111 1.1 pooka int error;
112 1.1 pooka
113 1.1 pooka if (SCARG(uap, tv)) {
114 1.1 pooka error = copyin(SCARG(uap, tv), (void *)&atv50, sizeof(atv50));
115 1.1 pooka if (error)
116 1.1 pooka return error;
117 1.1 pooka ats.tv_sec = atv50.tv_sec;
118 1.1 pooka ats.tv_nsec = atv50.tv_usec * 1000;
119 1.1 pooka ts = &ats;
120 1.1 pooka }
121 1.1 pooka
122 1.1 pooka return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
123 1.1 pooka SCARG(uap, ou), SCARG(uap, ex), ts, NULL);
124 1.1 pooka }
125 1.1 pooka
126 1.1 pooka int
127 1.1 pooka compat_50_sys_pselect(struct lwp *l,
128 1.1 pooka const struct compat_50_sys_pselect_args *uap, register_t *retval)
129 1.1 pooka {
130 1.1 pooka /* {
131 1.1 pooka syscallarg(int) nd;
132 1.1 pooka syscallarg(fd_set *) in;
133 1.1 pooka syscallarg(fd_set *) ou;
134 1.1 pooka syscallarg(fd_set *) ex;
135 1.1 pooka syscallarg(const struct timespec50 *) ts;
136 1.1 pooka syscallarg(sigset_t *) mask;
137 1.1 pooka } */
138 1.1 pooka struct timespec50 ats50;
139 1.1 pooka struct timespec ats, *ts = NULL;
140 1.1 pooka sigset_t amask, *mask = NULL;
141 1.1 pooka int error;
142 1.1 pooka
143 1.1 pooka if (SCARG(uap, ts)) {
144 1.1 pooka error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
145 1.1 pooka if (error)
146 1.1 pooka return error;
147 1.1 pooka timespec50_to_timespec(&ats50, &ats);
148 1.1 pooka ts = &ats;
149 1.1 pooka }
150 1.1 pooka if (SCARG(uap, mask) != NULL) {
151 1.1 pooka error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
152 1.1 pooka if (error)
153 1.1 pooka return error;
154 1.1 pooka mask = &amask;
155 1.1 pooka }
156 1.1 pooka
157 1.1 pooka return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
158 1.1 pooka SCARG(uap, ou), SCARG(uap, ex), ts, mask);
159 1.1 pooka }
160 1.1 pooka
161 1.1 pooka int
162 1.1 pooka compat_50_sys_pollts(struct lwp *l, const struct compat_50_sys_pollts_args *uap,
163 1.1 pooka register_t *retval)
164 1.1 pooka {
165 1.1 pooka /* {
166 1.1 pooka syscallarg(struct pollfd *) fds;
167 1.1 pooka syscallarg(u_int) nfds;
168 1.1 pooka syscallarg(const struct timespec50 *) ts;
169 1.1 pooka syscallarg(const sigset_t *) mask;
170 1.1 pooka } */
171 1.1 pooka struct timespec ats, *ts = NULL;
172 1.1 pooka struct timespec50 ats50;
173 1.1 pooka sigset_t amask, *mask = NULL;
174 1.1 pooka int error;
175 1.1 pooka
176 1.1 pooka if (SCARG(uap, ts)) {
177 1.1 pooka error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
178 1.1 pooka if (error)
179 1.1 pooka return error;
180 1.1 pooka timespec50_to_timespec(&ats50, &ats);
181 1.1 pooka ts = &ats;
182 1.1 pooka }
183 1.1 pooka if (SCARG(uap, mask)) {
184 1.1 pooka error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
185 1.1 pooka if (error)
186 1.1 pooka return error;
187 1.1 pooka mask = &amask;
188 1.1 pooka }
189 1.1 pooka
190 1.1 pooka return pollcommon(retval, SCARG(uap, fds), SCARG(uap, nfds), ts, mask);
191 1.1 pooka }
192 1.2 pgoyette
193 1.2 pgoyette int
194 1.2 pgoyette kern_select_50_init(void)
195 1.2 pgoyette {
196 1.2 pgoyette
197 1.2 pgoyette return syscall_establish(NULL, kern_select_50_syscalls);
198 1.2 pgoyette }
199 1.2 pgoyette
200 1.2 pgoyette int
201 1.2 pgoyette kern_select_50_fini(void)
202 1.2 pgoyette {
203 1.2 pgoyette
204 1.2 pgoyette return syscall_disestablish(NULL, kern_select_50_syscalls);
205 1.2 pgoyette }
206