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