Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / netbsd32 / netbsd32_compat_50.c
blobe893bd60eb59fe3d6b94279182921e3a77df5f2d
1 /* $NetBSD: netbsd32_compat_50.c,v 1.7 2009/11/11 09:48:51 rmind Exp $ */
3 /*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50.c,v 1.7 2009/11/11 09:48:51 rmind Exp $");
41 #if defined(_KERNEL_OPT)
42 #include "opt_sysv.h"
44 #include "fs_lfs.h"
45 #endif
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
53 #include <sys/stat.h>
54 #include <sys/time.h>
55 #include <sys/ktrace.h>
56 #include <sys/eventvar.h>
57 #include <sys/resourcevar.h>
58 #include <sys/vnode.h>
59 #include <sys/file.h>
60 #include <sys/filedesc.h>
61 #include <sys/poll.h>
62 #include <sys/namei.h>
63 #include <sys/statvfs.h>
64 #include <sys/syscallargs.h>
65 #include <sys/proc.h>
66 #include <sys/dirent.h>
67 #include <sys/kauth.h>
68 #include <sys/vfs_syscalls.h>
69 #include <sys/ipc.h>
70 #include <sys/msg.h>
71 #include <sys/sem.h>
72 #include <sys/shm.h>
74 #include <compat/netbsd32/netbsd32.h>
75 #include <compat/netbsd32/netbsd32_syscallargs.h>
76 #include <compat/netbsd32/netbsd32_conv.h>
77 #include <compat/sys/mount.h>
78 #include <compat/sys/time.h>
82 * Common routine to set access and modification times given a vnode.
84 static int
85 get_utimes32(const netbsd32_timeval50p_t *tptr, struct timeval *tv,
86 struct timeval **tvp)
88 int error;
89 struct netbsd32_timeval50 tv32[2];
91 if (tptr == NULL) {
92 *tvp = NULL;
93 return 0;
96 error = copyin(tptr, tv32, sizeof(tv32));
97 if (error)
98 return error;
99 netbsd32_to_timeval50(&tv32[0], &tv[0]);
100 netbsd32_to_timeval50(&tv32[1], &tv[1]);
102 *tvp = tv;
103 return 0;
107 compat_50_netbsd32_mknod(struct lwp *l,
108 const struct compat_50_netbsd32_mknod_args *uap, register_t *retval)
110 /* {
111 syscallarg(netbsd32_charp) path;
112 syscallarg(mode_t) mode;
113 syscallarg(uint32_t) dev;
114 } */
115 return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
116 SCARG(uap, dev), retval, UIO_USERSPACE);
120 compat_50_netbsd32_select(struct lwp *l,
121 const struct compat_50_netbsd32_select_args *uap, register_t *retval)
123 /* {
124 syscallarg(int) nd;
125 syscallarg(netbsd32_fd_setp_t) in;
126 syscallarg(netbsd32_fd_setp_t) ou;
127 syscallarg(netbsd32_fd_setp_t) ex;
128 syscallarg(netbsd32_timeval50p_t) tv;
129 } */
130 int error;
131 struct netbsd32_timeval50 tv32;
132 struct timespec ats, *ts = NULL;
134 if (SCARG_P32(uap, tv)) {
135 error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32));
136 if (error != 0)
137 return error;
138 ats.tv_sec = tv32.tv_sec;
139 ats.tv_nsec = tv32.tv_usec * 1000;
140 ts = &ats;
143 return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
144 SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL);
145 return 0;
149 compat_50_netbsd32_gettimeofday(struct lwp *l,
150 const struct compat_50_netbsd32_gettimeofday_args *uap, register_t *retval)
152 /* {
153 syscallarg(netbsd32_timeval50p_t) tp;
154 syscallarg(netbsd32_timezonep_t) tzp;
155 } */
156 struct timeval atv;
157 struct netbsd32_timeval50 tv32;
158 int error = 0;
159 struct netbsd32_timezone tzfake;
161 if (SCARG_P32(uap, tp)) {
162 microtime(&atv);
163 netbsd32_from_timeval50(&atv, &tv32);
164 error = copyout(&tv32, SCARG_P32(uap, tp), sizeof(tv32));
165 if (error)
166 return error;
168 if (SCARG_P32(uap, tzp)) {
170 * NetBSD has no kernel notion of time zone, so we just
171 * fake up a timezone struct and return it if demanded.
173 tzfake.tz_minuteswest = 0;
174 tzfake.tz_dsttime = 0;
175 error = copyout(&tzfake, SCARG_P32(uap, tzp), sizeof(tzfake));
177 return error;
181 compat_50_netbsd32_settimeofday(struct lwp *l,
182 const struct compat_50_netbsd32_settimeofday_args *uap, register_t *retval)
184 /* {
185 syscallarg(const netbsd32_timeval50p_t) tv;
186 syscallarg(const netbsd32_timezonep_t) tzp;
187 } */
188 struct netbsd32_timeval50 atv32;
189 struct timeval atv;
190 struct timespec ats;
191 int error;
192 struct proc *p = l->l_proc;
194 /* Verify all parameters before changing time. */
197 * NetBSD has no kernel notion of time zone, and only an
198 * obsolete program would try to set it, so we log a warning.
200 if (SCARG_P32(uap, tzp))
201 printf("pid %d attempted to set the "
202 "(obsolete) kernel time zone\n", p->p_pid);
204 if (SCARG_P32(uap, tv) == 0)
205 return 0;
207 if ((error = copyin(SCARG_P32(uap, tv), &atv32, sizeof(atv32))) != 0)
208 return error;
210 netbsd32_to_timeval50(&atv32, &atv);
211 TIMEVAL_TO_TIMESPEC(&atv, &ats);
212 return settime(p, &ats);
216 compat_50_netbsd32_utimes(struct lwp *l,
217 const struct compat_50_netbsd32_utimes_args *uap, register_t *retval)
219 /* {
220 syscallarg(const netbsd32_charp) path;
221 syscallarg(const netbsd32_timeval50p_t) tptr;
222 } */
223 int error;
224 struct timeval tv[2], *tvp;
226 error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
227 if (error != 0)
228 return error;
230 return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
231 tvp, UIO_SYSSPACE);
235 compat_50_netbsd32_adjtime(struct lwp *l,
236 const struct compat_50_netbsd32_adjtime_args *uap, register_t *retval)
238 /* {
239 syscallarg(const netbsd32_timeval50p_t) delta;
240 syscallarg(netbsd32_timeval50p_t) olddelta;
241 } */
242 struct netbsd32_timeval50 atv;
243 int error;
245 extern int time_adjusted; /* in kern_ntptime.c */
246 extern int64_t time_adjtime; /* in kern_ntptime.c */
248 if ((error = kauth_authorize_system(l->l_cred,
249 KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_ADJTIME, NULL, NULL,
250 NULL)) != 0)
251 return (error);
253 if (SCARG_P32(uap, olddelta)) {
254 atv.tv_sec = time_adjtime / 1000000;
255 atv.tv_usec = time_adjtime % 1000000;
256 if (atv.tv_usec < 0) {
257 atv.tv_usec += 1000000;
258 atv.tv_sec--;
260 (void) copyout(&atv,
261 SCARG_P32(uap, olddelta),
262 sizeof(atv));
263 if (error)
264 return (error);
267 if (SCARG_P32(uap, delta)) {
268 error = copyin(SCARG_P32(uap, delta), &atv,
269 sizeof(struct timeval));
270 if (error)
271 return (error);
273 time_adjtime = (int64_t)atv.tv_sec * 1000000 + atv.tv_usec;
275 if (time_adjtime)
276 /* We need to save the system time during shutdown */
277 time_adjusted |= 1;
280 return 0;
283 #if defined(LFS) || !defined(_KERNEL)
285 compat_50_netbsd32_lfs_segwait(struct lwp *l,
286 const struct compat_50_netbsd32_lfs_segwait_args *uap, register_t *retval)
288 return 0;
290 #endif
293 compat_50_netbsd32_futimes(struct lwp *l,
294 const struct compat_50_netbsd32_futimes_args *uap, register_t *retval)
296 /* {
297 syscallarg(int) fd;
298 syscallarg(const netbsd32_timeval50p_t) tptr;
299 } */
300 int error;
301 file_t *fp;
302 struct timeval tv[2], *tvp;
304 error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
305 if (error != 0)
306 return error;
308 /* fd_getvnode() will use the descriptor for us */
309 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
310 return error;
312 error = do_sys_utimes(l, fp->f_data, NULL, 0, tvp, UIO_SYSSPACE);
314 fd_putfile(SCARG(uap, fd));
315 return error;
319 compat_50_netbsd32_clock_gettime(struct lwp *l,
320 const struct compat_50_netbsd32_clock_gettime_args *uap, register_t *retval)
322 /* {
323 syscallarg(netbsd32_clockid_t) clock_id;
324 syscallarg(netbsd32_timespec50p_t) tp;
325 } */
326 clockid_t clock_id;
327 struct timespec ats;
328 struct netbsd32_timespec50 ts32;
330 clock_id = SCARG(uap, clock_id);
331 if (clock_id != CLOCK_REALTIME)
332 return (EINVAL);
334 nanotime(&ats);
335 netbsd32_from_timespec50(&ats, &ts32);
337 return copyout(&ts32, SCARG_P32(uap, tp), sizeof(ts32));
341 compat_50_netbsd32_clock_settime(struct lwp *l,
342 const struct compat_50_netbsd32_clock_settime_args *uap, register_t *retval)
344 /* {
345 syscallarg(netbsd32_clockid_t) clock_id;
346 syscallarg(const netbsd32_timespec50p_t) tp;
347 } */
348 struct netbsd32_timespec50 ts32;
349 clockid_t clock_id;
350 struct timespec ats;
351 int error;
353 clock_id = SCARG(uap, clock_id);
354 if (clock_id != CLOCK_REALTIME)
355 return (EINVAL);
357 if ((error = copyin(SCARG_P32(uap, tp), &ts32, sizeof(ts32))) != 0)
358 return (error);
360 netbsd32_to_timespec50(&ts32, &ats);
361 return settime(l->l_proc, &ats);
365 compat_50_netbsd32_clock_getres(struct lwp *l,
366 const struct compat_50_netbsd32_clock_getres_args *uap, register_t *retval)
368 /* {
369 syscallarg(netbsd32_clockid_t) clock_id;
370 syscallarg(netbsd32_timespec50p_t) tp;
371 } */
372 struct netbsd32_timespec50 ts32;
373 clockid_t clock_id;
374 struct timespec ts;
375 int error = 0;
377 clock_id = SCARG(uap, clock_id);
378 if (clock_id != CLOCK_REALTIME)
379 return (EINVAL);
381 if (SCARG_P32(uap, tp)) {
382 ts.tv_sec = 0;
383 ts.tv_nsec = 1000000000 / hz;
385 netbsd32_from_timespec50(&ts, &ts32);
386 error = copyout(&ts, SCARG_P32(uap, tp), sizeof(ts));
389 return error;
393 compat_50_netbsd32_timer_settime(struct lwp *l,
394 const struct compat_50_netbsd32_timer_settime_args *uap, register_t *retval)
396 /* {
397 syscallarg(netbsd32_timer_t) timerid;
398 syscallarg(int) flags;
399 syscallarg(const netbsd32_itimerspec50p_t) value;
400 syscallarg(netbsd32_itimerspec50p_t) ovalue;
401 } */
402 int error;
403 struct itimerspec value, ovalue, *ovp = NULL;
404 struct netbsd32_itimerspec50 its32;
406 if ((error = copyin(SCARG_P32(uap, value), &its32, sizeof(its32))) != 0)
407 return (error);
408 netbsd32_to_timespec50(&its32.it_interval, &value.it_interval);
409 netbsd32_to_timespec50(&its32.it_value, &value.it_value);
411 if (SCARG_P32(uap, ovalue))
412 ovp = &ovalue;
414 if ((error = dotimer_settime(SCARG(uap, timerid), &value, ovp,
415 SCARG(uap, flags), l->l_proc)) != 0)
416 return error;
418 if (ovp) {
419 netbsd32_from_timespec50(&ovp->it_interval, &its32.it_interval);
420 netbsd32_from_timespec50(&ovp->it_value, &its32.it_value);
421 return copyout(&its32, SCARG_P32(uap, ovalue), sizeof(its32));
423 return 0;
427 compat_50_netbsd32_timer_gettime(struct lwp *l, const struct compat_50_netbsd32_timer_gettime_args *uap, register_t *retval)
429 /* {
430 syscallarg(netbsd32_timer_t) timerid;
431 syscallarg(netbsd32_itimerspec50p_t) value;
432 } */
433 int error;
434 struct itimerspec its;
435 struct netbsd32_itimerspec50 its32;
437 if ((error = dotimer_gettime(SCARG(uap, timerid), l->l_proc,
438 &its)) != 0)
439 return error;
441 netbsd32_from_timespec50(&its.it_interval, &its32.it_interval);
442 netbsd32_from_timespec50(&its.it_value, &its32.it_value);
444 return copyout(&its32, SCARG_P32(uap, value), sizeof(its32));
448 compat_50_netbsd32_nanosleep(struct lwp *l,
449 const struct compat_50_netbsd32_nanosleep_args *uap, register_t *retval)
451 /* {
452 syscallarg(const netbsd32_timespec50p_t) rqtp;
453 syscallarg(netbsd32_timespecp_t) rmtp;
454 } */
455 static int nanowait;
456 struct netbsd32_timespec50 ts32;
457 struct timespec rqt, ctime, rmt;
458 int error, timo;
460 error = copyin(SCARG_P32(uap, rqtp), &ts32, sizeof(ts32));
461 if (error)
462 return (error);
464 netbsd32_to_timespec50(&ts32, &rqt);
465 if (itimespecfix(&rqt))
466 return (EINVAL);
468 getnanotime(&ctime);
469 timespecadd(&rqt, &ctime, &rqt);
470 timo = tshzto(&rqt);
472 * Avoid inadvertantly sleeping forever
474 if (timo == 0)
475 timo = 1;
477 error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo);
478 if (error == ERESTART)
479 error = EINTR;
480 if (error == EWOULDBLOCK)
481 error = 0;
483 if (SCARG_P32(uap, rmtp)) {
484 int error1;
486 getnanotime(&rmt);
488 timespecsub(&rqt, &rmt, &rmt);
489 if (rmt.tv_sec < 0)
490 timespecclear(&rmt);
492 netbsd32_from_timespec50(&rmt, &ts32);
493 error1 = copyout(&ts32, SCARG_P32(uap,rmtp), sizeof(ts32));
494 if (error1)
495 return (error1);
498 return error;
501 static int
502 compat_50_netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size)
504 const siginfo_t *info = src;
505 siginfo32_t info32;
507 netbsd32_si_to_si32(&info32, info);
509 return copyout(&info32, dst, sizeof(info32));
512 static int
513 compat_50_netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size)
515 struct timespec *ts = dst;
516 struct netbsd32_timespec50 ts32;
517 int error;
519 error = copyin(src, &ts32, sizeof(ts32));
520 if (error)
521 return error;
523 netbsd32_to_timespec50(&ts32, ts);
524 return 0;
527 static int
528 compat_50_netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size)
530 const struct timespec *ts = src;
531 struct netbsd32_timespec50 ts32;
533 netbsd32_from_timespec50(ts, &ts32);
535 return copyout(&ts32, dst, sizeof(ts32));
539 compat_50_netbsd32___sigtimedwait(struct lwp *l,
540 const struct compat_50_netbsd32___sigtimedwait_args *uap, register_t *retval)
542 /* {
543 syscallarg(netbsd32_sigsetp_t) set;
544 syscallarg(netbsd32_siginfop_t) info;
545 syscallarg(netbsd32_timespec50p_t) timeout;
546 } */
547 struct sys_____sigtimedwait50_args ua;
549 NETBSD32TOP_UAP(set, const sigset_t);
550 NETBSD32TOP_UAP(info, siginfo_t);
551 NETBSD32TOP_UAP(timeout, struct timespec);
553 return __sigtimedwait1(l, &ua, retval,
554 compat_50_netbsd32_sigtimedwait_put_info,
555 compat_50_netbsd32_sigtimedwait_fetch_timeout,
556 compat_50_netbsd32_sigtimedwait_put_timeout);
557 return 0;
561 compat_50_netbsd32_lutimes(struct lwp *l,
562 const struct compat_50_netbsd32_lutimes_args *uap, register_t *retval)
564 /* {
565 syscallarg(const netbsd32_charp) path;
566 syscallarg(const netbsd32_timeval50p_t) tptr;
567 } */
568 int error;
569 struct timeval tv[2], *tvp;
571 error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
572 if (error != 0)
573 return error;
575 return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
576 tvp, UIO_SYSSPACE);
580 compat_50_netbsd32__lwp_park(struct lwp *l,
581 const struct compat_50_netbsd32__lwp_park_args *uap, register_t *retval)
583 /* {
584 syscallarg(const netbsd32_timespec50p) ts;
585 syscallarg(lwpid_t) unpark;
586 syscallarg(netbsd32_voidp) hint;
587 syscallarg(netbsd32_voidp) unparkhint;
588 } */
589 struct timespec ts, *tsp;
590 struct netbsd32_timespec50 ts32;
591 int error;
593 if (SCARG_P32(uap, ts) == NULL)
594 tsp = NULL;
595 else {
596 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
597 if (error != 0)
598 return error;
599 netbsd32_to_timespec50(&ts32, &ts);
600 tsp = &ts;
603 if (SCARG(uap, unpark) != 0) {
604 error = lwp_unpark(SCARG(uap, unpark),
605 SCARG_P32(uap, unparkhint));
606 if (error != 0)
607 return error;
610 return lwp_park(tsp, SCARG_P32(uap, hint));
611 return 0;
614 static int
615 netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
617 struct netbsd32_timespec50 ts32;
618 int error;
620 KASSERT(length == sizeof(struct timespec50));
622 error = copyin(src, &ts32, sizeof(ts32));
623 if (error)
624 return error;
625 netbsd32_to_timespec50(&ts32, (struct timespec *)dest);
626 return 0;
629 static int
630 netbsd32_kevent_fetch_changes(void *private, const struct kevent *changelist,
631 struct kevent *changes, size_t index, int n)
633 const struct netbsd32_kevent *src =
634 (const struct netbsd32_kevent *)changelist;
635 struct netbsd32_kevent *kev32, *changes32 = private;
636 int error, i;
638 error = copyin(src + index, changes32, n * sizeof(*changes32));
639 if (error)
640 return error;
641 for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
642 netbsd32_to_kevent(kev32, changes);
643 return 0;
646 static int
647 netbsd32_kevent_put_events(void *private, struct kevent *events,
648 struct kevent *eventlist, size_t index, int n)
650 struct netbsd32_kevent *kev32, *events32 = private;
651 int i;
653 for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
654 netbsd32_from_kevent(events, kev32);
655 kev32 = (struct netbsd32_kevent *)eventlist;
656 return copyout(events32, kev32, n * sizeof(*events32));
660 compat_50_netbsd32_kevent(struct lwp *l,
661 const struct compat_50_netbsd32_kevent_args *uap, register_t *retval)
663 /* {
664 syscallarg(int) fd;
665 syscallarg(netbsd32_keventp_t) changelist;
666 syscallarg(netbsd32_size_t) nchanges;
667 syscallarg(netbsd32_keventp_t) eventlist;
668 syscallarg(netbsd32_size_t) nevents;
669 syscallarg(netbsd32_timespec50p_t) timeout;
670 } */
671 int error;
672 size_t maxalloc, nchanges, nevents;
673 struct kevent_ops netbsd32_kevent_ops = {
674 keo_fetch_timeout: netbsd32_kevent_fetch_timeout,
675 keo_fetch_changes: netbsd32_kevent_fetch_changes,
676 keo_put_events: netbsd32_kevent_put_events,
679 nchanges = SCARG(uap, nchanges);
680 nevents = SCARG(uap, nevents);
681 maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents));
682 netbsd32_kevent_ops.keo_private =
683 malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP,
684 M_WAITOK);
686 error = kevent1(retval, SCARG(uap, fd),
687 NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
688 NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
689 NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
691 free(netbsd32_kevent_ops.keo_private, M_TEMP);
692 return error;
693 return 0;
697 compat_50_netbsd32_pselect(struct lwp *l,
698 const struct compat_50_netbsd32_pselect_args *uap, register_t *retval)
700 /* {
701 syscallarg(int) nd;
702 syscallarg(netbsd32_fd_setp_t) in;
703 syscallarg(netbsd32_fd_setp_t) ou;
704 syscallarg(netbsd32_fd_setp_t) ex;
705 syscallarg(const netbsd32_timespec50p_t) ts;
706 syscallarg(const netbsd32_sigsetp_t) mask;
707 } */
708 int error;
709 struct netbsd32_timespec50 ts32;
710 struct timespec ats, *ts = NULL;
711 sigset_t amask, *mask = NULL;
713 if (SCARG_P32(uap, ts)) {
714 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
715 if (error != 0)
716 return error;
717 netbsd32_to_timespec50(&ts32, &ats);
718 ts = &ats;
720 if (SCARG_P32(uap, mask)) {
721 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
722 if (error != 0)
723 return error;
724 mask = &amask;
727 return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in),
728 SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask);
729 return 0;
733 compat_50_netbsd32_pollts(struct lwp *l,
734 const struct compat_50_netbsd32_pollts_args *uap, register_t *retval)
736 /* {
737 syscallarg(struct netbsd32_pollfdp_t) fds;
738 syscallarg(u_int) nfds;
739 syscallarg(const netbsd32_timespec50p_t) ts;
740 syscallarg(const netbsd32_sigsetp_t) mask;
741 } */
742 int error;
743 struct netbsd32_timespec50 ts32;
744 struct timespec ats, *ts = NULL;
745 sigset_t amask, *mask = NULL;
747 if (SCARG_P32(uap, ts)) {
748 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32));
749 if (error != 0)
750 return error;
751 netbsd32_to_timespec50(&ts32, &ats);
752 ts = &ats;
754 if (NETBSD32PTR64( SCARG(uap, mask))) {
755 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask));
756 if (error != 0)
757 return error;
758 mask = &amask;
761 return pollcommon(retval, SCARG_P32(uap, fds),
762 SCARG(uap, nfds), ts, mask);
766 compat_50_netbsd32___stat30(struct lwp *l,
767 const struct compat_50_netbsd32___stat30_args *uap, register_t *retval)
769 /* {
770 syscallarg(const netbsd32_charp) path;
771 syscallarg(netbsd32_stat50p_t) ub;
772 } */
773 struct netbsd32_stat50 sb32;
774 struct stat sb;
775 int error;
776 const char *path;
778 path = SCARG_P32(uap, path);
780 error = do_sys_stat(path, FOLLOW, &sb);
781 if (error)
782 return error;
783 netbsd32_from___stat50(&sb, &sb32);
784 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
785 return error;
789 compat_50_netbsd32___fstat30(struct lwp *l,
790 const struct compat_50_netbsd32___fstat30_args *uap, register_t *retval)
792 /* {
793 syscallarg(int) fd;
794 syscallarg(netbsd32_stat50p_t) sb;
795 } */
796 struct netbsd32_stat50 sb32;
797 struct stat ub;
798 int error;
800 error = do_sys_fstat(SCARG(uap, fd), &ub);
801 if (error == 0) {
802 netbsd32_from___stat50(&ub, &sb32);
803 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
805 return error;
809 compat_50_netbsd32___lstat30(struct lwp *l,
810 const struct compat_50_netbsd32___lstat30_args *uap, register_t *retval)
812 /* {
813 syscallarg(const netbsd32_charp) path;
814 syscallarg(netbsd32_stat50p_t) ub;
815 } */
816 struct netbsd32_stat50 sb32;
817 struct stat sb;
818 int error;
819 const char *path;
821 path = SCARG_P32(uap, path);
823 error = do_sys_stat(path, NOFOLLOW, &sb);
824 if (error)
825 return error;
826 netbsd32_from___stat50(&sb, &sb32);
827 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
828 return error;
832 compat_50_netbsd32___fhstat40(struct lwp *l, const struct compat_50_netbsd32___fhstat40_args *uap, register_t *retval)
834 /* {
835 syscallarg(const netbsd32_pointer_t) fhp;
836 syscallarg(netbsd32_size_t) fh_size;
837 syscallarg(netbsd32_stat50p_t) sb;
838 } */
839 struct stat sb;
840 struct netbsd32_stat50 sb32;
841 int error;
843 error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
844 if (error != 0) {
845 netbsd32_from___stat50(&sb, &sb32);
846 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
848 return error;
852 compat_50_netbsd32_wait4(struct lwp *l, const struct compat_50_netbsd32_wait4_args *uap, register_t *retval)
854 /* {
855 syscallarg(int) pid;
856 syscallarg(netbsd32_intp) status;
857 syscallarg(int) options;
858 syscallarg(netbsd32_rusage50p_t) rusage;
859 } */
860 int error, status, pid = SCARG(uap, pid);
861 struct netbsd32_rusage50 ru32;
862 struct rusage ru;
864 error = do_sys_wait(&pid, &status, SCARG(uap, options),
865 SCARG_P32(uap, rusage) != NULL ? &ru : NULL);
867 retval[0] = pid;
868 if (pid == 0)
869 return error;
871 if (SCARG_P32(uap, rusage)) {
872 netbsd32_from_rusage50(&ru, &ru32);
873 error = copyout(&ru32, SCARG_P32(uap, rusage), sizeof(ru32));
876 if (error == 0 && SCARG_P32(uap, status))
877 error = copyout(&status, SCARG_P32(uap, status), sizeof(status));
879 return error;
884 compat_50_netbsd32_getrusage(struct lwp *l, const struct compat_50_netbsd32_getrusage_args *uap, register_t *retval)
886 /* {
887 syscallarg(int) who;
888 syscallarg(netbsd32_rusage50p_t) rusage;
889 } */
890 struct proc *p = l->l_proc;
891 struct rusage *rup;
892 struct netbsd32_rusage50 ru;
894 switch (SCARG(uap, who)) {
896 case RUSAGE_SELF:
897 rup = &p->p_stats->p_ru;
898 mutex_enter(p->p_lock);
899 calcru(p, &rup->ru_utime, &rup->ru_stime, NULL, NULL);
900 mutex_exit(p->p_lock);
901 break;
903 case RUSAGE_CHILDREN:
904 rup = &p->p_stats->p_cru;
905 break;
907 default:
908 return (EINVAL);
910 netbsd32_from_rusage50(rup, &ru);
911 return copyout(&ru, SCARG_P32(uap, rusage), sizeof(ru));
915 compat_50_netbsd32_setitimer(struct lwp *l,
916 const struct compat_50_netbsd32_setitimer_args *uap, register_t *retval)
918 /* {
919 syscallarg(int) which;
920 syscallarg(const netbsd32_itimerval50p_t) itv;
921 syscallarg(netbsd32_itimerval50p_t) oitv;
922 } */
923 struct proc *p = l->l_proc;
924 struct netbsd32_itimerval50 s32it, *itv32;
925 int which = SCARG(uap, which);
926 struct compat_50_netbsd32_getitimer_args getargs;
927 struct itimerval aitv;
928 int error;
930 if ((u_int)which > ITIMER_PROF)
931 return (EINVAL);
932 itv32 = SCARG_P32(uap, itv);
933 if (itv32) {
934 if ((error = copyin(itv32, &s32it, sizeof(s32it))))
935 return (error);
936 netbsd32_to_itimerval50(&s32it, &aitv);
938 if (SCARG_P32(uap, oitv) != 0) {
939 SCARG(&getargs, which) = which;
940 SCARG(&getargs, itv) = SCARG(uap, oitv);
941 if ((error = compat_50_netbsd32_getitimer(l, &getargs, retval)) != 0)
942 return (error);
944 if (itv32 == 0)
945 return 0;
947 return dosetitimer(p, which, &aitv);
951 compat_50_netbsd32_getitimer(struct lwp *l, const struct compat_50_netbsd32_getitimer_args *uap, register_t *retval)
953 /* {
954 syscallarg(int) which;
955 syscallarg(netbsd32_itimerval50p_t) itv;
956 } */
957 struct proc *p = l->l_proc;
958 struct netbsd32_itimerval50 s32it;
959 struct itimerval aitv;
960 int error;
962 error = dogetitimer(p, SCARG(uap, which), &aitv);
963 if (error)
964 return error;
966 netbsd32_from_itimerval50(&aitv, &s32it);
967 return copyout(&s32it, SCARG_P32(uap, itv), sizeof(s32it));
970 #if defined(SYSVSEM)
973 compat_50_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval)
975 return do_netbsd32___semctl14(l, uap, retval, NULL);
979 do_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval, void *vkarg)
981 /* {
982 syscallarg(int) semid;
983 syscallarg(int) semnum;
984 syscallarg(int) cmd;
985 syscallarg(netbsd32_semun50p_t) arg;
986 } */
987 struct semid_ds sembuf;
988 struct netbsd32_semid_ds50 sembuf32;
989 int cmd, error;
990 void *pass_arg;
991 union __semun karg;
992 union netbsd32_semun50 karg32;
994 cmd = SCARG(uap, cmd);
996 switch (cmd) {
997 case IPC_SET:
998 case IPC_STAT:
999 pass_arg = &sembuf;
1000 break;
1002 case GETALL:
1003 case SETVAL:
1004 case SETALL:
1005 pass_arg = &karg;
1006 break;
1007 default:
1008 pass_arg = NULL;
1009 break;
1012 if (pass_arg) {
1013 if (vkarg != NULL)
1014 karg32 = *(union netbsd32_semun50 *)vkarg;
1015 else {
1016 error = copyin(SCARG_P32(uap, arg), &karg32,
1017 sizeof(karg32));
1018 if (error)
1019 return error;
1021 if (pass_arg == &karg) {
1022 switch (cmd) {
1023 case GETALL:
1024 case SETALL:
1025 karg.array = NETBSD32PTR64(karg32.array);
1026 break;
1027 case SETVAL:
1028 karg.val = karg32.val;
1029 break;
1032 if (cmd == IPC_SET) {
1033 error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32,
1034 sizeof(sembuf32));
1035 if (error)
1036 return (error);
1037 netbsd32_to_semid_ds50(&sembuf32, &sembuf);
1041 error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
1042 pass_arg, retval);
1044 if (error == 0 && cmd == IPC_STAT) {
1045 netbsd32_from_semid_ds50(&sembuf, &sembuf32);
1046 error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf),
1047 sizeof(sembuf32));
1050 return (error);
1052 #endif
1054 #if defined(SYSVMSG)
1057 compat_50_netbsd32___msgctl13(struct lwp *l, const struct compat_50_netbsd32___msgctl13_args *uap, register_t *retval)
1059 /* {
1060 syscallarg(int) msqid;
1061 syscallarg(int) cmd;
1062 syscallarg(netbsd32_msqid_ds50p_t) buf;
1063 } */
1064 struct msqid_ds ds;
1065 struct netbsd32_msqid_ds50 ds32;
1066 int error, cmd;
1068 cmd = SCARG(uap, cmd);
1069 if (cmd == IPC_SET) {
1070 error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
1071 if (error)
1072 return error;
1073 netbsd32_to_msqid_ds50(&ds32, &ds);
1076 error = msgctl1(l, SCARG(uap, msqid), cmd,
1077 (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
1079 if (error == 0 && cmd == IPC_STAT) {
1080 netbsd32_from_msqid_ds50(&ds, &ds32);
1081 error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
1084 return error;
1086 #endif
1088 #if defined(SYSVSHM)
1091 compat_50_netbsd32___shmctl13(struct lwp *l, const struct compat_50_netbsd32___shmctl13_args *uap, register_t *retval)
1093 /* {
1094 syscallarg(int) shmid;
1095 syscallarg(int) cmd;
1096 syscallarg(netbsd32_shmid_ds50p_t) buf;
1097 } */
1098 struct shmid_ds ds;
1099 struct netbsd32_shmid_ds50 ds32;
1100 int error, cmd;
1102 cmd = SCARG(uap, cmd);
1103 if (cmd == IPC_SET) {
1104 error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
1105 if (error)
1106 return error;
1107 netbsd32_to_shmid_ds50(&ds32, &ds);
1110 error = shmctl1(l, SCARG(uap, shmid), cmd,
1111 (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
1113 if (error == 0 && cmd == IPC_STAT) {
1114 netbsd32_from_shmid_ds50(&ds, &ds32);
1115 error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
1118 return error;
1120 #endif