netbsd32_netbsd.c revision 1.203 1 /* $NetBSD: netbsd32_netbsd.c,v 1.203 2016/09/13 07:39:45 martin Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001, 2008 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.203 2016/09/13 07:39:45 martin Exp $");
31
32 #if defined(_KERNEL_OPT)
33 #include "opt_ddb.h"
34 #include "opt_ntp.h"
35 #include "opt_compat_netbsd.h"
36 #include "opt_compat_43.h"
37 #include "opt_sysv.h"
38 #include "opt_syscall_debug.h"
39 #endif
40
41 /*
42 * Though COMPAT_OLDSOCK is needed only for COMPAT_43, SunOS, Linux,
43 * HP-UX, FreeBSD, Ultrix, OSF1, we define it unconditionally so that
44 * this would be module-safe.
45 */
46 #define COMPAT_OLDSOCK /* used by <sys/socket.h> */
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 //#define msg __msg /* Don't ask me! */
52 #include <sys/mount.h>
53 #include <sys/socket.h>
54 #include <sys/sockio.h>
55 #include <sys/socketvar.h>
56 #include <sys/mbuf.h>
57 #include <sys/mman.h>
58 #include <sys/stat.h>
59 #include <sys/swap.h>
60 #include <sys/time.h>
61 #include <sys/signalvar.h>
62 #include <sys/ptrace.h>
63 #include <sys/ktrace.h>
64 #include <sys/trace.h>
65 #include <sys/resourcevar.h>
66 #include <sys/pool.h>
67 #include <sys/vnode.h>
68 #include <sys/file.h>
69 #include <sys/filedesc.h>
70 #include <sys/namei.h>
71 #include <sys/dirent.h>
72 #include <sys/quotactl.h>
73 #include <sys/kauth.h>
74 #include <sys/vfs_syscalls.h>
75
76 #include <uvm/uvm_extern.h>
77 #include <uvm/uvm_swap.h>
78
79 #include <sys/syscallargs.h>
80 #include <sys/proc.h>
81 #include <sys/acct.h>
82 #include <sys/exec.h>
83
84 #include <net/if.h>
85
86 #include <compat/netbsd32/netbsd32.h>
87 #include <compat/netbsd32/netbsd32_exec.h>
88 #include <compat/netbsd32/netbsd32_syscall.h>
89 #include <compat/netbsd32/netbsd32_syscallargs.h>
90 #include <compat/netbsd32/netbsd32_conv.h>
91
92 #if defined(DDB)
93 #include <ddb/ddbvar.h>
94 #endif
95
96 extern struct sysent netbsd32_sysent[];
97 #ifdef SYSCALL_DEBUG
98 extern const char * const netbsd32_syscallnames[];
99 #endif
100 #ifdef __HAVE_SYSCALL_INTERN
101 void netbsd32_syscall_intern(struct proc *);
102 #else
103 void syscall(void);
104 #endif
105
106 void netbsd32_ktrpsig(int, sig_t, const sigset_t *, const ksiginfo_t *);
107
108 #define LIMITCHECK(a, b) ((a) != RLIM_INFINITY && (a) > (b))
109
110 #ifdef COMPAT_16
111 extern char netbsd32_sigcode[], netbsd32_esigcode[];
112 struct uvm_object *emul_netbsd32_object;
113 #endif
114
115 extern struct sysctlnode netbsd32_sysctl_root;
116
117 #ifdef MODULAR
118 #include <compat/netbsd32/netbsd32_syscalls_autoload.c>
119 #endif
120
121 struct emul emul_netbsd32 = {
122 .e_name = "netbsd32",
123 .e_path = "/emul/netbsd32",
124 #ifndef __HAVE_MINIMAL_EMUL
125 .e_flags = 0,
126 .e_errno = NULL,
127 .e_nosys = NETBSD32_SYS_netbsd32_syscall,
128 .e_nsysent = NETBSD32_SYS_NSYSENT,
129 #endif
130 .e_sysent = netbsd32_sysent,
131 #ifdef SYSCALL_DEBUG
132 .e_syscallnames = netbsd32_syscallnames,
133 #else
134 .e_syscallnames = NULL,
135 #endif
136 #ifdef MODULAR
137 .e_sc_autoload = netbsd32_syscalls_autoload,
138 #endif
139 .e_sendsig = netbsd32_sendsig,
140 .e_trapsignal = trapsignal,
141 .e_tracesig = NULL,
142 #ifdef COMPAT_16
143 .e_sigcode = netbsd32_sigcode,
144 .e_esigcode = netbsd32_esigcode,
145 .e_sigobject = &emul_netbsd32_object,
146 #else
147 .e_sigcode = NULL,
148 .e_esigcode = NULL,
149 .e_sigobject = NULL,
150 #endif
151 .e_setregs = netbsd32_setregs,
152 .e_proc_exec = NULL,
153 .e_proc_fork = NULL,
154 .e_proc_exit = NULL,
155 .e_lwp_fork = NULL,
156 .e_lwp_exit = NULL,
157 #ifdef __HAVE_SYSCALL_INTERN
158 .e_syscall_intern = netbsd32_syscall_intern,
159 #else
160 .e_syscall = syscall,
161 #endif
162 .e_sysctlovly = &netbsd32_sysctl_root,
163 .e_fault = NULL,
164 .e_vm_default_addr = netbsd32_vm_default_addr,
165 .e_usertrap = NULL,
166 .e_ucsize = sizeof(ucontext32_t),
167 .e_startlwp = startlwp32,
168 .e_ktrpsig = netbsd32_ktrpsig
169 };
170
171 /*
172 * below are all the standard NetBSD system calls, in the 32bit
173 * environment, with the necessary conversions to 64bit before
174 * calling the real syscall. anything that needs special
175 * attention is handled elsewhere.
176 */
177
178 int
179 netbsd32_exit(struct lwp *l, const struct netbsd32_exit_args *uap, register_t *retval)
180 {
181 /* {
182 syscallarg(int) rval;
183 } */
184 struct sys_exit_args ua;
185
186 NETBSD32TO64_UAP(rval);
187 return sys_exit(l, &ua, retval);
188 }
189
190 int
191 netbsd32_read(struct lwp *l, const struct netbsd32_read_args *uap, register_t *retval)
192 {
193 /* {
194 syscallarg(int) fd;
195 syscallarg(netbsd32_voidp) buf;
196 syscallarg(netbsd32_size_t) nbyte;
197 } */
198 struct sys_read_args ua;
199
200 NETBSD32TO64_UAP(fd);
201 NETBSD32TOP_UAP(buf, void *);
202 NETBSD32TOX_UAP(nbyte, size_t);
203 return sys_read(l, &ua, retval);
204 }
205
206 int
207 netbsd32_write(struct lwp *l, const struct netbsd32_write_args *uap, register_t *retval)
208 {
209 /* {
210 syscallarg(int) fd;
211 syscallarg(const netbsd32_voidp) buf;
212 syscallarg(netbsd32_size_t) nbyte;
213 } */
214 struct sys_write_args ua;
215
216 NETBSD32TO64_UAP(fd);
217 NETBSD32TOP_UAP(buf, void *);
218 NETBSD32TOX_UAP(nbyte, size_t);
219 return sys_write(l, &ua, retval);
220 }
221
222 int
223 netbsd32_close(struct lwp *l, const struct netbsd32_close_args *uap, register_t *retval)
224 {
225 /* {
226 syscallarg(int) fd;
227 } */
228 struct sys_close_args ua;
229
230 NETBSD32TO64_UAP(fd);
231 return sys_close(l, &ua, retval);
232 }
233
234 int
235 netbsd32_open(struct lwp *l, const struct netbsd32_open_args *uap, register_t *retval)
236 {
237 /* {
238 syscallarg(const netbsd32_charp) path;
239 syscallarg(int) flags;
240 syscallarg(mode_t) mode;
241 } */
242 struct sys_open_args ua;
243
244 NETBSD32TOP_UAP(path, const char);
245 NETBSD32TO64_UAP(flags);
246 NETBSD32TO64_UAP(mode);
247
248 return sys_open(l, &ua, retval);
249 }
250
251 int
252 netbsd32_link(struct lwp *l, const struct netbsd32_link_args *uap, register_t *retval)
253 {
254 /* {
255 syscallarg(const netbsd32_charp) path;
256 syscallarg(const netbsd32_charp) link;
257 } */
258 struct sys_link_args ua;
259
260 NETBSD32TOP_UAP(path, const char);
261 NETBSD32TOP_UAP(link, const char);
262 return (sys_link(l, &ua, retval));
263 }
264
265 int
266 netbsd32_unlink(struct lwp *l, const struct netbsd32_unlink_args *uap, register_t *retval)
267 {
268 /* {
269 syscallarg(const netbsd32_charp) path;
270 } */
271 struct sys_unlink_args ua;
272
273 NETBSD32TOP_UAP(path, const char);
274
275 return (sys_unlink(l, &ua, retval));
276 }
277
278 int
279 netbsd32_chdir(struct lwp *l, const struct netbsd32_chdir_args *uap, register_t *retval)
280 {
281 /* {
282 syscallarg(const netbsd32_charp) path;
283 } */
284 struct sys_chdir_args ua;
285
286 NETBSD32TOP_UAP(path, const char);
287
288 return (sys_chdir(l, &ua, retval));
289 }
290
291 int
292 netbsd32_fchdir(struct lwp *l, const struct netbsd32_fchdir_args *uap, register_t *retval)
293 {
294 /* {
295 syscallarg(int) fd;
296 } */
297 struct sys_fchdir_args ua;
298
299 NETBSD32TO64_UAP(fd);
300
301 return (sys_fchdir(l, &ua, retval));
302 }
303
304 int
305 netbsd32___mknod50(struct lwp *l, const struct netbsd32___mknod50_args *uap, register_t *retval)
306 {
307 /* {
308 syscallarg(const netbsd32_charp) path;
309 syscallarg(mode_t) mode;
310 syscallarg(netbsd32_dev_t) dev;
311 } */
312
313 return do_sys_mknod(l, SCARG_P32(uap, path), SCARG(uap, mode),
314 SCARG(uap, dev), retval, UIO_USERSPACE);
315 }
316
317 int
318 netbsd32_chmod(struct lwp *l, const struct netbsd32_chmod_args *uap, register_t *retval)
319 {
320 /* {
321 syscallarg(const netbsd32_charp) path;
322 syscallarg(mode_t) mode;
323 } */
324 struct sys_chmod_args ua;
325
326 NETBSD32TOP_UAP(path, const char);
327 NETBSD32TO64_UAP(mode);
328
329 return (sys_chmod(l, &ua, retval));
330 }
331
332 int
333 netbsd32_chown(struct lwp *l, const struct netbsd32_chown_args *uap, register_t *retval)
334 {
335 /* {
336 syscallarg(const netbsd32_charp) path;
337 syscallarg(uid_t) uid;
338 syscallarg(gid_t) gid;
339 } */
340 struct sys_chown_args ua;
341
342 NETBSD32TOP_UAP(path, const char);
343 NETBSD32TO64_UAP(uid);
344 NETBSD32TO64_UAP(gid);
345
346 return (sys_chown(l, &ua, retval));
347 }
348
349 int
350 netbsd32_break(struct lwp *l, const struct netbsd32_break_args *uap, register_t *retval)
351 {
352 /* {
353 syscallarg(netbsd32_charp) nsize;
354 } */
355 struct sys_obreak_args ua;
356
357 NETBSD32TOP_UAP(nsize, char);
358 return (sys_obreak(l, &ua, retval));
359 }
360
361 int
362 netbsd32_mount(struct lwp *l, const struct netbsd32_mount_args *uap, register_t *retval)
363 {
364 #ifdef COMPAT_40
365 /* {
366 syscallarg(const netbsd32_charp) type;
367 syscallarg(const netbsd32_charp) path;
368 syscallarg(int) flags;
369 syscallarg(netbsd32_voidp) data;
370 } */
371 struct compat_40_sys_mount_args ua;
372
373 NETBSD32TOP_UAP(type, const char);
374 NETBSD32TOP_UAP(path, const char);
375 NETBSD32TO64_UAP(flags);
376 NETBSD32TOP_UAP(data, void);
377 return (compat_40_sys_mount(l, &ua, retval));
378 #else
379 return ENOSYS;
380 #endif
381 }
382
383 int
384 netbsd32_unmount(struct lwp *l, const struct netbsd32_unmount_args *uap, register_t *retval)
385 {
386 /* {
387 syscallarg(const netbsd32_charp) path;
388 syscallarg(int) flags;
389 } */
390 struct sys_unmount_args ua;
391
392 NETBSD32TOP_UAP(path, const char);
393 NETBSD32TO64_UAP(flags);
394 return (sys_unmount(l, &ua, retval));
395 }
396
397 int
398 netbsd32_setuid(struct lwp *l, const struct netbsd32_setuid_args *uap, register_t *retval)
399 {
400 /* {
401 syscallarg(uid_t) uid;
402 } */
403 struct sys_setuid_args ua;
404
405 NETBSD32TO64_UAP(uid);
406 return (sys_setuid(l, &ua, retval));
407 }
408
409 int
410 netbsd32_ptrace(struct lwp *l, const struct netbsd32_ptrace_args *uap, register_t *retval)
411 {
412 /* {
413 syscallarg(int) req;
414 syscallarg(pid_t) pid;
415 syscallarg(netbsd32_voidp) addr;
416 syscallarg(int) data;
417 } */
418 struct sys_ptrace_args ua;
419
420 NETBSD32TO64_UAP(req);
421 NETBSD32TO64_UAP(pid);
422 NETBSD32TOP_UAP(addr, void *);
423 NETBSD32TO64_UAP(data);
424
425 return (*sysent[SYS_ptrace].sy_call)(l, &ua, retval);
426 }
427
428 int
429 netbsd32_accept(struct lwp *l, const struct netbsd32_accept_args *uap, register_t *retval)
430 {
431 /* {
432 syscallarg(int) s;
433 syscallarg(netbsd32_sockaddrp_t) name;
434 syscallarg(netbsd32_intp) anamelen;
435 } */
436 struct sys_accept_args ua;
437
438 NETBSD32TO64_UAP(s);
439 NETBSD32TOP_UAP(name, struct sockaddr);
440 NETBSD32TOP_UAP(anamelen, socklen_t);
441 return (sys_accept(l, &ua, retval));
442 }
443
444 int
445 netbsd32_getpeername(struct lwp *l, const struct netbsd32_getpeername_args *uap, register_t *retval)
446 {
447 /* {
448 syscallarg(int) fdes;
449 syscallarg(netbsd32_sockaddrp_t) asa;
450 syscallarg(netbsd32_intp) alen;
451 } */
452 struct sys_getpeername_args ua;
453
454 NETBSD32TO64_UAP(fdes);
455 NETBSD32TOP_UAP(asa, struct sockaddr);
456 NETBSD32TOP_UAP(alen, socklen_t);
457 /* NB: do the protocol specific sockaddrs need to be converted? */
458 return (sys_getpeername(l, &ua, retval));
459 }
460
461 int
462 netbsd32_getsockname(struct lwp *l, const struct netbsd32_getsockname_args *uap, register_t *retval)
463 {
464 /* {
465 syscallarg(int) fdes;
466 syscallarg(netbsd32_sockaddrp_t) asa;
467 syscallarg(netbsd32_intp) alen;
468 } */
469 struct sys_getsockname_args ua;
470
471 NETBSD32TO64_UAP(fdes);
472 NETBSD32TOP_UAP(asa, struct sockaddr);
473 NETBSD32TOP_UAP(alen, socklen_t);
474 return (sys_getsockname(l, &ua, retval));
475 }
476
477 int
478 netbsd32_access(struct lwp *l, const struct netbsd32_access_args *uap, register_t *retval)
479 {
480 /* {
481 syscallarg(const netbsd32_charp) path;
482 syscallarg(int) flags;
483 } */
484 struct sys_access_args ua;
485
486 NETBSD32TOP_UAP(path, const char);
487 NETBSD32TO64_UAP(flags);
488
489 return sys_access(l, &ua, retval);
490 }
491
492 int
493 netbsd32_chflags(struct lwp *l, const struct netbsd32_chflags_args *uap, register_t *retval)
494 {
495 /* {
496 syscallarg(const netbsd32_charp) path;
497 syscallarg(netbsd32_u_long) flags;
498 } */
499 struct sys_chflags_args ua;
500
501 NETBSD32TOP_UAP(path, const char);
502 NETBSD32TO64_UAP(flags);
503
504 return (sys_chflags(l, &ua, retval));
505 }
506
507 int
508 netbsd32_fchflags(struct lwp *l, const struct netbsd32_fchflags_args *uap, register_t *retval)
509 {
510 /* {
511 syscallarg(int) fd;
512 syscallarg(netbsd32_u_long) flags;
513 } */
514 struct sys_fchflags_args ua;
515
516 NETBSD32TO64_UAP(fd);
517 NETBSD32TO64_UAP(flags);
518
519 return (sys_fchflags(l, &ua, retval));
520 }
521
522 int
523 netbsd32_lchflags(struct lwp *l, const struct netbsd32_lchflags_args *uap, register_t *retval)
524 {
525 /* {
526 syscallarg(const char *) path;
527 syscallarg(netbsd32_u_long) flags;
528 } */
529 struct sys_lchflags_args ua;
530
531 NETBSD32TOP_UAP(path, const char);
532 NETBSD32TO64_UAP(flags);
533
534 return (sys_lchflags(l, &ua, retval));
535 }
536
537 int
538 netbsd32_kill(struct lwp *l, const struct netbsd32_kill_args *uap, register_t *retval)
539 {
540 /* {
541 syscallarg(int) pid;
542 syscallarg(int) signum;
543 } */
544 struct sys_kill_args ua;
545
546 NETBSD32TO64_UAP(pid);
547 NETBSD32TO64_UAP(signum);
548
549 return (sys_kill(l, &ua, retval));
550 }
551
552 int
553 netbsd32_dup(struct lwp *l, const struct netbsd32_dup_args *uap, register_t *retval)
554 {
555 /* {
556 syscallarg(int) fd;
557 } */
558 struct sys_dup_args ua;
559
560 NETBSD32TO64_UAP(fd);
561
562 return (sys_dup(l, &ua, retval));
563 }
564
565 int
566 netbsd32_profil(struct lwp *l, const struct netbsd32_profil_args *uap, register_t *retval)
567 {
568 /* {
569 syscallarg(netbsd32_voidp) samples;
570 syscallarg(netbsd32_size_t) size;
571 syscallarg(netbsd32_u_long) offset;
572 syscallarg(u_int) scale;
573 } */
574 struct sys_profil_args ua;
575
576 NETBSD32TOP_UAP(samples, void *);
577 NETBSD32TOX_UAP(size, size_t);
578 NETBSD32TOX_UAP(offset, u_long);
579 NETBSD32TO64_UAP(scale);
580 return (sys_profil(l, &ua, retval));
581 }
582
583 int
584 netbsd32_ktrace(struct lwp *l, const struct netbsd32_ktrace_args *uap, register_t *retval)
585 {
586 /* {
587 syscallarg(const netbsd32_charp) fname;
588 syscallarg(int) ops;
589 syscallarg(int) facs;
590 syscallarg(int) pid;
591 } */
592 struct sys_ktrace_args ua;
593
594 NETBSD32TOP_UAP(fname, const char);
595 NETBSD32TO64_UAP(ops);
596 NETBSD32TO64_UAP(facs);
597 NETBSD32TO64_UAP(pid);
598 return (sys_ktrace(l, &ua, retval));
599 }
600
601 int
602 netbsd32_utrace(struct lwp *l, const struct netbsd32_utrace_args *uap, register_t *retval)
603 {
604 /* {
605 syscallarg(const netbsd32_charp) label;
606 syscallarg(netbsd32_voidp) addr;
607 syscallarg(netbsd32_size_t) len;
608 } */
609 struct sys_utrace_args ua;
610
611 NETBSD32TOP_UAP(label, const char);
612 NETBSD32TOP_UAP(addr, void);
613 NETBSD32TO64_UAP(len);
614 return (sys_utrace(l, &ua, retval));
615 }
616
617 int
618 netbsd32___getlogin(struct lwp *l, const struct netbsd32___getlogin_args *uap, register_t *retval)
619 {
620 /* {
621 syscallarg(netbsd32_charp) namebuf;
622 syscallarg(u_int) namelen;
623 } */
624 struct sys___getlogin_args ua;
625
626 NETBSD32TOP_UAP(namebuf, char);
627 NETBSD32TO64_UAP(namelen);
628 return (sys___getlogin(l, &ua, retval));
629 }
630
631 int
632 netbsd32_setlogin(struct lwp *l, const struct netbsd32_setlogin_args *uap, register_t *retval)
633 {
634 /* {
635 syscallarg(const netbsd32_charp) namebuf;
636 } */
637 struct sys___setlogin_args ua;
638
639 NETBSD32TOP_UAP(namebuf, char);
640 return (sys___setlogin(l, &ua, retval));
641 }
642
643 int
644 netbsd32_acct(struct lwp *l, const struct netbsd32_acct_args *uap, register_t *retval)
645 {
646 /* {
647 syscallarg(const netbsd32_charp) path;
648 } */
649 struct sys_acct_args ua;
650
651 NETBSD32TOP_UAP(path, const char);
652 return (sys_acct(l, &ua, retval));
653 }
654
655 int
656 netbsd32_revoke(struct lwp *l, const struct netbsd32_revoke_args *uap, register_t *retval)
657 {
658 /* {
659 syscallarg(const netbsd32_charp) path;
660 } */
661 struct sys_revoke_args ua;
662
663 NETBSD32TOP_UAP(path, const char);
664
665 return (sys_revoke(l, &ua, retval));
666 }
667
668 int
669 netbsd32_symlink(struct lwp *l, const struct netbsd32_symlink_args *uap, register_t *retval)
670 {
671 /* {
672 syscallarg(const netbsd32_charp) path;
673 syscallarg(const netbsd32_charp) link;
674 } */
675 struct sys_symlink_args ua;
676
677 NETBSD32TOP_UAP(path, const char);
678 NETBSD32TOP_UAP(link, const char);
679
680 return (sys_symlink(l, &ua, retval));
681 }
682
683 int
684 netbsd32_readlink(struct lwp *l, const struct netbsd32_readlink_args *uap, register_t *retval)
685 {
686 /* {
687 syscallarg(const netbsd32_charp) path;
688 syscallarg(netbsd32_charp) buf;
689 syscallarg(netbsd32_size_t) count;
690 } */
691 struct sys_readlink_args ua;
692
693 NETBSD32TOP_UAP(path, const char);
694 NETBSD32TOP_UAP(buf, char);
695 NETBSD32TOX_UAP(count, size_t);
696
697 return (sys_readlink(l, &ua, retval));
698 }
699
700 int
701 netbsd32_umask(struct lwp *l, const struct netbsd32_umask_args *uap, register_t *retval)
702 {
703 /* {
704 syscallarg(mode_t) newmask;
705 } */
706 struct sys_umask_args ua;
707
708 NETBSD32TO64_UAP(newmask);
709 return (sys_umask(l, &ua, retval));
710 }
711
712 int
713 netbsd32_chroot(struct lwp *l, const struct netbsd32_chroot_args *uap, register_t *retval)
714 {
715 /* {
716 syscallarg(const netbsd32_charp) path;
717 } */
718 struct sys_chroot_args ua;
719
720 NETBSD32TOP_UAP(path, const char);
721 return (sys_chroot(l, &ua, retval));
722 }
723
724 int
725 netbsd32_sbrk(struct lwp *l, const struct netbsd32_sbrk_args *uap, register_t *retval)
726 {
727 /* {
728 syscallarg(int) incr;
729 } */
730 struct sys_sbrk_args ua;
731
732 NETBSD32TO64_UAP(incr);
733 return (sys_sbrk(l, &ua, retval));
734 }
735
736 int
737 netbsd32_sstk(struct lwp *l, const struct netbsd32_sstk_args *uap, register_t *retval)
738 {
739 /* {
740 syscallarg(int) incr;
741 } */
742 struct sys_sstk_args ua;
743
744 NETBSD32TO64_UAP(incr);
745 return (sys_sstk(l, &ua, retval));
746 }
747
748 int
749 netbsd32_munmap(struct lwp *l, const struct netbsd32_munmap_args *uap, register_t *retval)
750 {
751 /* {
752 syscallarg(netbsd32_voidp) addr;
753 syscallarg(netbsd32_size_t) len;
754 } */
755 struct sys_munmap_args ua;
756
757 NETBSD32TOP_UAP(addr, void);
758 NETBSD32TOX_UAP(len, size_t);
759 return (sys_munmap(l, &ua, retval));
760 }
761
762 int
763 netbsd32_mprotect(struct lwp *l, const struct netbsd32_mprotect_args *uap, register_t *retval)
764 {
765 /* {
766 syscallarg(netbsd32_voidp) addr;
767 syscallarg(netbsd32_size_t) len;
768 syscallarg(int) prot;
769 } */
770 struct sys_mprotect_args ua;
771
772 NETBSD32TOP_UAP(addr, void);
773 NETBSD32TOX_UAP(len, size_t);
774 NETBSD32TO64_UAP(prot);
775 return (sys_mprotect(l, &ua, retval));
776 }
777
778 int
779 netbsd32_madvise(struct lwp *l, const struct netbsd32_madvise_args *uap, register_t *retval)
780 {
781 /* {
782 syscallarg(netbsd32_voidp) addr;
783 syscallarg(netbsd32_size_t) len;
784 syscallarg(int) behav;
785 } */
786 struct sys_madvise_args ua;
787
788 NETBSD32TOP_UAP(addr, void);
789 NETBSD32TOX_UAP(len, size_t);
790 NETBSD32TO64_UAP(behav);
791 return (sys_madvise(l, &ua, retval));
792 }
793
794 int
795 netbsd32_mincore(struct lwp *l, const struct netbsd32_mincore_args *uap, register_t *retval)
796 {
797 /* {
798 syscallarg(netbsd32_voidp) addr;
799 syscallarg(netbsd32_size_t) len;
800 syscallarg(netbsd32_charp) vec;
801 } */
802 struct sys_mincore_args ua;
803
804 NETBSD32TOP_UAP(addr, void *);
805 NETBSD32TOX_UAP(len, size_t);
806 NETBSD32TOP_UAP(vec, char);
807 return (sys_mincore(l, &ua, retval));
808 }
809
810 /* XXX MOVE ME XXX ? */
811 int
812 netbsd32_getgroups(struct lwp *l, const struct netbsd32_getgroups_args *uap, register_t *retval)
813 {
814 /* {
815 syscallarg(int) gidsetsize;
816 syscallarg(netbsd32_gid_tp) gidset;
817 } */
818 struct sys_getgroups_args ua;
819
820 /* Since sizeof (gid_t) == sizeof (netbsd32_gid_t) ... */
821
822 NETBSD32TO64_UAP(gidsetsize);
823 NETBSD32TOP_UAP(gidset, gid_t);
824 return (sys_getgroups(l, &ua, retval));
825 }
826
827 int
828 netbsd32_setgroups(struct lwp *l, const struct netbsd32_setgroups_args *uap, register_t *retval)
829 {
830 /* {
831 syscallarg(int) gidsetsize;
832 syscallarg(const netbsd32_gid_tp) gidset;
833 } */
834 struct sys_setgroups_args ua;
835
836 NETBSD32TO64_UAP(gidsetsize);
837 NETBSD32TOP_UAP(gidset, gid_t);
838 return (sys_setgroups(l, &ua, retval));
839 }
840
841 int
842 netbsd32_setpgid(struct lwp *l, const struct netbsd32_setpgid_args *uap, register_t *retval)
843 {
844 /* {
845 syscallarg(int) pid;
846 syscallarg(int) pgid;
847 } */
848 struct sys_setpgid_args ua;
849
850 NETBSD32TO64_UAP(pid);
851 NETBSD32TO64_UAP(pgid);
852 return (sys_setpgid(l, &ua, retval));
853 }
854
855 int
856 netbsd32_fcntl(struct lwp *l, const struct netbsd32_fcntl_args *uap, register_t *retval)
857 {
858 /* {
859 syscallarg(int) fd;
860 syscallarg(int) cmd;
861 syscallarg(netbsd32_voidp) arg;
862 } */
863 struct sys_fcntl_args ua;
864
865 NETBSD32TO64_UAP(fd);
866 NETBSD32TO64_UAP(cmd);
867 NETBSD32TOP_UAP(arg, void);
868 /* we can do this because `struct flock' doesn't change */
869 return (sys_fcntl(l, &ua, retval));
870 }
871
872 int
873 netbsd32_dup2(struct lwp *l, const struct netbsd32_dup2_args *uap, register_t *retval)
874 {
875 /* {
876 syscallarg(int) from;
877 syscallarg(int) to;
878 } */
879 struct sys_dup2_args ua;
880
881 NETBSD32TO64_UAP(from);
882 NETBSD32TO64_UAP(to);
883 return (sys_dup2(l, &ua, retval));
884 }
885
886 int
887 netbsd32_fsync(struct lwp *l, const struct netbsd32_fsync_args *uap, register_t *retval)
888 {
889 /* {
890 syscallarg(int) fd;
891 } */
892 struct sys_fsync_args ua;
893
894 NETBSD32TO64_UAP(fd);
895 return (sys_fsync(l, &ua, retval));
896 }
897
898 int
899 netbsd32_setpriority(struct lwp *l, const struct netbsd32_setpriority_args *uap, register_t *retval)
900 {
901 /* {
902 syscallarg(int) which;
903 syscallarg(int) who;
904 syscallarg(int) prio;
905 } */
906 struct sys_setpriority_args ua;
907
908 NETBSD32TO64_UAP(which);
909 NETBSD32TO64_UAP(who);
910 NETBSD32TO64_UAP(prio);
911 return (sys_setpriority(l, &ua, retval));
912 }
913
914 int
915 netbsd32___socket30(struct lwp *l, const struct netbsd32___socket30_args *uap, register_t *retval)
916 {
917 /* {
918 syscallarg(int) domain;
919 syscallarg(int) type;
920 syscallarg(int) protocol;
921 } */
922 struct sys___socket30_args ua;
923
924 NETBSD32TO64_UAP(domain);
925 NETBSD32TO64_UAP(type);
926 NETBSD32TO64_UAP(protocol);
927 return (sys___socket30(l, &ua, retval));
928 }
929
930 int
931 netbsd32_connect(struct lwp *l, const struct netbsd32_connect_args *uap, register_t *retval)
932 {
933 /* {
934 syscallarg(int) s;
935 syscallarg(const netbsd32_sockaddrp_t) name;
936 syscallarg(int) namelen;
937 } */
938 struct sys_connect_args ua;
939
940 NETBSD32TO64_UAP(s);
941 NETBSD32TOP_UAP(name, struct sockaddr);
942 NETBSD32TO64_UAP(namelen);
943 return (sys_connect(l, &ua, retval));
944 }
945
946 int
947 netbsd32_getpriority(struct lwp *l, const struct netbsd32_getpriority_args *uap, register_t *retval)
948 {
949 /* {
950 syscallarg(int) which;
951 syscallarg(int) who;
952 } */
953 struct sys_getpriority_args ua;
954
955 NETBSD32TO64_UAP(which);
956 NETBSD32TO64_UAP(who);
957 return (sys_getpriority(l, &ua, retval));
958 }
959
960 int
961 netbsd32_bind(struct lwp *l, const struct netbsd32_bind_args *uap, register_t *retval)
962 {
963 /* {
964 syscallarg(int) s;
965 syscallarg(const netbsd32_sockaddrp_t) name;
966 syscallarg(int) namelen;
967 } */
968 struct sys_bind_args ua;
969
970 NETBSD32TO64_UAP(s);
971 NETBSD32TOP_UAP(name, struct sockaddr);
972 NETBSD32TO64_UAP(namelen);
973 return (sys_bind(l, &ua, retval));
974 }
975
976 int
977 netbsd32_setsockopt(struct lwp *l, const struct netbsd32_setsockopt_args *uap, register_t *retval)
978 {
979 /* {
980 syscallarg(int) s;
981 syscallarg(int) level;
982 syscallarg(int) name;
983 syscallarg(const netbsd32_voidp) val;
984 syscallarg(int) valsize;
985 } */
986 struct sys_setsockopt_args ua;
987
988 NETBSD32TO64_UAP(s);
989 NETBSD32TO64_UAP(level);
990 NETBSD32TO64_UAP(name);
991 NETBSD32TOP_UAP(val, void);
992 NETBSD32TO64_UAP(valsize);
993 /* may be more efficient to do this inline. */
994 return (sys_setsockopt(l, &ua, retval));
995 }
996
997 int
998 netbsd32_listen(struct lwp *l, const struct netbsd32_listen_args *uap, register_t *retval)
999 {
1000 /* {
1001 syscallarg(int) s;
1002 syscallarg(int) backlog;
1003 } */
1004 struct sys_listen_args ua;
1005
1006 NETBSD32TO64_UAP(s);
1007 NETBSD32TO64_UAP(backlog);
1008 return (sys_listen(l, &ua, retval));
1009 }
1010
1011 int
1012 netbsd32_fchown(struct lwp *l, const struct netbsd32_fchown_args *uap, register_t *retval)
1013 {
1014 /* {
1015 syscallarg(int) fd;
1016 syscallarg(uid_t) uid;
1017 syscallarg(gid_t) gid;
1018 } */
1019 struct sys_fchown_args ua;
1020
1021 NETBSD32TO64_UAP(fd);
1022 NETBSD32TO64_UAP(uid);
1023 NETBSD32TO64_UAP(gid);
1024 return (sys_fchown(l, &ua, retval));
1025 }
1026
1027 int
1028 netbsd32_fchmod(struct lwp *l, const struct netbsd32_fchmod_args *uap, register_t *retval)
1029 {
1030 /* {
1031 syscallarg(int) fd;
1032 syscallarg(mode_t) mode;
1033 } */
1034 struct sys_fchmod_args ua;
1035
1036 NETBSD32TO64_UAP(fd);
1037 NETBSD32TO64_UAP(mode);
1038 return (sys_fchmod(l, &ua, retval));
1039 }
1040
1041 int
1042 netbsd32_setreuid(struct lwp *l, const struct netbsd32_setreuid_args *uap, register_t *retval)
1043 {
1044 /* {
1045 syscallarg(uid_t) ruid;
1046 syscallarg(uid_t) euid;
1047 } */
1048 struct sys_setreuid_args ua;
1049
1050 NETBSD32TO64_UAP(ruid);
1051 NETBSD32TO64_UAP(euid);
1052 return (sys_setreuid(l, &ua, retval));
1053 }
1054
1055 int
1056 netbsd32_setregid(struct lwp *l, const struct netbsd32_setregid_args *uap, register_t *retval)
1057 {
1058 /* {
1059 syscallarg(gid_t) rgid;
1060 syscallarg(gid_t) egid;
1061 } */
1062 struct sys_setregid_args ua;
1063
1064 NETBSD32TO64_UAP(rgid);
1065 NETBSD32TO64_UAP(egid);
1066 return (sys_setregid(l, &ua, retval));
1067 }
1068
1069 int
1070 netbsd32_getsockopt(struct lwp *l, const struct netbsd32_getsockopt_args *uap, register_t *retval)
1071 {
1072 /* {
1073 syscallarg(int) s;
1074 syscallarg(int) level;
1075 syscallarg(int) name;
1076 syscallarg(netbsd32_voidp) val;
1077 syscallarg(netbsd32_intp) avalsize;
1078 } */
1079 struct sys_getsockopt_args ua;
1080
1081 NETBSD32TO64_UAP(s);
1082 NETBSD32TO64_UAP(level);
1083 NETBSD32TO64_UAP(name);
1084 NETBSD32TOP_UAP(val, void);
1085 NETBSD32TOP_UAP(avalsize, socklen_t);
1086 return (sys_getsockopt(l, &ua, retval));
1087 }
1088
1089 int
1090 netbsd32_rename(struct lwp *l, const struct netbsd32_rename_args *uap, register_t *retval)
1091 {
1092 /* {
1093 syscallarg(const netbsd32_charp) from;
1094 syscallarg(const netbsd32_charp) to;
1095 } */
1096 struct sys_rename_args ua;
1097
1098 NETBSD32TOP_UAP(from, const char);
1099 NETBSD32TOP_UAP(to, const char);
1100
1101 return (sys_rename(l, &ua, retval));
1102 }
1103
1104 int
1105 netbsd32_flock(struct lwp *l, const struct netbsd32_flock_args *uap, register_t *retval)
1106 {
1107 /* {
1108 syscallarg(int) fd;
1109 syscallarg(int) how;
1110 } */
1111 struct sys_flock_args ua;
1112
1113 NETBSD32TO64_UAP(fd);
1114 NETBSD32TO64_UAP(how);
1115
1116 return (sys_flock(l, &ua, retval));
1117 }
1118
1119 int
1120 netbsd32_mkfifo(struct lwp *l, const struct netbsd32_mkfifo_args *uap, register_t *retval)
1121 {
1122 /* {
1123 syscallarg(const netbsd32_charp) path;
1124 syscallarg(mode_t) mode;
1125 } */
1126 struct sys_mkfifo_args ua;
1127
1128 NETBSD32TOP_UAP(path, const char);
1129 NETBSD32TO64_UAP(mode);
1130 return (sys_mkfifo(l, &ua, retval));
1131 }
1132
1133 int
1134 netbsd32_shutdown(struct lwp *l, const struct netbsd32_shutdown_args *uap, register_t *retval)
1135 {
1136 /* {
1137 syscallarg(int) s;
1138 syscallarg(int) how;
1139 } */
1140 struct sys_shutdown_args ua;
1141
1142 NETBSD32TO64_UAP(s);
1143 NETBSD32TO64_UAP(how);
1144 return (sys_shutdown(l, &ua, retval));
1145 }
1146
1147 int
1148 netbsd32_socketpair(struct lwp *l, const struct netbsd32_socketpair_args *uap, register_t *retval)
1149 {
1150 /* {
1151 syscallarg(int) domain;
1152 syscallarg(int) type;
1153 syscallarg(int) protocol;
1154 syscallarg(netbsd32_intp) rsv;
1155 } */
1156 struct sys_socketpair_args ua;
1157
1158 NETBSD32TO64_UAP(domain);
1159 NETBSD32TO64_UAP(type);
1160 NETBSD32TO64_UAP(protocol);
1161 NETBSD32TOP_UAP(rsv, int);
1162 /* Since we're just copying out two `int's we can do this */
1163 return (sys_socketpair(l, &ua, retval));
1164 }
1165
1166 int
1167 netbsd32_mkdir(struct lwp *l, const struct netbsd32_mkdir_args *uap, register_t *retval)
1168 {
1169 /* {
1170 syscallarg(const netbsd32_charp) path;
1171 syscallarg(mode_t) mode;
1172 } */
1173 struct sys_mkdir_args ua;
1174
1175 NETBSD32TOP_UAP(path, const char);
1176 NETBSD32TO64_UAP(mode);
1177 return (sys_mkdir(l, &ua, retval));
1178 }
1179
1180 int
1181 netbsd32_rmdir(struct lwp *l, const struct netbsd32_rmdir_args *uap, register_t *retval)
1182 {
1183 /* {
1184 syscallarg(const netbsd32_charp) path;
1185 } */
1186 struct sys_rmdir_args ua;
1187
1188 NETBSD32TOP_UAP(path, const char);
1189 return (sys_rmdir(l, &ua, retval));
1190 }
1191
1192 int
1193 netbsd32___quotactl(struct lwp *l, const struct netbsd32___quotactl_args *uap, register_t *retval)
1194 {
1195 /* {
1196 syscallarg(const netbsd32_charp) path;
1197 syscallarg(netbsd32_voidp) args;
1198 } */
1199 struct netbsd32_quotactlargs args32;
1200 struct quotactl_args args;
1201 int error;
1202
1203 error = copyin(SCARG_P32(uap, args), &args32, sizeof(args32));
1204 if (error) {
1205 return error;
1206 }
1207
1208 args.qc_op = args32.qc_op;
1209 switch (args.qc_op) {
1210 case QUOTACTL_STAT:
1211 args.u.stat.qc_info = NETBSD32PTR64(args32.u.stat.qc_info);
1212 break;
1213 case QUOTACTL_IDTYPESTAT:
1214 args.u.idtypestat.qc_idtype = args32.u.idtypestat.qc_idtype;
1215 args.u.idtypestat.qc_info =
1216 NETBSD32PTR64(args32.u.idtypestat.qc_info);
1217 break;
1218 case QUOTACTL_OBJTYPESTAT:
1219 args.u.objtypestat.qc_objtype =
1220 args32.u.objtypestat.qc_objtype;
1221 args.u.objtypestat.qc_info =
1222 NETBSD32PTR64(args32.u.objtypestat.qc_info);
1223 break;
1224 case QUOTACTL_GET:
1225 args.u.get.qc_key = NETBSD32PTR64(args32.u.get.qc_key);
1226 args.u.get.qc_val = NETBSD32PTR64(args32.u.get.qc_val);
1227 break;
1228 case QUOTACTL_PUT:
1229 args.u.put.qc_key = NETBSD32PTR64(args32.u.put.qc_key);
1230 args.u.put.qc_val = NETBSD32PTR64(args32.u.put.qc_val);
1231 break;
1232 case QUOTACTL_DEL:
1233 args.u.del.qc_key = NETBSD32PTR64(args32.u.del.qc_key);
1234 break;
1235 case QUOTACTL_CURSOROPEN:
1236 args.u.cursoropen.qc_cursor =
1237 NETBSD32PTR64(args32.u.cursoropen.qc_cursor);
1238 break;
1239 case QUOTACTL_CURSORCLOSE:
1240 args.u.cursorclose.qc_cursor =
1241 NETBSD32PTR64(args32.u.cursorclose.qc_cursor);
1242 break;
1243 case QUOTACTL_CURSORSKIPIDTYPE:
1244 args.u.cursorskipidtype.qc_cursor =
1245 NETBSD32PTR64(args32.u.cursorskipidtype.qc_cursor);
1246 args.u.cursorskipidtype.qc_idtype =
1247 args32.u.cursorskipidtype.qc_idtype;
1248 break;
1249 case QUOTACTL_CURSORGET:
1250 args.u.cursorget.qc_cursor =
1251 NETBSD32PTR64(args32.u.cursorget.qc_cursor);
1252 args.u.cursorget.qc_keys =
1253 NETBSD32PTR64(args32.u.cursorget.qc_keys);
1254 args.u.cursorget.qc_vals =
1255 NETBSD32PTR64(args32.u.cursorget.qc_vals);
1256 args.u.cursorget.qc_maxnum =
1257 args32.u.cursorget.qc_maxnum;
1258 args.u.cursorget.qc_ret =
1259 NETBSD32PTR64(args32.u.cursorget.qc_ret);
1260 break;
1261 case QUOTACTL_CURSORATEND:
1262 args.u.cursoratend.qc_cursor =
1263 NETBSD32PTR64(args32.u.cursoratend.qc_cursor);
1264 args.u.cursoratend.qc_ret =
1265 NETBSD32PTR64(args32.u.cursoratend.qc_ret);
1266 break;
1267 case QUOTACTL_CURSORREWIND:
1268 args.u.cursorrewind.qc_cursor =
1269 NETBSD32PTR64(args32.u.cursorrewind.qc_cursor);
1270 break;
1271 case QUOTACTL_QUOTAON:
1272 args.u.quotaon.qc_idtype = args32.u.quotaon.qc_idtype;
1273 args.u.quotaon.qc_quotafile =
1274 NETBSD32PTR64(args32.u.quotaon.qc_quotafile);
1275 break;
1276 case QUOTACTL_QUOTAOFF:
1277 args.u.quotaoff.qc_idtype = args32.u.quotaoff.qc_idtype;
1278 break;
1279 default:
1280 return EINVAL;
1281 }
1282
1283 return do_sys_quotactl(SCARG_P32(uap, path), &args);
1284 }
1285
1286 int
1287 netbsd32___getfh30(struct lwp *l, const struct netbsd32___getfh30_args *uap, register_t *retval)
1288 {
1289 /* {
1290 syscallarg(const netbsd32_charp) fname;
1291 syscallarg(netbsd32_fhandlep_t) fhp;
1292 syscallarg(netbsd32_size_tp) fh_size;
1293 } */
1294 struct vnode *vp;
1295 fhandle_t *fh;
1296 int error;
1297 struct pathbuf *pb;
1298 struct nameidata nd;
1299 netbsd32_size_t usz32, sz32;
1300 size_t sz;
1301
1302 /*
1303 * Must be super user
1304 */
1305 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE,
1306 0, NULL, NULL, NULL);
1307 if (error)
1308 return (error);
1309
1310 error = pathbuf_copyin(SCARG_P32(uap, fname), &pb);
1311 if (error) {
1312 return error;
1313 }
1314
1315 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
1316 error = namei(&nd);
1317 if (error) {
1318 pathbuf_destroy(pb);
1319 return error;
1320 }
1321 vp = nd.ni_vp;
1322 pathbuf_destroy(pb);
1323
1324 error = vfs_composefh_alloc(vp, &fh);
1325 vput(vp);
1326 if (error != 0) {
1327 return error;
1328 }
1329 error = copyin(SCARG_P32(uap, fh_size), &usz32, sizeof(usz32));
1330 if (error != 0) {
1331 goto out;
1332 }
1333 sz = FHANDLE_SIZE(fh);
1334 sz32 = sz;
1335
1336 error = copyout(&sz32, SCARG_P32(uap, fh_size), sizeof(sz32));
1337 if (error != 0) {
1338 goto out;
1339 }
1340 if (usz32 >= sz32) {
1341 error = copyout(fh, SCARG_P32(uap, fhp), sz);
1342 } else {
1343 error = E2BIG;
1344 }
1345 out:
1346 vfs_composefh_free(fh);
1347 return (error);
1348 }
1349
1350 int
1351 netbsd32_pread(struct lwp *l, const struct netbsd32_pread_args *uap, register_t *retval)
1352 {
1353 /* {
1354 syscallarg(int) fd;
1355 syscallarg(netbsd32_voidp) buf;
1356 syscallarg(netbsd32_size_t) nbyte;
1357 syscallarg(int) PAD;
1358 syscallarg(netbsd32_off_t) offset;
1359 } */
1360 struct sys_pread_args ua;
1361
1362 NETBSD32TO64_UAP(fd);
1363 NETBSD32TOP_UAP(buf, void);
1364 NETBSD32TOX_UAP(nbyte, size_t);
1365 NETBSD32TO64_UAP(PAD);
1366 NETBSD32TO64_UAP(offset);
1367 return sys_pread(l, &ua, retval);
1368 }
1369
1370 int
1371 netbsd32_pwrite(struct lwp *l, const struct netbsd32_pwrite_args *uap, register_t *retval)
1372 {
1373 /* {
1374 syscallarg(int) fd;
1375 syscallarg(const netbsd32_voidp) buf;
1376 syscallarg(netbsd32_size_t) nbyte;
1377 syscallarg(int) PAD;
1378 syscallarg(netbsd32_off_t) offset;
1379 } */
1380 struct sys_pwrite_args ua;
1381
1382 NETBSD32TO64_UAP(fd);
1383 NETBSD32TOP_UAP(buf, void);
1384 NETBSD32TOX_UAP(nbyte, size_t);
1385 NETBSD32TO64_UAP(PAD);
1386 NETBSD32TO64_UAP(offset);
1387 return sys_pwrite(l, &ua, retval);
1388 }
1389
1390 int
1391 netbsd32_setgid(struct lwp *l, const struct netbsd32_setgid_args *uap, register_t *retval)
1392 {
1393 /* {
1394 syscallarg(gid_t) gid;
1395 } */
1396 struct sys_setgid_args ua;
1397
1398 NETBSD32TO64_UAP(gid);
1399 return (sys_setgid(l, &ua, retval));
1400 }
1401
1402 int
1403 netbsd32_setegid(struct lwp *l, const struct netbsd32_setegid_args *uap, register_t *retval)
1404 {
1405 /* {
1406 syscallarg(gid_t) egid;
1407 } */
1408 struct sys_setegid_args ua;
1409
1410 NETBSD32TO64_UAP(egid);
1411 return (sys_setegid(l, &ua, retval));
1412 }
1413
1414 int
1415 netbsd32_seteuid(struct lwp *l, const struct netbsd32_seteuid_args *uap, register_t *retval)
1416 {
1417 /* {
1418 syscallarg(gid_t) euid;
1419 } */
1420 struct sys_seteuid_args ua;
1421
1422 NETBSD32TO64_UAP(euid);
1423 return (sys_seteuid(l, &ua, retval));
1424 }
1425
1426 int
1427 netbsd32_pathconf(struct lwp *l, const struct netbsd32_pathconf_args *uap, register_t *retval)
1428 {
1429 /* {
1430 syscallarg(netbsd32_charp) path;
1431 syscallarg(int) name;
1432 } */
1433 struct sys_pathconf_args ua;
1434
1435 NETBSD32TOP_UAP(path, const char);
1436 NETBSD32TO64_UAP(name);
1437 return sys_pathconf(l, &ua, retval);
1438 }
1439
1440 int
1441 netbsd32_fpathconf(struct lwp *l, const struct netbsd32_fpathconf_args *uap, register_t *retval)
1442 {
1443 /* {
1444 syscallarg(int) fd;
1445 syscallarg(int) name;
1446 } */
1447 struct sys_fpathconf_args ua;
1448
1449 NETBSD32TO64_UAP(fd);
1450 NETBSD32TO64_UAP(name);
1451 return sys_fpathconf(l, &ua, retval);
1452 }
1453
1454 static void
1455 fixlimit(int which, struct rlimit *alim)
1456 {
1457 switch (which) {
1458 case RLIMIT_DATA:
1459 if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
1460 alim->rlim_cur = MAXDSIZ32;
1461 if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
1462 alim->rlim_max = MAXDSIZ32;
1463 return;
1464 case RLIMIT_STACK:
1465 if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
1466 alim->rlim_cur = MAXSSIZ32;
1467 if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
1468 alim->rlim_max = MAXSSIZ32;
1469 return;
1470 default:
1471 return;
1472 }
1473 }
1474
1475 int
1476 netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
1477 register_t *retval)
1478 {
1479 /* {
1480 syscallarg(int) which;
1481 syscallarg(netbsd32_rlimitp_t) rlp;
1482 } */
1483 int which = SCARG(uap, which);
1484 struct rlimit alim;
1485
1486 if ((u_int)which >= RLIM_NLIMITS)
1487 return EINVAL;
1488
1489 alim = l->l_proc->p_rlimit[which];
1490
1491 fixlimit(which, &alim);
1492
1493 return copyout(&alim, SCARG_P32(uap, rlp), sizeof(alim));
1494 }
1495
1496 int
1497 netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
1498 register_t *retval)
1499 {
1500 /* {
1501 syscallarg(int) which;
1502 syscallarg(const netbsd32_rlimitp_t) rlp;
1503 } */
1504 int which = SCARG(uap, which);
1505 struct rlimit alim;
1506 int error;
1507
1508 if ((u_int)which >= RLIM_NLIMITS)
1509 return EINVAL;
1510
1511 error = copyin(SCARG_P32(uap, rlp), &alim, sizeof(struct rlimit));
1512 if (error)
1513 return (error);
1514
1515 fixlimit(which, &alim);
1516
1517 return dosetrlimit(l, l->l_proc, which, &alim);
1518 }
1519
1520 int
1521 netbsd32_mmap(struct lwp *l, const struct netbsd32_mmap_args *uap, register_t *retval)
1522 {
1523 /* {
1524 syscallarg(netbsd32_voidp) addr;
1525 syscallarg(netbsd32_size_t) len;
1526 syscallarg(int) prot;
1527 syscallarg(int) flags;
1528 syscallarg(int) fd;
1529 syscallarg(netbsd32_long) PAD;
1530 syscallarg(netbsd32_off_t) pos;
1531 } */
1532 struct sys_mmap_args ua;
1533 int error;
1534
1535 NETBSD32TOP_UAP(addr, void);
1536 NETBSD32TOX_UAP(len, size_t);
1537 NETBSD32TO64_UAP(prot);
1538 NETBSD32TO64_UAP(flags);
1539 #ifdef __x86_64__
1540 /*
1541 * Ancient kernel on x86 did not obey PROT_EXEC on i386 at least
1542 * and ld.so did not turn it on!
1543 */
1544 if (SCARG(&ua, flags) & MAP_COPY)
1545 SCARG(&ua, prot) |= PROT_EXEC;
1546 #endif
1547 NETBSD32TO64_UAP(fd);
1548 NETBSD32TOX_UAP(PAD, long);
1549 NETBSD32TOX_UAP(pos, off_t);
1550 #ifdef DEBUG_MMAP
1551 printf("mmap(addr=0x%lx, len=0x%lx, prot=0x%lx, flags=0x%lx, "
1552 "fd=%ld, pos=0x%lx);\n",
1553 (long)SCARG(&ua, addr), (long)SCARG(&ua, len),
1554 (long)SCARG(&ua, prot), (long)SCARG(&ua, flags),
1555 (long)SCARG(&ua, fd), (long)SCARG(&ua, pos));
1556 #endif
1557 error = sys_mmap(l, &ua, retval);
1558 if ((u_long)*retval > (u_long)UINT_MAX) {
1559 printf("netbsd32_mmap: retval out of range: 0x%lx\n",
1560 (u_long)*retval);
1561 /* Should try to recover and return an error here. */
1562 }
1563 return (error);
1564 }
1565
1566 int
1567 netbsd32_mremap(struct lwp *l, const struct netbsd32_mremap_args *uap, register_t *retval)
1568 {
1569 /* {
1570 syscallarg(void *) old_address;
1571 syscallarg(size_t) old_size;
1572 syscallarg(void *) new_address;
1573 syscallarg(size_t) new_size;
1574 syscallarg(int) flags;
1575 } */
1576 struct sys_mremap_args ua;
1577
1578 NETBSD32TOP_UAP(old_address, void);
1579 NETBSD32TOX_UAP(old_size, size_t);
1580 NETBSD32TOP_UAP(new_address, void);
1581 NETBSD32TOX_UAP(new_size, size_t);
1582 NETBSD32TO64_UAP(flags);
1583
1584 return sys_mremap(l, &ua, retval);
1585 }
1586
1587 int
1588 netbsd32_lseek(struct lwp *l, const struct netbsd32_lseek_args *uap, register_t *retval)
1589 {
1590 /* {
1591 syscallarg(int) fd;
1592 syscallarg(int) PAD;
1593 syscallarg(netbsd32_off_t) offset;
1594 syscallarg(int) whence;
1595 } */
1596 struct sys_lseek_args ua;
1597 union {
1598 register_t retval64[2];
1599 register32_t retval32[4];
1600 } newpos;
1601 int rv;
1602
1603 NETBSD32TO64_UAP(fd);
1604 NETBSD32TO64_UAP(PAD);
1605 NETBSD32TO64_UAP(offset);
1606 NETBSD32TO64_UAP(whence);
1607 rv = sys_lseek(l, &ua, newpos.retval64);
1608
1609 /*
1610 * We have to split the 64 bit value into 2 halves which will
1611 * end up in separate 32 bit registers.
1612 * This should DTRT on big and little-endian systems provided that
1613 * gcc's 'strict aliasing' tests don't decide that the retval32[]
1614 * entries can't have been assigned to, so need not be read!
1615 */
1616 retval[0] = newpos.retval32[0];
1617 retval[1] = newpos.retval32[1];
1618
1619 return rv;
1620 }
1621
1622 int
1623 netbsd32_truncate(struct lwp *l, const struct netbsd32_truncate_args *uap, register_t *retval)
1624 {
1625 /* {
1626 syscallarg(const netbsd32_charp) path;
1627 syscallarg(int) PAD;
1628 syscallarg(netbsd32_off_t) length;
1629 } */
1630 struct sys_truncate_args ua;
1631
1632 NETBSD32TOP_UAP(path, const char);
1633 NETBSD32TO64_UAP(PAD);
1634 NETBSD32TO64_UAP(length);
1635 return (sys_truncate(l, &ua, retval));
1636 }
1637
1638 int
1639 netbsd32_ftruncate(struct lwp *l, const struct netbsd32_ftruncate_args *uap, register_t *retval)
1640 {
1641 /* {
1642 syscallarg(int) fd;
1643 syscallarg(int) PAD;
1644 syscallarg(netbsd32_off_t) length;
1645 } */
1646 struct sys_ftruncate_args ua;
1647
1648 NETBSD32TO64_UAP(fd);
1649 NETBSD32TO64_UAP(PAD);
1650 NETBSD32TO64_UAP(length);
1651 return (sys_ftruncate(l, &ua, retval));
1652 }
1653
1654 int
1655 netbsd32_mlock(struct lwp *l, const struct netbsd32_mlock_args *uap, register_t *retval)
1656 {
1657 /* {
1658 syscallarg(const netbsd32_voidp) addr;
1659 syscallarg(netbsd32_size_t) len;
1660 } */
1661 struct sys_mlock_args ua;
1662
1663 NETBSD32TOP_UAP(addr, const void);
1664 NETBSD32TO64_UAP(len);
1665 return (sys_mlock(l, &ua, retval));
1666 }
1667
1668 int
1669 netbsd32_munlock(struct lwp *l, const struct netbsd32_munlock_args *uap, register_t *retval)
1670 {
1671 /* {
1672 syscallarg(const netbsd32_voidp) addr;
1673 syscallarg(netbsd32_size_t) len;
1674 } */
1675 struct sys_munlock_args ua;
1676
1677 NETBSD32TOP_UAP(addr, const void);
1678 NETBSD32TO64_UAP(len);
1679 return (sys_munlock(l, &ua, retval));
1680 }
1681
1682 int
1683 netbsd32_undelete(struct lwp *l, const struct netbsd32_undelete_args *uap, register_t *retval)
1684 {
1685 /* {
1686 syscallarg(const netbsd32_charp) path;
1687 } */
1688 struct sys_undelete_args ua;
1689
1690 NETBSD32TOP_UAP(path, const char);
1691 return (sys_undelete(l, &ua, retval));
1692 }
1693
1694 int
1695 netbsd32_getpgid(struct lwp *l, const struct netbsd32_getpgid_args *uap, register_t *retval)
1696 {
1697 /* {
1698 syscallarg(pid_t) pid;
1699 } */
1700 struct sys_getpgid_args ua;
1701
1702 NETBSD32TO64_UAP(pid);
1703 return (sys_getpgid(l, &ua, retval));
1704 }
1705
1706 int
1707 netbsd32_reboot(struct lwp *l, const struct netbsd32_reboot_args *uap, register_t *retval)
1708 {
1709 /* {
1710 syscallarg(int) opt;
1711 syscallarg(netbsd32_charp) bootstr;
1712 } */
1713 struct sys_reboot_args ua;
1714
1715 NETBSD32TO64_UAP(opt);
1716 NETBSD32TOP_UAP(bootstr, char);
1717 return (sys_reboot(l, &ua, retval));
1718 }
1719
1720 #include <sys/poll.h>
1721 int
1722 netbsd32_poll(struct lwp *l, const struct netbsd32_poll_args *uap, register_t *retval)
1723 {
1724 /* {
1725 syscallarg(netbsd32_pollfdp_t) fds;
1726 syscallarg(u_int) nfds;
1727 syscallarg(int) timeout;
1728 } */
1729 struct sys_poll_args ua;
1730
1731 NETBSD32TOP_UAP(fds, struct pollfd);
1732 NETBSD32TO64_UAP(nfds);
1733 NETBSD32TO64_UAP(timeout);
1734
1735 return (sys_poll(l, &ua, retval));
1736 }
1737
1738 int
1739 netbsd32_fdatasync(struct lwp *l, const struct netbsd32_fdatasync_args *uap, register_t *retval)
1740 {
1741 /* {
1742 syscallarg(int) fd;
1743 } */
1744 struct sys_fdatasync_args ua;
1745
1746 NETBSD32TO64_UAP(fd);
1747 return (sys_fdatasync(l, &ua, retval));
1748 }
1749
1750 int
1751 netbsd32___posix_rename(struct lwp *l, const struct netbsd32___posix_rename_args *uap, register_t *retval)
1752 {
1753 /* {
1754 syscallarg(const netbsd32_charp) from;
1755 syscallarg(const netbsd32_charp) to;
1756 } */
1757 struct sys___posix_rename_args ua;
1758
1759 NETBSD32TOP_UAP(from, const char);
1760 NETBSD32TOP_UAP(to, const char);
1761 return (sys___posix_rename(l, &ua, retval));
1762 }
1763
1764 static int
1765 netbsd32_swapctl_stats(struct lwp *l, struct sys_swapctl_args *uap, register_t *retval)
1766 {
1767 struct swapent *ksep;
1768 struct netbsd32_swapent *usep32;
1769 struct netbsd32_swapent se32;
1770 int count = SCARG(uap, misc);
1771 int i, error = 0;
1772 size_t ksep_len;
1773
1774 if (count < 0)
1775 return EINVAL;
1776
1777 swapsys_lock(RW_WRITER);
1778
1779 if ((size_t)count > (size_t)uvmexp.nswapdev)
1780 count = uvmexp.nswapdev;
1781 if (count == 0) {
1782 /* No swap device */
1783 swapsys_unlock();
1784 return 0;
1785 }
1786
1787 ksep_len = sizeof(*ksep) * count;
1788 ksep = kmem_alloc(ksep_len, KM_SLEEP);
1789 usep32 = (struct netbsd32_swapent *)SCARG(uap, arg);
1790
1791 uvm_swap_stats(SWAP_STATS, ksep, count, retval);
1792 count = *retval;
1793
1794 swapsys_unlock();
1795
1796 for (i = 0; i < count; i++) {
1797 se32.se_dev = ksep[i].se_dev;
1798 se32.se_flags = ksep[i].se_flags;
1799 se32.se_nblks = ksep[i].se_nblks;
1800 se32.se_inuse = ksep[i].se_inuse;
1801 se32.se_priority = ksep[i].se_priority;
1802 memcpy(se32.se_path, ksep[i].se_path,
1803 sizeof(se32.se_path));
1804
1805 error = copyout(&se32, usep32 + i, sizeof(se32));
1806 if (error)
1807 break;
1808 }
1809
1810 kmem_free(ksep, ksep_len);
1811
1812 return error;
1813 }
1814
1815 int
1816 netbsd32_swapctl(struct lwp *l, const struct netbsd32_swapctl_args *uap, register_t *retval)
1817 {
1818 /* {
1819 syscallarg(int) cmd;
1820 syscallarg(const netbsd32_voidp) arg;
1821 syscallarg(int) misc;
1822 } */
1823 struct sys_swapctl_args ua;
1824
1825 NETBSD32TO64_UAP(cmd);
1826 NETBSD32TOP_UAP(arg, void);
1827 NETBSD32TO64_UAP(misc);
1828
1829 /* SWAP_STATS50 and SWAP_STATS13 structures need no translation */
1830 if (SCARG(&ua, cmd) == SWAP_STATS)
1831 return netbsd32_swapctl_stats(l, &ua, retval);
1832
1833 return (sys_swapctl(l, &ua, retval));
1834 }
1835
1836 int
1837 netbsd32_minherit(struct lwp *l, const struct netbsd32_minherit_args *uap, register_t *retval)
1838 {
1839 /* {
1840 syscallarg(netbsd32_voidp) addr;
1841 syscallarg(netbsd32_size_t) len;
1842 syscallarg(int) inherit;
1843 } */
1844 struct sys_minherit_args ua;
1845
1846 NETBSD32TOP_UAP(addr, void);
1847 NETBSD32TOX_UAP(len, size_t);
1848 NETBSD32TO64_UAP(inherit);
1849 return (sys_minherit(l, &ua, retval));
1850 }
1851
1852 int
1853 netbsd32_lchmod(struct lwp *l, const struct netbsd32_lchmod_args *uap, register_t *retval)
1854 {
1855 /* {
1856 syscallarg(const netbsd32_charp) path;
1857 syscallarg(mode_t) mode;
1858 } */
1859 struct sys_lchmod_args ua;
1860
1861 NETBSD32TOP_UAP(path, const char);
1862 NETBSD32TO64_UAP(mode);
1863 return (sys_lchmod(l, &ua, retval));
1864 }
1865
1866 int
1867 netbsd32_lchown(struct lwp *l, const struct netbsd32_lchown_args *uap, register_t *retval)
1868 {
1869 /* {
1870 syscallarg(const netbsd32_charp) path;
1871 syscallarg(uid_t) uid;
1872 syscallarg(gid_t) gid;
1873 } */
1874 struct sys_lchown_args ua;
1875
1876 NETBSD32TOP_UAP(path, const char);
1877 NETBSD32TO64_UAP(uid);
1878 NETBSD32TO64_UAP(gid);
1879 return (sys_lchown(l, &ua, retval));
1880 }
1881
1882 int
1883 netbsd32___msync13(struct lwp *l, const struct netbsd32___msync13_args *uap, register_t *retval)
1884 {
1885 /* {
1886 syscallarg(netbsd32_voidp) addr;
1887 syscallarg(netbsd32_size_t) len;
1888 syscallarg(int) flags;
1889 } */
1890 struct sys___msync13_args ua;
1891
1892 NETBSD32TOP_UAP(addr, void);
1893 NETBSD32TOX_UAP(len, size_t);
1894 NETBSD32TO64_UAP(flags);
1895 return (sys___msync13(l, &ua, retval));
1896 }
1897
1898 int
1899 netbsd32___posix_chown(struct lwp *l, const struct netbsd32___posix_chown_args *uap, register_t *retval)
1900 {
1901 /* {
1902 syscallarg(const netbsd32_charp) path;
1903 syscallarg(uid_t) uid;
1904 syscallarg(gid_t) gid;
1905 } */
1906 struct sys___posix_chown_args ua;
1907
1908 NETBSD32TOP_UAP(path, const char);
1909 NETBSD32TO64_UAP(uid);
1910 NETBSD32TO64_UAP(gid);
1911 return (sys___posix_chown(l, &ua, retval));
1912 }
1913
1914 int
1915 netbsd32___posix_fchown(struct lwp *l, const struct netbsd32___posix_fchown_args *uap, register_t *retval)
1916 {
1917 /* {
1918 syscallarg(int) fd;
1919 syscallarg(uid_t) uid;
1920 syscallarg(gid_t) gid;
1921 } */
1922 struct sys___posix_fchown_args ua;
1923
1924 NETBSD32TO64_UAP(fd);
1925 NETBSD32TO64_UAP(uid);
1926 NETBSD32TO64_UAP(gid);
1927 return (sys___posix_fchown(l, &ua, retval));
1928 }
1929
1930 int
1931 netbsd32___posix_lchown(struct lwp *l, const struct netbsd32___posix_lchown_args *uap, register_t *retval)
1932 {
1933 /* {
1934 syscallarg(const netbsd32_charp) path;
1935 syscallarg(uid_t) uid;
1936 syscallarg(gid_t) gid;
1937 } */
1938 struct sys___posix_lchown_args ua;
1939
1940 NETBSD32TOP_UAP(path, const char);
1941 NETBSD32TO64_UAP(uid);
1942 NETBSD32TO64_UAP(gid);
1943 return (sys___posix_lchown(l, &ua, retval));
1944 }
1945
1946 int
1947 netbsd32_getsid(struct lwp *l, const struct netbsd32_getsid_args *uap, register_t *retval)
1948 {
1949 /* {
1950 syscallarg(pid_t) pid;
1951 } */
1952 struct sys_getsid_args ua;
1953
1954 NETBSD32TO64_UAP(pid);
1955 return (sys_getsid(l, &ua, retval));
1956 }
1957
1958 int
1959 netbsd32_fktrace(struct lwp *l, const struct netbsd32_fktrace_args *uap, register_t *retval)
1960 {
1961 /* {
1962 syscallarg(int) fd;
1963 syscallarg(int) ops;
1964 syscallarg(int) facs;
1965 syscallarg(int) pid;
1966 } */
1967 struct sys_fktrace_args ua;
1968
1969 NETBSD32TOX_UAP(fd, int);
1970 NETBSD32TO64_UAP(ops);
1971 NETBSD32TO64_UAP(facs);
1972 NETBSD32TO64_UAP(pid);
1973 return (sys_fktrace(l, &ua, retval));
1974 }
1975
1976 int
1977 netbsd32___sigpending14(struct lwp *l, const struct netbsd32___sigpending14_args *uap, register_t *retval)
1978 {
1979 /* {
1980 syscallarg(sigset_t *) set;
1981 } */
1982 struct sys___sigpending14_args ua;
1983
1984 NETBSD32TOP_UAP(set, sigset_t);
1985 return (sys___sigpending14(l, &ua, retval));
1986 }
1987
1988 int
1989 netbsd32___sigprocmask14(struct lwp *l, const struct netbsd32___sigprocmask14_args *uap, register_t *retval)
1990 {
1991 /* {
1992 syscallarg(int) how;
1993 syscallarg(const sigset_t *) set;
1994 syscallarg(sigset_t *) oset;
1995 } */
1996 struct sys___sigprocmask14_args ua;
1997
1998 NETBSD32TO64_UAP(how);
1999 NETBSD32TOP_UAP(set, sigset_t);
2000 NETBSD32TOP_UAP(oset, sigset_t);
2001 return (sys___sigprocmask14(l, &ua, retval));
2002 }
2003
2004 int
2005 netbsd32___sigsuspend14(struct lwp *l, const struct netbsd32___sigsuspend14_args *uap, register_t *retval)
2006 {
2007 /* {
2008 syscallarg(const sigset_t *) set;
2009 } */
2010 struct sys___sigsuspend14_args ua;
2011
2012 NETBSD32TOP_UAP(set, sigset_t);
2013 return (sys___sigsuspend14(l, &ua, retval));
2014 }
2015
2016 int
2017 netbsd32_fchroot(struct lwp *l, const struct netbsd32_fchroot_args *uap, register_t *retval)
2018 {
2019 /* {
2020 syscallarg(int) fd;
2021 } */
2022 struct sys_fchroot_args ua;
2023
2024 NETBSD32TO64_UAP(fd);
2025 return (sys_fchroot(l, &ua, retval));
2026 }
2027
2028 /*
2029 * Open a file given a file handle.
2030 *
2031 * Check permissions, allocate an open file structure,
2032 * and call the device open routine if any.
2033 */
2034 int
2035 netbsd32___fhopen40(struct lwp *l, const struct netbsd32___fhopen40_args *uap, register_t *retval)
2036 {
2037 /* {
2038 syscallarg(const netbsd32_pointer_t *) fhp;
2039 syscallarg(netbsd32_size_t) fh_size;
2040 syscallarg(int) flags;
2041 } */
2042 struct sys___fhopen40_args ua;
2043
2044 NETBSD32TOP_UAP(fhp, fhandle_t);
2045 NETBSD32TO64_UAP(fh_size);
2046 NETBSD32TO64_UAP(flags);
2047 return (sys___fhopen40(l, &ua, retval));
2048 }
2049
2050 /* virtual memory syscalls */
2051 int
2052 netbsd32_ovadvise(struct lwp *l, const struct netbsd32_ovadvise_args *uap, register_t *retval)
2053 {
2054 /* {
2055 syscallarg(int) anom;
2056 } */
2057 struct sys_ovadvise_args ua;
2058
2059 NETBSD32TO64_UAP(anom);
2060 return (sys_ovadvise(l, &ua, retval));
2061 }
2062
2063 void
2064 netbsd32_adjust_limits(struct proc *p)
2065 {
2066 static const struct {
2067 int id;
2068 rlim_t lim;
2069 } lm[] = {
2070 { RLIMIT_DATA, MAXDSIZ32 },
2071 { RLIMIT_STACK, MAXSSIZ32 },
2072 };
2073 size_t i;
2074 struct plimit *lim;
2075 struct rlimit *rlim;
2076
2077 /*
2078 * We can only reduce the current limits, we cannot stop external
2079 * processes from changing them (eg via sysctl) later on.
2080 * So there is no point trying to lock out such changes here.
2081 *
2082 * If we assume that rlim_cur/max are accessed using atomic
2083 * operations, we don't need to lock against any other updates
2084 * that might happen if the plimit structure is shared writable
2085 * between multiple processes.
2086 */
2087
2088 /* Scan to determine is any limits are out of range */
2089 lim = p->p_limit;
2090 for (i = 0; ; i++) {
2091 if (i >= __arraycount(lm))
2092 /* All in range */
2093 return;
2094 rlim = lim->pl_rlimit + lm[i].id;
2095 if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
2096 break;
2097 if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
2098 break;
2099 }
2100
2101 lim_privatise(p);
2102
2103 lim = p->p_limit;
2104 for (i = 0; i < __arraycount(lm); i++) {
2105 rlim = lim->pl_rlimit + lm[i].id;
2106 if (LIMITCHECK(rlim->rlim_cur, lm[i].lim))
2107 rlim->rlim_cur = lm[i].lim;
2108 if (LIMITCHECK(rlim->rlim_max, lm[i].lim))
2109 rlim->rlim_max = lm[i].lim;
2110 }
2111 }
2112
2113 int
2114 netbsd32_uuidgen(struct lwp *l, const struct netbsd32_uuidgen_args *uap, register_t *retval)
2115 {
2116 /* {
2117 syscallarg(netbsd32_uuidp_t) store;
2118 syscallarg(int) count;
2119 } */
2120 struct sys_uuidgen_args ua;
2121
2122 NETBSD32TOP_UAP(store, struct uuid);
2123 NETBSD32TO64_UAP(count);
2124 return (sys_uuidgen(l, &ua, retval));
2125 }
2126
2127 int
2128 netbsd32_extattrctl(struct lwp *l, const struct netbsd32_extattrctl_args *uap, register_t *retval)
2129 {
2130 /* {
2131 syscallarg(const netbsd32_charp) path;
2132 syscallarg(int) cmd;
2133 syscallarg(const netbsd32_charp) filename;
2134 syscallarg(int) attrnamespace;
2135 syscallarg(const netbsd32_charp) attrname;
2136 } */
2137 struct sys_extattrctl_args ua;
2138
2139 NETBSD32TOP_UAP(path, const char);
2140 NETBSD32TO64_UAP(cmd);
2141 NETBSD32TOP_UAP(filename, const char);
2142 NETBSD32TO64_UAP(attrnamespace);
2143 NETBSD32TOP_UAP(attrname, const char);
2144 return sys_extattrctl(l, &ua, retval);
2145 }
2146
2147 int
2148 netbsd32_extattr_set_fd(struct lwp *l, const struct netbsd32_extattr_set_fd_args *uap, register_t *retval)
2149 {
2150 /* {
2151 syscallarg(int) fd;
2152 syscallarg(int) attrnamespace;
2153 syscallarg(const netbsd32_charp) attrname;
2154 syscallarg(const netbsd32_voidp) data;
2155 syscallarg(netbsd32_size_t) nbytes;
2156 } */
2157 struct sys_extattr_set_fd_args ua;
2158
2159 NETBSD32TO64_UAP(fd);
2160 NETBSD32TO64_UAP(attrnamespace);
2161 NETBSD32TOP_UAP(attrname, const char);
2162 NETBSD32TOP_UAP(data, const void);
2163 NETBSD32TOX_UAP(nbytes, size_t);
2164 return sys_extattr_set_fd(l, &ua, retval);
2165 }
2166
2167 int
2168 netbsd32_extattr_set_file(struct lwp *l, const struct netbsd32_extattr_set_file_args *uap, register_t *retval)
2169 {
2170 /* {
2171 syscallarg(const netbsd32_charp) path;
2172 syscallarg(int) attrnamespace;
2173 syscallarg(const netbsd32_charp) attrname;
2174 syscallarg(const netbsd32_voidp) data;
2175 syscallarg(netbsd32_size_t) nbytes;
2176 } */
2177 struct sys_extattr_set_file_args ua;
2178
2179 NETBSD32TOP_UAP(path, const char);
2180 NETBSD32TO64_UAP(attrnamespace);
2181 NETBSD32TOP_UAP(attrname, const char);
2182 NETBSD32TOP_UAP(data, const void);
2183 NETBSD32TOX_UAP(nbytes, size_t);
2184 return sys_extattr_set_file(l, &ua, retval);
2185 }
2186
2187 int
2188 netbsd32_extattr_set_link(struct lwp *l, const struct netbsd32_extattr_set_link_args *uap, register_t *retval)
2189 {
2190 /* {
2191 syscallarg(const netbsd32_charp) path;
2192 syscallarg(int) attrnamespace;
2193 syscallarg(const netbsd32_charp) attrname;
2194 syscallarg(const netbsd32_voidp) data;
2195 syscallarg(netbsd32_size_t) nbytes;
2196 } */
2197 struct sys_extattr_set_link_args ua;
2198
2199 NETBSD32TOP_UAP(path, const char);
2200 NETBSD32TO64_UAP(attrnamespace);
2201 NETBSD32TOP_UAP(attrname, const char);
2202 NETBSD32TOP_UAP(data, const void);
2203 NETBSD32TOX_UAP(nbytes, size_t);
2204 return sys_extattr_set_link(l, &ua, retval);
2205 }
2206
2207 int
2208 netbsd32_extattr_get_fd(struct lwp *l, const struct netbsd32_extattr_get_fd_args *uap, register_t *retval)
2209 {
2210 /* {
2211 syscallarg(int) fd;
2212 syscallarg(int) attrnamespace;
2213 syscallarg(const netbsd32_charp) attrname;
2214 syscallarg(netbsd32_voidp) data;
2215 syscallarg(netbsd32_size_t) nbytes;
2216 } */
2217 struct sys_extattr_get_fd_args ua;
2218
2219 NETBSD32TO64_UAP(fd);
2220 NETBSD32TO64_UAP(attrnamespace);
2221 NETBSD32TOP_UAP(attrname, const char);
2222 NETBSD32TOP_UAP(data, void);
2223 NETBSD32TOX_UAP(nbytes, size_t);
2224 return sys_extattr_get_fd(l, &ua, retval);
2225 }
2226
2227 int
2228 netbsd32_extattr_get_file(struct lwp *l, const struct netbsd32_extattr_get_file_args *uap, register_t *retval)
2229 {
2230 /* {
2231 syscallarg(const netbsd32_charp) path;
2232 syscallarg(int) attrnamespace;
2233 syscallarg(const netbsd32_charp) attrname;
2234 syscallarg(netbsd32_voidp) data;
2235 syscallarg(netbsd32_size_t) nbytes;
2236 } */
2237 struct sys_extattr_get_file_args ua;
2238
2239 NETBSD32TOP_UAP(path, const char);
2240 NETBSD32TO64_UAP(attrnamespace);
2241 NETBSD32TOP_UAP(attrname, const char);
2242 NETBSD32TOP_UAP(data, void);
2243 NETBSD32TOX_UAP(nbytes, size_t);
2244 return sys_extattr_get_file(l, &ua, retval);
2245 }
2246
2247 int
2248 netbsd32_extattr_get_link(struct lwp *l, const struct netbsd32_extattr_get_link_args *uap, register_t *retval)
2249 {
2250 /* {
2251 syscallarg(const netbsd32_charp) path;
2252 syscallarg(int) attrnamespace;
2253 syscallarg(const netbsd32_charp) attrname;
2254 syscallarg(netbsd32_voidp) data;
2255 syscallarg(netbsd32_size_t) nbytes;
2256 } */
2257 struct sys_extattr_get_link_args ua;
2258
2259 NETBSD32TOP_UAP(path, const char);
2260 NETBSD32TO64_UAP(attrnamespace);
2261 NETBSD32TOP_UAP(attrname, const char);
2262 NETBSD32TOP_UAP(data, void);
2263 NETBSD32TOX_UAP(nbytes, size_t);
2264 return sys_extattr_get_link(l, &ua, retval);
2265 }
2266
2267 int
2268 netbsd32_extattr_delete_fd(struct lwp *l, const struct netbsd32_extattr_delete_fd_args *uap, register_t *retval)
2269 {
2270 /* {
2271 syscallarg(int) fd;
2272 syscallarg(int) attrnamespace;
2273 syscallarg(const netbsd32_charp) attrname;
2274 } */
2275 struct sys_extattr_delete_fd_args ua;
2276
2277 NETBSD32TO64_UAP(fd);
2278 NETBSD32TO64_UAP(attrnamespace);
2279 NETBSD32TOP_UAP(attrname, const char);
2280 return sys_extattr_delete_fd(l, &ua, retval);
2281 }
2282
2283 int
2284 netbsd32_extattr_delete_file(struct lwp *l, const struct netbsd32_extattr_delete_file_args *uap, register_t *retval)
2285 {
2286 /* {
2287 syscallarg(const netbsd32_charp) path;
2288 syscallarg(int) attrnamespace;
2289 syscallarg(const netbsd32_charp) attrname;
2290 } */
2291 struct sys_extattr_delete_file_args ua;
2292
2293 NETBSD32TOP_UAP(path, const char);
2294 NETBSD32TO64_UAP(attrnamespace);
2295 NETBSD32TOP_UAP(attrname, const char);
2296 return sys_extattr_delete_file(l, &ua, retval);
2297 }
2298
2299 int
2300 netbsd32_extattr_delete_link(struct lwp *l, const struct netbsd32_extattr_delete_link_args *uap, register_t *retval)
2301 {
2302 /* {
2303 syscallarg(const netbsd32_charp) path;
2304 syscallarg(int) attrnamespace;
2305 syscallarg(const netbsd32_charp) attrname;
2306 } */
2307 struct sys_extattr_delete_link_args ua;
2308
2309 NETBSD32TOP_UAP(path, const char);
2310 NETBSD32TO64_UAP(attrnamespace);
2311 NETBSD32TOP_UAP(attrname, const char);
2312 return sys_extattr_delete_link(l, &ua, retval);
2313 }
2314
2315 int
2316 netbsd32_extattr_list_fd(struct lwp *l, const struct netbsd32_extattr_list_fd_args *uap, register_t *retval)
2317 {
2318 /* {
2319 syscallarg(int) fd;
2320 syscallarg(int) attrnamespace;
2321 syscallarg(netbsd32_voidp) data;
2322 syscallarg(netbsd32_size_t) nbytes;
2323 } */
2324 struct sys_extattr_list_fd_args ua;
2325
2326 NETBSD32TO64_UAP(fd);
2327 NETBSD32TO64_UAP(attrnamespace);
2328 NETBSD32TOP_UAP(data, void);
2329 NETBSD32TOX_UAP(nbytes, size_t);
2330 return sys_extattr_list_fd(l, &ua, retval);
2331 }
2332
2333 int
2334 netbsd32_extattr_list_file(struct lwp *l, const struct netbsd32_extattr_list_file_args *uap, register_t *retval)
2335 {
2336 /* {
2337 syscallarg(const netbsd32_charp) path;
2338 syscallarg(int) attrnamespace;
2339 syscallarg(netbsd32_voidp) data;
2340 syscallarg(netbsd32_size_t) nbytes;
2341 } */
2342 struct sys_extattr_list_file_args ua;
2343
2344 NETBSD32TOP_UAP(path, const char);
2345 NETBSD32TO64_UAP(attrnamespace);
2346 NETBSD32TOP_UAP(data, void);
2347 NETBSD32TOX_UAP(nbytes, size_t);
2348 return sys_extattr_list_file(l, &ua, retval);
2349 }
2350
2351 int
2352 netbsd32_extattr_list_link(struct lwp *l, const struct netbsd32_extattr_list_link_args *uap, register_t *retval)
2353 {
2354 /* {
2355 syscallarg(const netbsd32_charp) path;
2356 syscallarg(int) attrnamespace;
2357 syscallarg(netbsd32_voidp) data;
2358 syscallarg(netbsd32_size_t) nbytes;
2359 } */
2360 struct sys_extattr_list_link_args ua;
2361
2362 NETBSD32TOP_UAP(path, const char);
2363 NETBSD32TO64_UAP(attrnamespace);
2364 NETBSD32TOP_UAP(data, void);
2365 NETBSD32TOX_UAP(nbytes, size_t);
2366 return sys_extattr_list_link(l, &ua, retval);
2367 }
2368
2369 int
2370 netbsd32_mlockall(struct lwp *l, const struct netbsd32_mlockall_args *uap, register_t *retval)
2371 {
2372 /* {
2373 syscallarg(int) flags;
2374 } */
2375 struct sys_mlockall_args ua;
2376
2377 NETBSD32TO64_UAP(flags);
2378 return (sys_mlockall(l, &ua, retval));
2379 }
2380
2381 int
2382 netbsd32___clone(struct lwp *l, const struct netbsd32___clone_args *uap, register_t *retval)
2383 {
2384 /* {
2385 syscallarg(int) flags;
2386 syscallarg(netbsd32_voidp) stack;
2387 } */
2388 struct sys___clone_args ua;
2389
2390 NETBSD32TO64_UAP(flags);
2391 NETBSD32TOP_UAP(stack, void);
2392 return sys___clone(l, &ua, retval);
2393 }
2394
2395 int
2396 netbsd32_fsync_range(struct lwp *l, const struct netbsd32_fsync_range_args *uap, register_t *retval)
2397 {
2398 /* {
2399 syscallarg(int) fd;
2400 syscallarg(int) flags;
2401 syscallarg(off_t) start;
2402 syscallarg(off_t) length;
2403 } */
2404 struct sys_fsync_range_args ua;
2405
2406 NETBSD32TO64_UAP(fd);
2407 NETBSD32TO64_UAP(flags);
2408 NETBSD32TO64_UAP(start);
2409 NETBSD32TO64_UAP(length);
2410 return (sys_fsync_range(l, &ua, retval));
2411 }
2412
2413 int
2414 netbsd32_rasctl(struct lwp *l, const struct netbsd32_rasctl_args *uap, register_t *retval)
2415 {
2416 /* {
2417 syscallarg(netbsd32_voidp) addr;
2418 syscallarg(netbsd32_size_t) len;
2419 syscallarg(int) op;
2420 } */
2421 struct sys_rasctl_args ua;
2422
2423 NETBSD32TOP_UAP(addr, void *);
2424 NETBSD32TOX_UAP(len, size_t);
2425 NETBSD32TO64_UAP(op);
2426 return sys_rasctl(l, &ua, retval);
2427 }
2428
2429 int
2430 netbsd32_setxattr(struct lwp *l, const struct netbsd32_setxattr_args *uap, register_t *retval)
2431 {
2432 /* {
2433 syscallarg(const netbsd32_charp) path;
2434 syscallarg(const netbsd32_charp) name;
2435 syscallarg(netbsd32_voidp) value;
2436 syscallarg(netbsd32_size_t) size;
2437 syscallarg(int) flags;
2438 } */
2439 struct sys_setxattr_args ua;
2440 NETBSD32TOP_UAP(path, const char);
2441 NETBSD32TOP_UAP(name, const char);
2442 NETBSD32TOP_UAP(value, void);
2443 NETBSD32TOX_UAP(size, size_t);
2444 NETBSD32TO64_UAP(flags);
2445 return sys_setxattr(l, &ua, retval);
2446 }
2447
2448 int
2449 netbsd32_lsetxattr(struct lwp *l, const struct netbsd32_lsetxattr_args *uap, register_t *retval)
2450 {
2451 /* {
2452 syscallarg(const netbsd32_charp) path;
2453 syscallarg(const netbsd32_charp) name;
2454 syscallarg(netbsd32_voidp) value;
2455 syscallarg(netbsd32_size_t) size;
2456 syscallarg(int) flags;
2457 } */
2458 struct sys_lsetxattr_args ua;
2459 NETBSD32TOP_UAP(path, const char);
2460 NETBSD32TOP_UAP(name, const char);
2461 NETBSD32TOP_UAP(value, void);
2462 NETBSD32TOX_UAP(size, size_t);
2463 NETBSD32TO64_UAP(flags);
2464 return sys_lsetxattr(l, &ua, retval);
2465 }
2466
2467 int
2468 netbsd32_fsetxattr(struct lwp *l, const struct netbsd32_fsetxattr_args *uap, register_t *retval)
2469 {
2470 /* {
2471 syscallarg(int) fd;
2472 syscallarg(const netbsd32_charp) name;
2473 syscallarg(netbsd32_voidp) value;
2474 syscallarg(netbsd32_size_t) size;
2475 syscallarg(int) flags;
2476 } */
2477 struct sys_fsetxattr_args ua;
2478 NETBSD32TO64_UAP(fd);
2479 NETBSD32TOP_UAP(name, const char);
2480 NETBSD32TOP_UAP(value, void);
2481 NETBSD32TOX_UAP(size, size_t);
2482 NETBSD32TO64_UAP(flags);
2483 return sys_fsetxattr(l, &ua, retval);
2484 }
2485
2486 int
2487 netbsd32_getxattr(struct lwp *l, const struct netbsd32_getxattr_args *uap, register_t *retval)
2488 {
2489 /* {
2490 syscallarg(const netbsd32_charp) path;
2491 syscallarg(const netbsd32_charp) name;
2492 syscallarg(netbsd32_voidp) value;
2493 syscallarg(netbsd32_size_t) size;
2494 } */
2495 struct sys_getxattr_args ua;
2496 NETBSD32TOP_UAP(path, const char);
2497 NETBSD32TOP_UAP(name, const char);
2498 NETBSD32TOP_UAP(value, void);
2499 NETBSD32TOX_UAP(size, size_t);
2500 return sys_getxattr(l, &ua, retval);
2501 }
2502
2503 int
2504 netbsd32_lgetxattr(struct lwp *l, const struct netbsd32_lgetxattr_args *uap, register_t *retval)
2505 {
2506 /* {
2507 syscallarg(const netbsd32_charp) path;
2508 syscallarg(const netbsd32_charp) name;
2509 syscallarg(netbsd32_voidp) value;
2510 syscallarg(netbsd32_size_t) size;
2511 } */
2512 struct sys_lgetxattr_args ua;
2513 NETBSD32TOP_UAP(path, const char);
2514 NETBSD32TOP_UAP(name, const char);
2515 NETBSD32TOP_UAP(value, void);
2516 NETBSD32TOX_UAP(size, size_t);
2517 return sys_lgetxattr(l, &ua, retval);
2518 }
2519
2520 int
2521 netbsd32_fgetxattr(struct lwp *l, const struct netbsd32_fgetxattr_args *uap, register_t *retval)
2522 {
2523 /* {
2524 syscallarg(int) fd;
2525 syscallarg(const netbsd32_charp) name;
2526 syscallarg(netbsd32_voidp) value;
2527 syscallarg(netbsd32_size_t) size;
2528 } */
2529 struct sys_fgetxattr_args ua;
2530 NETBSD32TO64_UAP(fd);
2531 NETBSD32TOP_UAP(name, const char);
2532 NETBSD32TOP_UAP(value, void);
2533 NETBSD32TOX_UAP(size, size_t);
2534 return sys_fgetxattr(l, &ua, retval);
2535 }
2536
2537 int
2538 netbsd32_listxattr(struct lwp *l, const struct netbsd32_listxattr_args *uap, register_t *retval)
2539 {
2540 /* {
2541 syscallarg(const netbsd32_charp) path;
2542 syscallarg(netbsd32_charp) list;
2543 syscallarg(netbsd32_size_t) size;
2544 } */
2545 struct sys_listxattr_args ua;
2546 NETBSD32TOP_UAP(path, const char);
2547 NETBSD32TOP_UAP(list, char);
2548 NETBSD32TOX_UAP(size, size_t);
2549 return sys_listxattr(l, &ua, retval);
2550 }
2551
2552 int
2553 netbsd32_llistxattr(struct lwp *l, const struct netbsd32_llistxattr_args *uap, register_t *retval)
2554 {
2555 /* {
2556 syscallarg(const netbsd32_charp) path;
2557 syscallarg(netbsd32_charp) list;
2558 syscallarg(netbsd32_size_t) size;
2559 } */
2560 struct sys_llistxattr_args ua;
2561 NETBSD32TOP_UAP(path, const char);
2562 NETBSD32TOP_UAP(list, char);
2563 NETBSD32TOX_UAP(size, size_t);
2564 return sys_llistxattr(l, &ua, retval);
2565 }
2566
2567 int
2568 netbsd32_flistxattr(struct lwp *l, const struct netbsd32_flistxattr_args *uap, register_t *retval)
2569 {
2570 /* {
2571 syscallarg(int) fd;
2572 syscallarg(netbsd32_charp) list;
2573 syscallarg(netbsd32_size_t) size;
2574 } */
2575 struct sys_flistxattr_args ua;
2576 NETBSD32TO64_UAP(fd);
2577 NETBSD32TOP_UAP(list, char);
2578 NETBSD32TOX_UAP(size, size_t);
2579 return sys_flistxattr(l, &ua, retval);
2580 }
2581
2582 int
2583 netbsd32_removexattr(struct lwp *l, const struct netbsd32_removexattr_args *uap, register_t *retval)
2584 {
2585 /* {
2586 syscallarg(const netbsd32_charp) path;
2587 syscallarg(const netbsd32_charp) name;
2588 } */
2589 struct sys_removexattr_args ua;
2590 NETBSD32TOP_UAP(path, const char);
2591 NETBSD32TOP_UAP(name, const char);
2592 return sys_removexattr(l, &ua, retval);
2593 }
2594
2595 int
2596 netbsd32_lremovexattr(struct lwp *l, const struct netbsd32_lremovexattr_args *uap, register_t *retval)
2597 {
2598 /* {
2599 syscallarg(const netbsd32_charp) path;
2600 syscallarg(const netbsd32_charp) name;
2601 } */
2602 struct sys_lremovexattr_args ua;
2603 NETBSD32TOP_UAP(path, const char);
2604 NETBSD32TOP_UAP(name, const char);
2605 return sys_lremovexattr(l, &ua, retval);
2606 }
2607
2608 int
2609 netbsd32_fremovexattr(struct lwp *l, const struct netbsd32_fremovexattr_args *uap, register_t *retval)
2610 {
2611 /* {
2612 syscallarg(int) fd;
2613 syscallarg(const netbsd32_charp) name;
2614 } */
2615 struct sys_fremovexattr_args ua;
2616 NETBSD32TO64_UAP(fd);
2617 NETBSD32TOP_UAP(name, const char);
2618 return sys_fremovexattr(l, &ua, retval);
2619 }
2620
2621 int
2622 netbsd32___posix_fadvise50(struct lwp *l,
2623 const struct netbsd32___posix_fadvise50_args *uap, register_t *retval)
2624 {
2625 /* {
2626 syscallarg(int) fd;
2627 syscallarg(int) PAD;
2628 syscallarg(netbsd32_off_t) offset;
2629 syscallarg(netbsd32_off_t) len;
2630 syscallarg(int) advice;
2631 } */
2632
2633 *retval = do_posix_fadvise(SCARG(uap, fd), SCARG(uap, offset),
2634 SCARG(uap, len), SCARG(uap, advice));
2635
2636 return 0;
2637 }
2638
2639 int
2640 netbsd32__sched_setparam(struct lwp *l,
2641 const struct netbsd32__sched_setparam_args *uap,
2642 register_t *retval)
2643 {
2644 /* {
2645 syscallarg(pid_t) pid;
2646 syscallarg(lwpid_t) lid;
2647 syscallarg(int) policy;
2648 syscallarg(const netbsd32_sched_paramp_t) params;
2649 } */
2650 struct sys__sched_setparam_args ua;
2651
2652 NETBSD32TO64_UAP(pid);
2653 NETBSD32TO64_UAP(lid);
2654 NETBSD32TO64_UAP(policy);
2655 NETBSD32TOP_UAP(params, const struct sched_param *);
2656 return sys__sched_setparam(l, &ua, retval);
2657 }
2658
2659 int
2660 netbsd32__sched_getparam(struct lwp *l,
2661 const struct netbsd32__sched_getparam_args *uap,
2662 register_t *retval)
2663 {
2664 /* {
2665 syscallarg(pid_t) pid;
2666 syscallarg(lwpid_t) lid;
2667 syscallarg(netbsd32_intp) policy;
2668 syscallarg(netbsd32_sched_paramp_t) params;
2669 } */
2670 struct sys__sched_getparam_args ua;
2671
2672 NETBSD32TO64_UAP(pid);
2673 NETBSD32TO64_UAP(lid);
2674 NETBSD32TOP_UAP(policy, int *);
2675 NETBSD32TOP_UAP(params, struct sched_param *);
2676 return sys__sched_getparam(l, &ua, retval);
2677 }
2678
2679 int
2680 netbsd32__sched_setaffinity(struct lwp *l,
2681 const struct netbsd32__sched_setaffinity_args *uap,
2682 register_t *retval)
2683 {
2684 /* {
2685 syscallarg(pid_t) pid;
2686 syscallarg(lwpid_t) lid;
2687 syscallarg(netbsd_size_t) size;
2688 syscallarg(const netbsd32_cpusetp_t) cpuset;
2689 } */
2690 struct sys__sched_setaffinity_args ua;
2691
2692 NETBSD32TO64_UAP(pid);
2693 NETBSD32TO64_UAP(lid);
2694 NETBSD32TOX_UAP(size, size_t);
2695 NETBSD32TOP_UAP(cpuset, const cpuset_t *);
2696 return sys__sched_setaffinity(l, &ua, retval);
2697 }
2698
2699 int
2700 netbsd32__sched_getaffinity(struct lwp *l,
2701 const struct netbsd32__sched_getaffinity_args *uap,
2702 register_t *retval)
2703 {
2704 /* {
2705 syscallarg(pid_t) pid;
2706 syscallarg(lwpid_t) lid;
2707 syscallarg(netbsd_size_t) size;
2708 syscallarg(netbsd32_cpusetp_t) cpuset;
2709 } */
2710 struct sys__sched_getaffinity_args ua;
2711
2712 NETBSD32TO64_UAP(pid);
2713 NETBSD32TO64_UAP(lid);
2714 NETBSD32TOX_UAP(size, size_t);
2715 NETBSD32TOP_UAP(cpuset, cpuset_t *);
2716 return sys__sched_getaffinity(l, &ua, retval);
2717 }
2718
2719 int
2720 netbsd32__sched_protect(struct lwp *l,
2721 const struct netbsd32__sched_protect_args *uap,
2722 register_t *retval)
2723 {
2724 /* {
2725 syscallarg(int) priority;
2726 } */
2727 struct sys__sched_protect_args ua;
2728
2729 NETBSD32TO64_UAP(priority);
2730 return sys__sched_protect(l, &ua, retval);
2731 }
2732
2733 int
2734 netbsd32_pipe2(struct lwp *l, const struct netbsd32_pipe2_args *uap,
2735 register_t *retval)
2736 {
2737 /* {
2738 syscallarg(netbsd32_intp) fildes;
2739 syscallarg(int) flags;
2740 } */
2741 int fd[2], error;
2742
2743 error = pipe1(l, retval, SCARG(uap, flags));
2744 if (error != 0)
2745 return error;
2746
2747 fd[0] = retval[0];
2748 fd[1] = retval[1];
2749
2750 error = copyout(fd, SCARG_P32(uap, fildes), sizeof(fd));
2751 if (error != 0)
2752 return error;
2753
2754 retval[0] = 0;
2755 return 0;
2756 }
2757
2758 int
2759 netbsd32_dup3(struct lwp *l, const struct netbsd32_dup3_args *uap,
2760 register_t *retval)
2761 {
2762 /* {
2763 syscallarg(int) from;
2764 syscallarg(int) to;
2765 syscallarg(int) flags;
2766 } */
2767 struct sys_dup3_args ua;
2768
2769 NETBSD32TO64_UAP(from);
2770 NETBSD32TO64_UAP(to);
2771 NETBSD32TO64_UAP(flags);
2772
2773 return sys_dup3(l, &ua, retval);
2774 }
2775
2776 int
2777 netbsd32_kqueue1(struct lwp *l, const struct netbsd32_kqueue1_args *uap,
2778 register_t *retval)
2779 {
2780 /* {
2781 syscallarg(int) flags;
2782 } */
2783 struct sys_kqueue1_args ua;
2784
2785 NETBSD32TO64_UAP(flags);
2786
2787 return sys_kqueue1(l, &ua, retval);
2788 }
2789
2790 int
2791 netbsd32_paccept(struct lwp *l, const struct netbsd32_paccept_args *uap,
2792 register_t *retval)
2793 {
2794 /* {
2795 syscallarg(int) s;
2796 syscallarg(netbsd32_sockaddrp_t) name;
2797 syscallarg(netbsd32_socklenp_t) anamelen;
2798 syscallarg(const netbsd32_sigsetp_t) mask;
2799 syscallarg(int) flags;
2800 } */
2801 struct sys_paccept_args ua;
2802
2803 NETBSD32TO64_UAP(s);
2804 NETBSD32TOP_UAP(name, struct sockaddr *);
2805 NETBSD32TOP_UAP(anamelen, socklen_t *);
2806 NETBSD32TOP_UAP(mask, const sigset_t *);
2807 NETBSD32TO64_UAP(flags);
2808
2809 return sys_paccept(l, &ua, retval);
2810 }
2811
2812 int
2813 netbsd32_fdiscard(struct lwp *l, const struct netbsd32_fdiscard_args *uap,
2814 register_t *retval)
2815 {
2816 /* {
2817 syscallarg(int) fd;
2818 syscallarg(netbsd32_off_t) pos;
2819 syscallarg(netbsd32_off_t) len;
2820 } */
2821 struct sys_fdiscard_args ua;
2822
2823 NETBSD32TO64_UAP(fd);
2824 NETBSD32TO64_UAP(pos);
2825 NETBSD32TO64_UAP(len);
2826
2827 return sys_fdiscard(l, &ua, retval);
2828 }
2829
2830 int
2831 netbsd32_posix_fallocate(struct lwp *l, const struct netbsd32_posix_fallocate_args *uap,
2832 register_t *retval)
2833 {
2834 /* {
2835 syscallarg(int) fd;
2836 syscallarg(netbsd32_off_t) pos;
2837 syscallarg(netbsd32_off_t) len;
2838 } */
2839 struct sys_posix_fallocate_args ua;
2840
2841 NETBSD32TO64_UAP(fd);
2842 NETBSD32TO64_UAP(pos);
2843 NETBSD32TO64_UAP(len);
2844
2845 return sys_posix_fallocate(l, &ua, retval);
2846 }
2847
2848 int
2849 netbsd32_pset_create(struct lwp *l,
2850 const struct netbsd32_pset_create_args *uap, register_t *retval)
2851 {
2852 /* {
2853 syscallarg(netbsd32_psetidp_t) psid;
2854 }; */
2855
2856 return sys_pset_create(l, (const void *)uap, retval);
2857 }
2858
2859 int
2860 netbsd32_pset_destroy(struct lwp *l,
2861 const struct netbsd32_pset_destroy_args *uap, register_t *retval)
2862 {
2863 /* {
2864 syscallarg(psetid_t) psid;
2865 }; */
2866
2867 return sys_pset_destroy(l, (const void *)uap, retval);
2868 }
2869
2870 int
2871 netbsd32_pset_assign(struct lwp *l,
2872 const struct netbsd32_pset_assign_args *uap, register_t *retval)
2873 {
2874 /* {
2875 syscallarg(psetid_t) psid;
2876 syscallarg(cpuid_t) cpuid;
2877 syscallarg(netbsd32_psetidp_t) opsid;
2878 }; */
2879 struct sys_pset_assign_args ua;
2880
2881 SCARG(&ua, psid) = SCARG(uap, psid);
2882 NETBSD32TO64_UAP(cpuid);
2883 NETBSD32TOP_UAP(opsid, psetid_t);
2884
2885 return sys_pset_assign(l, &ua, retval);
2886 }
2887
2888 int
2889 netbsd32__pset_bind(struct lwp *l,
2890 const struct netbsd32__pset_bind_args *uap, register_t *retval)
2891 {
2892 /* {
2893 syscallarg(idtype_t) idtype;
2894 syscallarg(id_t) first_id;
2895 syscallarg(id_t) second_id;
2896 syscallarg(psetid_t) psid;
2897 syscallarg(netbsd32_psetidp_t) opsid;
2898 }; */
2899 struct sys__pset_bind_args ua;
2900
2901 SCARG(&ua, idtype) = SCARG(uap, idtype);
2902 SCARG(&ua, first_id) = SCARG(uap, first_id);
2903 SCARG(&ua, second_id) = SCARG(uap, second_id);
2904 SCARG(&ua, psid) = SCARG(uap, psid);
2905 NETBSD32TOP_UAP(opsid, psetid_t);
2906
2907 return sys__pset_bind(l, &ua, retval);
2908 }
2909
2910
2911 /*
2912 * MI indirect system call support.
2913 * Only used if the MD netbsd32_syscall.c doesn't intercept the calls.
2914 */
2915
2916 #define NETBSD32_SYSCALL
2917 #undef SYS_NSYSENT
2918 #define SYS_NSYSENT NETBSD32_SYS_NSYSENT
2919
2920 #define SYS_SYSCALL netbsd32_syscall
2921 #include "../../kern/sys_syscall.c"
2922 #undef SYS_SYSCALL
2923
2924 #define SYS_SYSCALL netbsd32____syscall
2925 #include "../../kern/sys_syscall.c"
2926 #undef SYS_SYSCALL
2927