netbsd32_compat_50.c revision 1.3 1 1.3 njoly /* $NetBSD: netbsd32_compat_50.c,v 1.3 2009/01/26 13:00:04 njoly Exp $ */
2 1.2 christos
3 1.2 christos /*-
4 1.2 christos * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.2 christos * All rights reserved.
6 1.2 christos *
7 1.2 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.2 christos * by Christos Zoulas.
9 1.2 christos *
10 1.2 christos * Redistribution and use in source and binary forms, with or without
11 1.2 christos * modification, are permitted provided that the following conditions
12 1.2 christos * are met:
13 1.2 christos * 1. Redistributions of source code must retain the above copyright
14 1.2 christos * notice, this list of conditions and the following disclaimer.
15 1.2 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 christos * notice, this list of conditions and the following disclaimer in the
17 1.2 christos * documentation and/or other materials provided with the distribution.
18 1.2 christos * 3. All advertising materials mentioning features or use of this software
19 1.2 christos * must display the following acknowledgement:
20 1.2 christos * This product includes software developed by the NetBSD
21 1.2 christos * Foundation, Inc. and its contributors.
22 1.2 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 christos * contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.2 christos */
38 1.2 christos #include <sys/cdefs.h>
39 1.3 njoly __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.3 2009/01/26 13:00:04 njoly Exp $");
40 1.2 christos
41 1.2 christos #if defined(_KERNEL_OPT)
42 1.2 christos #include "opt_sysv.h"
43 1.2 christos #endif
44 1.2 christos
45 1.2 christos #include "fs_lfs.h"
46 1.2 christos
47 1.2 christos #include <sys/param.h>
48 1.2 christos #include <sys/systm.h>
49 1.2 christos #include <sys/malloc.h>
50 1.2 christos #include <sys/mount.h>
51 1.2 christos #include <sys/socket.h>
52 1.2 christos #include <sys/socketvar.h>
53 1.2 christos #include <sys/stat.h>
54 1.2 christos #include <sys/time.h>
55 1.2 christos #include <sys/ktrace.h>
56 1.2 christos #include <sys/eventvar.h>
57 1.2 christos #include <sys/resourcevar.h>
58 1.2 christos #include <sys/vnode.h>
59 1.2 christos #include <sys/file.h>
60 1.2 christos #include <sys/filedesc.h>
61 1.2 christos #include <sys/poll.h>
62 1.2 christos #include <sys/namei.h>
63 1.2 christos #include <sys/statvfs.h>
64 1.2 christos #include <sys/syscallargs.h>
65 1.2 christos #include <sys/proc.h>
66 1.2 christos #include <sys/dirent.h>
67 1.2 christos #include <sys/kauth.h>
68 1.2 christos #include <sys/vfs_syscalls.h>
69 1.2 christos #include <sys/ipc.h>
70 1.2 christos #include <sys/msg.h>
71 1.2 christos #include <sys/sem.h>
72 1.2 christos #include <sys/shm.h>
73 1.2 christos
74 1.2 christos #include <compat/netbsd32/netbsd32.h>
75 1.2 christos #include <compat/netbsd32/netbsd32_syscallargs.h>
76 1.2 christos #include <compat/netbsd32/netbsd32_conv.h>
77 1.2 christos #include <compat/sys/mount.h>
78 1.2 christos #include <compat/sys/time.h>
79 1.2 christos
80 1.2 christos
81 1.2 christos /*
82 1.2 christos * Common routine to set access and modification times given a vnode.
83 1.2 christos */
84 1.2 christos static int
85 1.2 christos get_utimes32(const netbsd32_timeval50p_t *tptr, struct timeval *tv,
86 1.2 christos struct timeval **tvp)
87 1.2 christos {
88 1.2 christos int error;
89 1.2 christos struct netbsd32_timeval50 tv32[2];
90 1.2 christos
91 1.2 christos if (tptr == NULL) {
92 1.2 christos *tvp = NULL;
93 1.2 christos return 0;
94 1.2 christos }
95 1.2 christos
96 1.2 christos error = copyin(tptr, tv32, sizeof(tv32));
97 1.2 christos if (error)
98 1.2 christos return error;
99 1.2 christos netbsd32_to_timeval50(&tv32[0], &tv[0]);
100 1.2 christos netbsd32_to_timeval50(&tv32[1], &tv[1]);
101 1.2 christos
102 1.2 christos *tvp = tv;
103 1.2 christos return 0;
104 1.2 christos }
105 1.2 christos
106 1.2 christos int
107 1.2 christos compat_50_netbsd32_mknod(struct lwp *l,
108 1.2 christos const struct compat_50_netbsd32_mknod_args *uap, register_t *retval)
109 1.2 christos {
110 1.2 christos /* {
111 1.2 christos syscallarg(netbsd32_charp) path;
112 1.2 christos syscallarg(mode_t) mode;
113 1.2 christos syscallarg(uint32_t) dev;
114 1.2 christos } */
115 1.2 christos return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
116 1.2 christos SCARG(uap, dev), retval);
117 1.2 christos }
118 1.2 christos
119 1.2 christos int
120 1.2 christos compat_50_netbsd32_select(struct lwp *l,
121 1.2 christos const struct compat_50_netbsd32_select_args *uap, register_t *retval)
122 1.2 christos {
123 1.2 christos /* {
124 1.2 christos syscallarg(int) nd;
125 1.2 christos syscallarg(netbsd32_fd_setp_t) in;
126 1.2 christos syscallarg(netbsd32_fd_setp_t) ou;
127 1.2 christos syscallarg(netbsd32_fd_setp_t) ex;
128 1.2 christos syscallarg(netbsd32_timeval50p_t) tv;
129 1.2 christos } */
130 1.2 christos int error;
131 1.2 christos struct netbsd32_timeval50 tv32;
132 1.2 christos struct timeval atv, *tv = NULL;
133 1.2 christos
134 1.2 christos if (SCARG_P32(uap, tv)) {
135 1.2 christos error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
136 1.2 christos if (error != 0)
137 1.2 christos return error;
138 1.2 christos netbsd32_to_timeval50(&tv32, &atv);
139 1.2 christos tv = &atv;
140 1.2 christos }
141 1.2 christos
142 1.2 christos return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in),
143 1.2 christos SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, NULL);
144 1.2 christos return 0;
145 1.2 christos }
146 1.2 christos
147 1.2 christos int
148 1.2 christos compat_50_netbsd32_gettimeofday(struct lwp *l,
149 1.2 christos const struct compat_50_netbsd32_gettimeofday_args *uap, register_t *retval)
150 1.2 christos {
151 1.2 christos /* {
152 1.2 christos syscallarg(netbsd32_timeval50p_t) tp;
153 1.2 christos syscallarg(netbsd32_timezonep_t) tzp;
154 1.2 christos } */
155 1.2 christos struct timeval atv;
156 1.2 christos struct netbsd32_timeval50 tv32;
157 1.2 christos int error = 0;
158 1.2 christos struct netbsd32_timezone tzfake;
159 1.2 christos
160 1.2 christos if (SCARG_P32(uap, tp)) {
161 1.2 christos microtime(&atv);
162 1.2 christos netbsd32_from_timeval50(&atv, &tv32);
163 1.2 christos error = copyout(&tv32, SCARG_P32(uap, tp), sizeof(tv32));
164 1.2 christos if (error)
165 1.2 christos return error;
166 1.2 christos }
167 1.2 christos if (SCARG_P32(uap, tzp)) {
168 1.2 christos /*
169 1.2 christos * NetBSD has no kernel notion of time zone, so we just
170 1.2 christos * fake up a timezone struct and return it if demanded.
171 1.2 christos */
172 1.2 christos tzfake.tz_minuteswest = 0;
173 1.2 christos tzfake.tz_dsttime = 0;
174 1.2 christos error = copyout(&tzfake, SCARG_P32(uap, tzp), sizeof(tzfake));
175 1.2 christos }
176 1.2 christos return error;
177 1.2 christos }
178 1.2 christos
179 1.2 christos int
180 1.2 christos compat_50_netbsd32_settimeofday(struct lwp *l,
181 1.2 christos const struct compat_50_netbsd32_settimeofday_args *uap, register_t *retval)
182 1.2 christos {
183 1.2 christos /* {
184 1.2 christos syscallarg(const netbsd32_timeval50p_t) tv;
185 1.2 christos syscallarg(const netbsd32_timezonep_t) tzp;
186 1.2 christos } */
187 1.2 christos struct netbsd32_timeval50 atv32;
188 1.2 christos struct timeval atv;
189 1.2 christos struct timespec ats;
190 1.2 christos int error;
191 1.2 christos struct proc *p = l->l_proc;
192 1.2 christos
193 1.2 christos /* Verify all parameters before changing time. */
194 1.2 christos
195 1.2 christos /*
196 1.2 christos * NetBSD has no kernel notion of time zone, and only an
197 1.2 christos * obsolete program would try to set it, so we log a warning.
198 1.2 christos */
199 1.2 christos if (SCARG_P32(uap, tzp))
200 1.2 christos printf("pid %d attempted to set the "
201 1.2 christos "(obsolete) kernel time zone\n", p->p_pid);
202 1.2 christos
203 1.2 christos if (SCARG_P32(uap, tv) == 0)
204 1.2 christos return 0;
205 1.2 christos
206 1.2 christos if ((error = copyin(SCARG_P32(uap, tv), &atv32, sizeof(atv32))) != 0)
207 1.2 christos return error;
208 1.2 christos
209 1.2 christos netbsd32_to_timeval50(&atv32, &atv);
210 1.2 christos TIMEVAL_TO_TIMESPEC(&atv, &ats);
211 1.2 christos return settime(p, &ats);
212 1.2 christos }
213 1.2 christos
214 1.2 christos int
215 1.2 christos compat_50_netbsd32_utimes(struct lwp *l,
216 1.2 christos const struct compat_50_netbsd32_utimes_args *uap, register_t *retval)
217 1.2 christos {
218 1.2 christos /* {
219 1.2 christos syscallarg(const netbsd32_charp) path;
220 1.2 christos syscallarg(const netbsd32_timeval50p_t) tptr;
221 1.2 christos } */
222 1.2 christos int error;
223 1.2 christos struct timeval tv[2], *tvp;
224 1.2 christos
225 1.2 christos error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
226 1.2 christos if (error != 0)
227 1.2 christos return error;
228 1.2 christos
229 1.2 christos return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
230 1.2 christos tvp, UIO_SYSSPACE);
231 1.2 christos }
232 1.2 christos
233 1.2 christos int
234 1.2 christos compat_50_netbsd32_adjtime(struct lwp *l,
235 1.2 christos const struct compat_50_netbsd32_adjtime_args *uap, register_t *retval)
236 1.2 christos {
237 1.2 christos /* {
238 1.2 christos syscallarg(const netbsd32_timeval50p_t) delta;
239 1.2 christos syscallarg(netbsd32_timeval50p_t) olddelta;
240 1.2 christos } */
241 1.2 christos struct netbsd32_timeval50 atv;
242 1.2 christos int error;
243 1.2 christos
244 1.2 christos extern int time_adjusted; /* in kern_ntptime.c */
245 1.2 christos extern int64_t time_adjtime; /* in kern_ntptime.c */
246 1.2 christos
247 1.2 christos if ((error = kauth_authorize_system(l->l_cred,
248 1.2 christos KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL,
249 1.2 christos NULL)) != 0)
250 1.2 christos return (error);
251 1.2 christos
252 1.2 christos if (SCARG_P32(uap, olddelta)) {
253 1.2 christos atv.tv_sec = time_adjtime / 1000000;
254 1.2 christos atv.tv_usec = time_adjtime % 1000000;
255 1.2 christos if (atv.tv_usec < 0) {
256 1.2 christos atv.tv_usec += 1000000;
257 1.2 christos atv.tv_sec--;
258 1.2 christos }
259 1.2 christos (void) copyout(&atv,
260 1.2 christos SCARG_P32(uap, olddelta),
261 1.2 christos sizeof(atv));
262 1.2 christos if (error)
263 1.2 christos return (error);
264 1.2 christos }
265 1.2 christos
266 1.2 christos if (SCARG_P32(uap, delta)) {
267 1.2 christos error = copyin(SCARG_P32(uap, delta), &atv,
268 1.2 christos sizeof(struct timeval));
269 1.2 christos if (error)
270 1.2 christos return (error);
271 1.2 christos
272 1.2 christos time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
273 1.2 christos
274 1.2 christos if (time_adjtime)
275 1.2 christos /* We need to save the system time during shutdown */
276 1.2 christos time_adjusted |= 1;
277 1.2 christos }
278 1.2 christos
279 1.2 christos return 0;
280 1.2 christos }
281 1.2 christos
282 1.2 christos #if defined(LFS) || !defined(_KERNEL)
283 1.2 christos int
284 1.2 christos compat_50_netbsd32_lfs_segwait(struct lwp *l,
285 1.2 christos const struct compat_50_netbsd32_lfs_segwait_args *uap, register_t *retval)
286 1.2 christos {
287 1.2 christos return 0;
288 1.2 christos }
289 1.2 christos #endif
290 1.2 christos
291 1.2 christos int
292 1.2 christos compat_50_netbsd32_futimes(struct lwp *l,
293 1.2 christos const struct compat_50_netbsd32_futimes_args *uap, register_t *retval)
294 1.2 christos {
295 1.2 christos /* {
296 1.2 christos syscallarg(int) fd;
297 1.2 christos syscallarg(const netbsd32_timeval50p_t) tptr;
298 1.2 christos } */
299 1.2 christos int error;
300 1.2 christos file_t *fp;
301 1.2 christos struct timeval tv[2], *tvp;
302 1.2 christos
303 1.2 christos error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
304 1.2 christos if (error != 0)
305 1.2 christos return error;
306 1.2 christos
307 1.2 christos /* fd_getvnode() will use the descriptor for us */
308 1.2 christos if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
309 1.2 christos return error;
310 1.2 christos
311 1.2 christos error = do_sys_utimes(l, fp->f_data, NULL, 0, tvp, UIO_SYSSPACE);
312 1.2 christos
313 1.2 christos fd_putfile(SCARG(uap, fd));
314 1.2 christos return error;
315 1.2 christos }
316 1.2 christos
317 1.2 christos int
318 1.2 christos compat_50_netbsd32_clock_gettime(struct lwp *l,
319 1.2 christos const struct compat_50_netbsd32_clock_gettime_args *uap, register_t *retval)
320 1.2 christos {
321 1.2 christos /* {
322 1.2 christos syscallarg(netbsd32_clockid_t) clock_id;
323 1.2 christos syscallarg(netbsd32_timespec50p_t) tp;
324 1.2 christos } */
325 1.2 christos clockid_t clock_id;
326 1.2 christos struct timespec ats;
327 1.2 christos struct netbsd32_timespec50 ts32;
328 1.2 christos
329 1.2 christos clock_id = SCARG(uap, clock_id);
330 1.2 christos if (clock_id != CLOCK_REALTIME)
331 1.2 christos return (EINVAL);
332 1.2 christos
333 1.2 christos nanotime(&ats);
334 1.2 christos netbsd32_from_timespec50(&ats, &ts32);
335 1.2 christos
336 1.2 christos return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
337 1.2 christos }
338 1.2 christos
339 1.2 christos int
340 1.2 christos compat_50_netbsd32_clock_settime(struct lwp *l,
341 1.2 christos const struct compat_50_netbsd32_clock_settime_args *uap, register_t *retval)
342 1.2 christos {
343 1.2 christos /* {
344 1.2 christos syscallarg(netbsd32_clockid_t) clock_id;
345 1.2 christos syscallarg(const netbsd32_timespec50p_t) tp;
346 1.2 christos } */
347 1.2 christos struct netbsd32_timespec50 ts32;
348 1.2 christos clockid_t clock_id;
349 1.2 christos struct timespec ats;
350 1.2 christos int error;
351 1.2 christos
352 1.2 christos clock_id = SCARG(uap, clock_id);
353 1.2 christos if (clock_id != CLOCK_REALTIME)
354 1.2 christos return (EINVAL);
355 1.2 christos
356 1.2 christos if ((error = copyin(SCARG_P32(uap, tp), &ts32, sizeof(ts32))) != 0)
357 1.2 christos return (error);
358 1.2 christos
359 1.2 christos netbsd32_to_timespec50(&ts32, &ats);
360 1.2 christos return settime(l->l_proc, &ats);
361 1.2 christos }
362 1.2 christos
363 1.2 christos int
364 1.2 christos compat_50_netbsd32_clock_getres(struct lwp *l,
365 1.2 christos const struct compat_50_netbsd32_clock_getres_args *uap, register_t *retval)
366 1.2 christos {
367 1.2 christos /* {
368 1.2 christos syscallarg(netbsd32_clockid_t) clock_id;
369 1.2 christos syscallarg(netbsd32_timespec50p_t) tp;
370 1.2 christos } */
371 1.2 christos struct netbsd32_timespec50 ts32;
372 1.2 christos clockid_t clock_id;
373 1.2 christos struct timespec ts;
374 1.2 christos int error = 0;
375 1.2 christos
376 1.2 christos clock_id = SCARG(uap, clock_id);
377 1.2 christos if (clock_id != CLOCK_REALTIME)
378 1.2 christos return (EINVAL);
379 1.2 christos
380 1.2 christos if (SCARG_P32(uap, tp)) {
381 1.2 christos ts.tv_sec = 0;
382 1.2 christos ts.tv_nsec = 1000000000 / hz;
383 1.2 christos
384 1.2 christos netbsd32_from_timespec50(&ts, &ts32);
385 1.2 christos error = copyout(&ts, SCARG_P32(uap, tp), sizeof(ts));
386 1.2 christos }
387 1.2 christos
388 1.2 christos return error;
389 1.2 christos }
390 1.2 christos
391 1.2 christos int
392 1.2 christos compat_50_netbsd32_timer_settime(struct lwp *l,
393 1.2 christos const struct compat_50_netbsd32_timer_settime_args *uap, register_t *retval)
394 1.2 christos {
395 1.2 christos /* {
396 1.2 christos syscallarg(netbsd32_timer_t) timerid;
397 1.2 christos syscallarg(int) flags;
398 1.2 christos syscallarg(const netbsd32_itimerspec50p_t) value;
399 1.2 christos syscallarg(netbsd32_itimerspec50p_t) ovalue;
400 1.2 christos } */
401 1.2 christos int error;
402 1.2 christos struct itimerspec value, ovalue, *ovp = NULL;
403 1.2 christos struct netbsd32_itimerspec50 its32;
404 1.2 christos
405 1.2 christos if ((error = copyin(SCARG_P32(uap, value), &its32, sizeof(its32))) != 0)
406 1.2 christos return (error);
407 1.2 christos netbsd32_to_timespec50(&its32.it_interval, &value.it_interval);
408 1.2 christos netbsd32_to_timespec50(&its32.it_value, &value.it_value);
409 1.2 christos
410 1.2 christos if (SCARG_P32(uap, ovalue))
411 1.2 christos ovp = &ovalue;
412 1.2 christos
413 1.2 christos if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
414 1.2 christos SCARG(uap, flags), l->l_proc)) != 0)
415 1.2 christos return error;
416 1.2 christos
417 1.2 christos if (ovp) {
418 1.2 christos netbsd32_from_timespec50(&ovp->it_interval, &its32.it_interval);
419 1.2 christos netbsd32_from_timespec50(&ovp->it_value, &its32.it_value);
420 1.2 christos return copyout(&its32, SCARG_P32(uap, ovalue), sizeof(its32));
421 1.2 christos }
422 1.2 christos return 0;
423 1.2 christos }
424 1.2 christos
425 1.2 christos int
426 1.2 christos compat_50_netbsd32_timer_gettime(struct lwp *l, const struct compat_50_netbsd32_timer_gettime_args *uap, register_t *retval)
427 1.2 christos {
428 1.2 christos /* {
429 1.2 christos syscallarg(netbsd32_timer_t) timerid;
430 1.2 christos syscallarg(netbsd32_itimerspec50p_t) value;
431 1.2 christos } */
432 1.2 christos int error;
433 1.2 christos struct itimerspec its;
434 1.2 christos struct netbsd32_itimerspec50 its32;
435 1.2 christos
436 1.2 christos if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
437 1.2 christos &its)) != 0)
438 1.2 christos return error;
439 1.2 christos
440 1.2 christos netbsd32_from_timespec50(&its.it_interval, &its32.it_interval);
441 1.2 christos netbsd32_from_timespec50(&its.it_value, &its32.it_value);
442 1.2 christos
443 1.2 christos return copyout(&its32, SCARG_P32(uap, value), sizeof(its32));
444 1.2 christos }
445 1.2 christos
446 1.2 christos int
447 1.2 christos compat_50_netbsd32_nanosleep(struct lwp *l,
448 1.2 christos const struct compat_50_netbsd32_nanosleep_args *uap, register_t *retval)
449 1.2 christos {
450 1.2 christos /* {
451 1.2 christos syscallarg(const netbsd32_timespec50p_t) rqtp;
452 1.2 christos syscallarg(netbsd32_timespecp_t) rmtp;
453 1.2 christos } */
454 1.2 christos static int nanowait;
455 1.2 christos struct netbsd32_timespec50 ts32;
456 1.2 christos struct timespec rqt, ctime, rmt;
457 1.2 christos int error, timo;
458 1.2 christos
459 1.2 christos error = copyin(SCARG_P32(uap, rqtp), &ts32, sizeof(ts32));
460 1.2 christos if (error)
461 1.2 christos return (error);
462 1.2 christos
463 1.2 christos netbsd32_to_timespec50(&ts32, &rqt);
464 1.2 christos if (itimespecfix(&rqt))
465 1.2 christos return (EINVAL);
466 1.2 christos
467 1.2 christos getnanotime(&ctime);
468 1.2 christos timespecadd(&rqt, &ctime, &rqt);
469 1.2 christos timo = tshzto(&rqt);
470 1.2 christos /*
471 1.2 christos * Avoid inadvertantly sleeping forever
472 1.2 christos */
473 1.2 christos if (timo == 0)
474 1.2 christos timo = 1;
475 1.2 christos
476 1.2 christos error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
477 1.2 christos if (error == ERESTART)
478 1.2 christos error = EINTR;
479 1.2 christos if (error == EWOULDBLOCK)
480 1.2 christos error = 0;
481 1.2 christos
482 1.2 christos if (SCARG_P32(uap, rmtp)) {
483 1.2 christos int error1;
484 1.2 christos
485 1.2 christos getnanotime(&rmt);
486 1.2 christos
487 1.2 christos timespecsub(&rqt, &rmt, &rmt);
488 1.2 christos if (rmt.tv_sec < 0)
489 1.2 christos timespecclear(&rmt);
490 1.2 christos
491 1.2 christos netbsd32_from_timespec50(&rmt, &ts32);
492 1.2 christos error1 = copyout(&ts32, SCARG_P32(uap,rmtp), sizeof(ts32));
493 1.2 christos if (error1)
494 1.2 christos return (error1);
495 1.2 christos }
496 1.2 christos
497 1.2 christos return error;
498 1.2 christos }
499 1.2 christos
500 1.2 christos static int
501 1.2 christos compat_50_netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
502 1.2 christos {
503 1.2 christos const siginfo_t *info = src;
504 1.2 christos siginfo32_t info32;
505 1.2 christos
506 1.2 christos netbsd32_si_to_si32(&info32, info);
507 1.2 christos
508 1.2 christos return copyout(&info32, dst, sizeof(info32));
509 1.2 christos }
510 1.2 christos
511 1.2 christos static int
512 1.2 christos compat_50_netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
513 1.2 christos {
514 1.2 christos struct timespec *ts = dst;
515 1.2 christos struct netbsd32_timespec50 ts32;
516 1.2 christos int error;
517 1.2 christos
518 1.2 christos error = copyin(src, &ts32, sizeof(ts32));
519 1.2 christos if (error)
520 1.2 christos return error;
521 1.2 christos
522 1.2 christos netbsd32_to_timespec50(&ts32, ts);
523 1.2 christos return 0;
524 1.2 christos }
525 1.2 christos
526 1.2 christos static int
527 1.2 christos compat_50_netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
528 1.2 christos {
529 1.2 christos const struct timespec *ts = src;
530 1.2 christos struct netbsd32_timespec50 ts32;
531 1.2 christos
532 1.2 christos netbsd32_from_timespec50(ts, &ts32);
533 1.2 christos
534 1.2 christos return copyout(&ts32, dst, sizeof(ts32));
535 1.2 christos }
536 1.2 christos
537 1.2 christos int
538 1.2 christos compat_50_netbsd32___sigtimedwait(struct lwp *l,
539 1.2 christos const struct compat_50_netbsd32___sigtimedwait_args *uap, register_t *retval)
540 1.2 christos {
541 1.2 christos /* {
542 1.2 christos syscallarg(netbsd32_sigsetp_t) set;
543 1.2 christos syscallarg(netbsd32_siginfop_t) info;
544 1.2 christos syscallarg(netbsd32_timespec50p_t) timeout;
545 1.2 christos } */
546 1.2 christos struct sys_____sigtimedwait50_args ua;
547 1.2 christos
548 1.2 christos NETBSD32TOP_UAP(set, const sigset_t);
549 1.2 christos NETBSD32TOP_UAP(info, siginfo_t);
550 1.2 christos NETBSD32TOP_UAP(timeout, struct timespec);
551 1.2 christos
552 1.2 christos return __sigtimedwait1(l, &ua, retval,
553 1.2 christos compat_50_netbsd32_sigtimedwait_put_info,
554 1.2 christos compat_50_netbsd32_sigtimedwait_fetch_timeout,
555 1.2 christos compat_50_netbsd32_sigtimedwait_put_timeout);
556 1.2 christos return 0;
557 1.2 christos }
558 1.2 christos
559 1.2 christos int
560 1.2 christos compat_50_netbsd32_lutimes(struct lwp *l,
561 1.2 christos const struct compat_50_netbsd32_lutimes_args *uap, register_t *retval)
562 1.2 christos {
563 1.2 christos /* {
564 1.2 christos syscallarg(const netbsd32_charp) path;
565 1.2 christos syscallarg(const netbsd32_timeval50p_t) tptr;
566 1.2 christos } */
567 1.2 christos int error;
568 1.2 christos struct timeval tv[2], *tvp;
569 1.2 christos
570 1.2 christos error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
571 1.2 christos if (error != 0)
572 1.2 christos return error;
573 1.2 christos
574 1.2 christos return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
575 1.2 christos tvp, UIO_SYSSPACE);
576 1.2 christos }
577 1.2 christos
578 1.2 christos int
579 1.2 christos compat_50_netbsd32__lwp_park(struct lwp *l,
580 1.2 christos const struct compat_50_netbsd32__lwp_park_args *uap, register_t *retval)
581 1.2 christos {
582 1.2 christos /* {
583 1.2 christos syscallarg(const netbsd32_timespec50p) ts;
584 1.2 christos syscallarg(lwpid_t) unpark;
585 1.2 christos syscallarg(netbsd32_voidp) hint;
586 1.2 christos syscallarg(netbsd32_voidp) unparkhint;
587 1.2 christos } */
588 1.2 christos struct timespec ts, *tsp;
589 1.2 christos struct netbsd32_timespec50 ts32;
590 1.2 christos int error;
591 1.2 christos
592 1.2 christos if (SCARG_P32(uap, ts) == NULL)
593 1.2 christos tsp = NULL;
594 1.2 christos else {
595 1.2 christos error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
596 1.2 christos if (error != 0)
597 1.2 christos return error;
598 1.2 christos netbsd32_to_timespec50(&ts32, &ts);
599 1.2 christos tsp = &ts;
600 1.2 christos }
601 1.2 christos
602 1.2 christos if (SCARG(uap, unpark) != 0) {
603 1.2 christos error = lwp_unpark(SCARG(uap, unpark),
604 1.2 christos SCARG_P32(uap, unparkhint));
605 1.2 christos if (error != 0)
606 1.2 christos return error;
607 1.2 christos }
608 1.2 christos
609 1.2 christos return lwp_park(tsp, SCARG_P32(uap, hint));
610 1.2 christos return 0;
611 1.2 christos }
612 1.2 christos
613 1.2 christos static int
614 1.2 christos netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
615 1.2 christos {
616 1.2 christos struct netbsd32_timespec50 ts32;
617 1.2 christos int error;
618 1.2 christos
619 1.2 christos KASSERT(length == sizeof(struct timespec50));
620 1.2 christos
621 1.2 christos error = copyin(src, &ts32, sizeof(ts32));
622 1.2 christos if (error)
623 1.2 christos return error;
624 1.2 christos netbsd32_to_timespec50(&ts32, (struct timespec *)dest);
625 1.2 christos return 0;
626 1.2 christos }
627 1.2 christos
628 1.2 christos static int
629 1.2 christos netbsd32_kevent_fetch_changes(void *private, const struct kevent *changelist,
630 1.2 christos struct kevent *changes, size_t index, int n)
631 1.2 christos {
632 1.2 christos const struct netbsd32_kevent *src =
633 1.2 christos (const struct netbsd32_kevent *)changelist;
634 1.2 christos struct netbsd32_kevent *kev32, *changes32 = private;
635 1.2 christos int error, i;
636 1.2 christos
637 1.2 christos error = copyin(src + index, changes32, n * sizeof(*changes32));
638 1.2 christos if (error)
639 1.2 christos return error;
640 1.2 christos for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
641 1.2 christos netbsd32_to_kevent(kev32, changes);
642 1.2 christos return 0;
643 1.2 christos }
644 1.2 christos
645 1.2 christos static int
646 1.2 christos netbsd32_kevent_put_events(void *private, struct kevent *events,
647 1.2 christos struct kevent *eventlist, size_t index, int n)
648 1.2 christos {
649 1.2 christos struct netbsd32_kevent *kev32, *events32 = private;
650 1.2 christos int i;
651 1.2 christos
652 1.2 christos for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
653 1.2 christos netbsd32_from_kevent(events, kev32);
654 1.2 christos kev32 = (struct netbsd32_kevent *)eventlist;
655 1.2 christos return copyout(events32, kev32, n * sizeof(*events32));
656 1.2 christos }
657 1.2 christos
658 1.2 christos int
659 1.2 christos compat_50_netbsd32_kevent(struct lwp *l,
660 1.2 christos const struct compat_50_netbsd32_kevent_args *uap, register_t *retval)
661 1.2 christos {
662 1.2 christos /* {
663 1.2 christos syscallarg(int) fd;
664 1.2 christos syscallarg(netbsd32_keventp_t) changelist;
665 1.2 christos syscallarg(netbsd32_size_t) nchanges;
666 1.2 christos syscallarg(netbsd32_keventp_t) eventlist;
667 1.2 christos syscallarg(netbsd32_size_t) nevents;
668 1.2 christos syscallarg(netbsd32_timespec50p_t) timeout;
669 1.2 christos } */
670 1.2 christos int error;
671 1.2 christos size_t maxalloc, nchanges, nevents;
672 1.2 christos struct kevent_ops netbsd32_kevent_ops = {
673 1.2 christos keo_fetch_timeout: netbsd32_kevent_fetch_timeout,
674 1.2 christos keo_fetch_changes: netbsd32_kevent_fetch_changes,
675 1.2 christos keo_put_events: netbsd32_kevent_put_events,
676 1.2 christos };
677 1.2 christos
678 1.2 christos nchanges = SCARG(uap, nchanges);
679 1.2 christos nevents = SCARG(uap, nevents);
680 1.2 christos maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents));
681 1.2 christos netbsd32_kevent_ops.keo_private =
682 1.2 christos malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP,
683 1.2 christos M_WAITOK);
684 1.2 christos
685 1.2 christos error = kevent1(retval, SCARG(uap, fd),
686 1.2 christos NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
687 1.2 christos NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
688 1.2 christos NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
689 1.2 christos
690 1.2 christos free(netbsd32_kevent_ops.keo_private, M_TEMP);
691 1.2 christos return error;
692 1.2 christos return 0;
693 1.2 christos }
694 1.2 christos
695 1.2 christos int
696 1.2 christos compat_50_netbsd32_pselect(struct lwp *l,
697 1.2 christos const struct compat_50_netbsd32_pselect_args *uap, register_t *retval)
698 1.2 christos {
699 1.2 christos /* {
700 1.2 christos syscallarg(int) nd;
701 1.2 christos syscallarg(netbsd32_fd_setp_t) in;
702 1.2 christos syscallarg(netbsd32_fd_setp_t) ou;
703 1.2 christos syscallarg(netbsd32_fd_setp_t) ex;
704 1.2 christos syscallarg(const netbsd32_timespec50p_t) ts;
705 1.2 christos syscallarg(const netbsd32_sigsetp_t) mask;
706 1.2 christos } */
707 1.2 christos int error;
708 1.2 christos struct netbsd32_timespec50 ts32;
709 1.2 christos struct timespec ts;
710 1.2 christos struct timeval atv, *tv = NULL;
711 1.2 christos sigset_t amask, *mask = NULL;
712 1.2 christos
713 1.2 christos if (SCARG_P32(uap, ts)) {
714 1.2 christos error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
715 1.2 christos if (error != 0)
716 1.2 christos return error;
717 1.2 christos netbsd32_to_timespec50(&ts32, &ts);
718 1.2 christos atv.tv_sec = ts.tv_sec;
719 1.2 christos atv.tv_usec = ts.tv_nsec / 1000;
720 1.2 christos tv = &atv;
721 1.2 christos }
722 1.2 christos if (SCARG_P32(uap, mask)) {
723 1.2 christos error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
724 1.2 christos if (error != 0)
725 1.2 christos return error;
726 1.2 christos mask = &amask;
727 1.2 christos }
728 1.2 christos
729 1.2 christos return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in),
730 1.2 christos SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, mask);
731 1.2 christos return 0;
732 1.2 christos }
733 1.2 christos
734 1.2 christos int
735 1.2 christos compat_50_netbsd32_pollts(struct lwp *l,
736 1.2 christos const struct compat_50_netbsd32_pollts_args *uap, register_t *retval)
737 1.2 christos {
738 1.2 christos /* {
739 1.2 christos syscallarg(struct netbsd32_pollfdp_t) fds;
740 1.2 christos syscallarg(u_int) nfds;
741 1.2 christos syscallarg(const netbsd32_timespec50p_t) ts;
742 1.2 christos syscallarg(const netbsd32_sigsetp_t) mask;
743 1.2 christos } */
744 1.2 christos int error;
745 1.2 christos struct netbsd32_timespec50 ts32;
746 1.2 christos struct timespec ts;
747 1.2 christos struct timeval atv, *tv = NULL;
748 1.2 christos sigset_t amask, *mask = NULL;
749 1.2 christos
750 1.2 christos if (SCARG_P32(uap, ts)) {
751 1.2 christos error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
752 1.2 christos if (error != 0)
753 1.2 christos return error;
754 1.2 christos netbsd32_to_timespec50(&ts32, &ts);
755 1.2 christos atv.tv_sec = ts.tv_sec;
756 1.2 christos atv.tv_usec = ts.tv_nsec / 1000;
757 1.2 christos tv = &atv;
758 1.2 christos }
759 1.2 christos if (NETBSD32PTR64( SCARG(uap, mask))) {
760 1.2 christos error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
761 1.2 christos if (error != 0)
762 1.2 christos return error;
763 1.2 christos mask = &amask;
764 1.2 christos }
765 1.2 christos
766 1.2 christos return pollcommon(l, retval, SCARG_P32(uap, fds),
767 1.2 christos SCARG(uap, nfds), tv, mask);
768 1.2 christos }
769 1.2 christos
770 1.2 christos int
771 1.2 christos compat_50_netbsd32___stat30(struct lwp *l,
772 1.2 christos const struct compat_50_netbsd32___stat30_args *uap, register_t *retval)
773 1.2 christos {
774 1.2 christos /* {
775 1.2 christos syscallarg(const netbsd32_charp) path;
776 1.2 christos syscallarg(netbsd32_stat50p_t) ub;
777 1.2 christos } */
778 1.2 christos struct netbsd32_stat50 sb32;
779 1.2 christos struct stat sb;
780 1.2 christos int error;
781 1.2 christos const char *path;
782 1.2 christos
783 1.2 christos path = SCARG_P32(uap, path);
784 1.2 christos
785 1.2 christos error = do_sys_stat(path, FOLLOW, &sb);
786 1.2 christos if (error)
787 1.2 christos return error;
788 1.2 christos netbsd32_from___stat50(&sb, &sb32);
789 1.2 christos error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
790 1.2 christos return error;
791 1.2 christos }
792 1.2 christos
793 1.2 christos int
794 1.2 christos compat_50_netbsd32___fstat30(struct lwp *l,
795 1.2 christos const struct compat_50_netbsd32___fstat30_args *uap, register_t *retval)
796 1.2 christos {
797 1.2 christos /* {
798 1.2 christos syscallarg(int) fd;
799 1.2 christos syscallarg(netbsd32_stat50p_t) sb;
800 1.2 christos } */
801 1.2 christos struct netbsd32_stat50 sb32;
802 1.2 christos struct stat ub;
803 1.3 njoly int error;
804 1.2 christos
805 1.3 njoly error = do_sys_fstat(SCARG(uap, fd), &ub);
806 1.2 christos if (error == 0) {
807 1.2 christos netbsd32_from___stat50(&ub, &sb32);
808 1.2 christos error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
809 1.2 christos }
810 1.2 christos return error;
811 1.2 christos }
812 1.2 christos
813 1.2 christos int
814 1.2 christos compat_50_netbsd32___lstat30(struct lwp *l,
815 1.2 christos const struct compat_50_netbsd32___lstat30_args *uap, register_t *retval)
816 1.2 christos {
817 1.2 christos /* {
818 1.2 christos syscallarg(const netbsd32_charp) path;
819 1.2 christos syscallarg(netbsd32_stat50p_t) ub;
820 1.2 christos } */
821 1.2 christos struct netbsd32_stat50 sb32;
822 1.2 christos struct stat sb;
823 1.2 christos int error;
824 1.2 christos const char *path;
825 1.2 christos
826 1.2 christos path = SCARG_P32(uap, path);
827 1.2 christos
828 1.2 christos error = do_sys_stat(path, NOFOLLOW, &sb);
829 1.2 christos if (error)
830 1.2 christos return error;
831 1.2 christos netbsd32_from___stat50(&sb, &sb32);
832 1.2 christos error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
833 1.2 christos return error;
834 1.2 christos }
835 1.2 christos
836 1.2 christos int
837 1.2 christos compat_50_netbsd32___fhstat40(struct lwp *l, const struct compat_50_netbsd32___fhstat40_args *uap, register_t *retval)
838 1.2 christos {
839 1.2 christos /* {
840 1.2 christos syscallarg(const netbsd32_pointer_t) fhp;
841 1.2 christos syscallarg(netbsd32_size_t) fh_size;
842 1.2 christos syscallarg(netbsd32_stat50p_t) sb;
843 1.2 christos } */
844 1.2 christos struct stat sb;
845 1.2 christos struct netbsd32_stat50 sb32;
846 1.2 christos int error;
847 1.2 christos
848 1.2 christos error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
849 1.2 christos if (error != 0) {
850 1.2 christos netbsd32_from___stat50(&sb, &sb32);
851 1.2 christos error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
852 1.2 christos }
853 1.2 christos return error;
854 1.2 christos }
855 1.2 christos
856 1.2 christos int
857 1.2 christos compat_50_netbsd32_wait4(struct lwp *l, const struct compat_50_netbsd32_wait4_args *uap, register_t *retval)
858 1.2 christos {
859 1.2 christos /* {
860 1.2 christos syscallarg(int) pid;
861 1.2 christos syscallarg(netbsd32_intp) status;
862 1.2 christos syscallarg(int) options;
863 1.2 christos syscallarg(netbsd32_rusage50p_t) rusage;
864 1.2 christos } */
865 1.2 christos int status, error;
866 1.2 christos int was_zombie;
867 1.2 christos struct rusage ru;
868 1.2 christos struct netbsd32_rusage50 ru32;
869 1.2 christos int pid = SCARG(uap, pid);
870 1.2 christos
871 1.2 christos error = do_sys_wait(l, &pid, &status, SCARG(uap, options),
872 1.2 christos SCARG_P32(uap, rusage) != NULL ? &ru : NULL, &was_zombie);
873 1.2 christos
874 1.2 christos retval[0] = pid;
875 1.2 christos if (pid == 0)
876 1.2 christos return error;
877 1.2 christos
878 1.2 christos if (SCARG_P32(uap, rusage)) {
879 1.2 christos netbsd32_from_rusage50(&ru, &ru32);
880 1.2 christos error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
881 1.2 christos }
882 1.2 christos
883 1.2 christos if (error == 0 && SCARG_P32(uap, status))
884 1.2 christos error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
885 1.2 christos
886 1.2 christos return error;
887 1.2 christos }
888 1.2 christos
889 1.2 christos
890 1.2 christos int
891 1.2 christos compat_50_netbsd32_getrusage(struct lwp *l, const struct compat_50_netbsd32_getrusage_args *uap, register_t *retval)
892 1.2 christos {
893 1.2 christos /* {
894 1.2 christos syscallarg(int) who;
895 1.2 christos syscallarg(netbsd32_rusage50p_t) rusage;
896 1.2 christos } */
897 1.2 christos struct proc *p = l->l_proc;
898 1.2 christos struct rusage *rup;
899 1.2 christos struct netbsd32_rusage50 ru;
900 1.2 christos
901 1.2 christos switch (SCARG(uap, who)) {
902 1.2 christos
903 1.2 christos case RUSAGE_SELF:
904 1.2 christos rup = &p->p_stats->p_ru;
905 1.2 christos mutex_enter(p->p_lock);
906 1.2 christos calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
907 1.2 christos mutex_exit(p->p_lock);
908 1.2 christos break;
909 1.2 christos
910 1.2 christos case RUSAGE_CHILDREN:
911 1.2 christos rup = &p->p_stats->p_cru;
912 1.2 christos break;
913 1.2 christos
914 1.2 christos default:
915 1.2 christos return (EINVAL);
916 1.2 christos }
917 1.2 christos netbsd32_from_rusage50(rup, &ru);
918 1.2 christos return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
919 1.2 christos }
920 1.2 christos
921 1.2 christos int
922 1.2 christos compat_50_netbsd32_setitimer(struct lwp *l,
923 1.2 christos const struct compat_50_netbsd32_setitimer_args *uap, register_t *retval)
924 1.2 christos {
925 1.2 christos /* {
926 1.2 christos syscallarg(int) which;
927 1.2 christos syscallarg(const netbsd32_itimerval50p_t) itv;
928 1.2 christos syscallarg(netbsd32_itimerval50p_t) oitv;
929 1.2 christos } */
930 1.2 christos struct proc *p = l->l_proc;
931 1.2 christos struct netbsd32_itimerval50 s32it, *itv32;
932 1.2 christos int which = SCARG(uap, which);
933 1.2 christos struct compat_50_netbsd32_getitimer_args getargs;
934 1.2 christos struct itimerval aitv;
935 1.2 christos int error;
936 1.2 christos
937 1.2 christos if ((u_int)which > ITIMER_PROF)
938 1.2 christos return (EINVAL);
939 1.2 christos itv32 = SCARG_P32(uap, itv);
940 1.2 christos if (itv32) {
941 1.2 christos if ((error = copyin(itv32, &s32it, sizeof(s32it))))
942 1.2 christos return (error);
943 1.2 christos netbsd32_to_itimerval50(&s32it, &aitv);
944 1.2 christos }
945 1.2 christos if (SCARG_P32(uap, oitv) != 0) {
946 1.2 christos SCARG(&getargs, which) = which;
947 1.2 christos SCARG(&getargs, itv) = SCARG(uap, oitv);
948 1.2 christos if ((error = compat_50_netbsd32_getitimer(l, &getargs, retval)) != 0)
949 1.2 christos return (error);
950 1.2 christos }
951 1.2 christos if (itv32 == 0)
952 1.2 christos return 0;
953 1.2 christos
954 1.2 christos return dosetitimer(p, which, &aitv);
955 1.2 christos }
956 1.2 christos
957 1.2 christos int
958 1.2 christos compat_50_netbsd32_getitimer(struct lwp *l, const struct compat_50_netbsd32_getitimer_args *uap, register_t *retval)
959 1.2 christos {
960 1.2 christos /* {
961 1.2 christos syscallarg(int) which;
962 1.2 christos syscallarg(netbsd32_itimerval50p_t) itv;
963 1.2 christos } */
964 1.2 christos struct proc *p = l->l_proc;
965 1.2 christos struct netbsd32_itimerval50 s32it;
966 1.2 christos struct itimerval aitv;
967 1.2 christos int error;
968 1.2 christos
969 1.2 christos error = dogetitimer(p, SCARG(uap, which), &aitv);
970 1.2 christos if (error)
971 1.2 christos return error;
972 1.2 christos
973 1.2 christos netbsd32_from_itimerval50(&aitv, &s32it);
974 1.2 christos return copyout(&s32it, SCARG_P32(uap, itv), sizeof(s32it));
975 1.2 christos }
976 1.2 christos
977 1.2 christos #if defined(SYSVSEM)
978 1.2 christos
979 1.2 christos int
980 1.2 christos compat_50_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval)
981 1.2 christos {
982 1.2 christos return do_netbsd32___semctl14(l, uap, retval, NULL);
983 1.2 christos }
984 1.2 christos
985 1.2 christos int
986 1.2 christos do_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval, void *vkarg)
987 1.2 christos {
988 1.2 christos /* {
989 1.2 christos syscallarg(int) semid;
990 1.2 christos syscallarg(int) semnum;
991 1.2 christos syscallarg(int) cmd;
992 1.2 christos syscallarg(netbsd32_semun50p_t) arg;
993 1.2 christos } */
994 1.2 christos struct semid_ds sembuf;
995 1.2 christos struct netbsd32_semid_ds50 sembuf32;
996 1.2 christos int cmd, error;
997 1.2 christos void *pass_arg;
998 1.2 christos union __semun karg;
999 1.2 christos union netbsd32_semun50 karg32;
1000 1.2 christos
1001 1.2 christos cmd = SCARG(uap, cmd);
1002 1.2 christos
1003 1.2 christos switch (cmd) {
1004 1.2 christos case IPC_SET:
1005 1.2 christos case IPC_STAT:
1006 1.2 christos pass_arg = &sembuf;
1007 1.2 christos break;
1008 1.2 christos
1009 1.2 christos case GETALL:
1010 1.2 christos case SETVAL:
1011 1.2 christos case SETALL:
1012 1.2 christos pass_arg = &karg;
1013 1.2 christos break;
1014 1.2 christos default:
1015 1.2 christos pass_arg = NULL;
1016 1.2 christos break;
1017 1.2 christos }
1018 1.2 christos
1019 1.2 christos if (pass_arg) {
1020 1.2 christos if (vkarg != NULL)
1021 1.2 christos karg32 = *(union netbsd32_semun50 *)vkarg;
1022 1.2 christos else {
1023 1.2 christos error = copyin(SCARG_P32(uap, arg), &karg32,
1024 1.2 christos sizeof(karg32));
1025 1.2 christos if (error)
1026 1.2 christos return error;
1027 1.2 christos }
1028 1.2 christos if (pass_arg == &karg) {
1029 1.2 christos switch (cmd) {
1030 1.2 christos case GETALL:
1031 1.2 christos case SETALL:
1032 1.2 christos karg.array = NETBSD32PTR64(karg32.array);
1033 1.2 christos break;
1034 1.2 christos case SETVAL:
1035 1.2 christos karg.val = karg32.val;
1036 1.2 christos break;
1037 1.2 christos }
1038 1.2 christos }
1039 1.2 christos if (cmd == IPC_SET) {
1040 1.2 christos error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32,
1041 1.2 christos sizeof(sembuf32));
1042 1.2 christos if (error)
1043 1.2 christos return (error);
1044 1.2 christos netbsd32_to_semid_ds50(&sembuf32, &sembuf);
1045 1.2 christos }
1046 1.2 christos }
1047 1.2 christos
1048 1.2 christos error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
1049 1.2 christos pass_arg, retval);
1050 1.2 christos
1051 1.2 christos if (error == 0 && cmd == IPC_STAT) {
1052 1.2 christos netbsd32_from_semid_ds50(&sembuf, &sembuf32);
1053 1.2 christos error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf),
1054 1.2 christos sizeof(sembuf32));
1055 1.2 christos }
1056 1.2 christos
1057 1.2 christos return (error);
1058 1.2 christos }
1059 1.2 christos #endif
1060 1.2 christos
1061 1.2 christos #if defined(SYSVMSG)
1062 1.2 christos
1063 1.2 christos int
1064 1.2 christos compat_50_netbsd32___msgctl13(struct lwp *l, const struct compat_50_netbsd32___msgctl13_args *uap, register_t *retval)
1065 1.2 christos {
1066 1.2 christos /* {
1067 1.2 christos syscallarg(int) msqid;
1068 1.2 christos syscallarg(int) cmd;
1069 1.2 christos syscallarg(netbsd32_msqid_ds50p_t) buf;
1070 1.2 christos } */
1071 1.2 christos struct msqid_ds ds;
1072 1.2 christos struct netbsd32_msqid_ds50 ds32;
1073 1.2 christos int error, cmd;
1074 1.2 christos
1075 1.2 christos cmd = SCARG(uap, cmd);
1076 1.2 christos if (cmd == IPC_SET) {
1077 1.2 christos error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
1078 1.2 christos if (error)
1079 1.2 christos return error;
1080 1.2 christos netbsd32_to_msqid_ds50(&ds32, &ds);
1081 1.2 christos }
1082 1.2 christos
1083 1.2 christos error = msgctl1(l, SCARG(uap, msqid), cmd,
1084 1.2 christos (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
1085 1.2 christos
1086 1.2 christos if (error == 0 && cmd == IPC_STAT) {
1087 1.2 christos netbsd32_from_msqid_ds50(&ds, &ds32);
1088 1.2 christos error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
1089 1.2 christos }
1090 1.2 christos
1091 1.2 christos return error;
1092 1.2 christos }
1093 1.2 christos #endif
1094 1.2 christos
1095 1.2 christos #if defined(SYSVSHM)
1096 1.2 christos
1097 1.2 christos int
1098 1.2 christos compat_50_netbsd32___shmctl13(struct lwp *l, const struct compat_50_netbsd32___shmctl13_args *uap, register_t *retval)
1099 1.2 christos {
1100 1.2 christos /* {
1101 1.2 christos syscallarg(int) shmid;
1102 1.2 christos syscallarg(int) cmd;
1103 1.2 christos syscallarg(netbsd32_shmid_ds50p_t) buf;
1104 1.2 christos } */
1105 1.2 christos struct shmid_ds ds;
1106 1.2 christos struct netbsd32_shmid_ds50 ds32;
1107 1.2 christos int error, cmd;
1108 1.2 christos
1109 1.2 christos cmd = SCARG(uap, cmd);
1110 1.2 christos if (cmd == IPC_SET) {
1111 1.2 christos error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
1112 1.2 christos if (error)
1113 1.2 christos return error;
1114 1.2 christos netbsd32_to_shmid_ds50(&ds32, &ds);
1115 1.2 christos }
1116 1.2 christos
1117 1.2 christos error = shmctl1(l, SCARG(uap, shmid), cmd,
1118 1.2 christos (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
1119 1.2 christos
1120 1.2 christos if (error == 0 && cmd == IPC_STAT) {
1121 1.2 christos netbsd32_from_shmid_ds50(&ds, &ds32);
1122 1.2 christos error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
1123 1.2 christos }
1124 1.2 christos
1125 1.2 christos return error;
1126 1.2 christos }
1127 1.2 christos #endif
1128