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