netbsd32_compat_43.c revision 1.54.8.1 1 /* $NetBSD: netbsd32_compat_43.c,v 1.54.8.1 2020/01/21 18:12:54 martin Exp $ */
2
3 /*
4 * Copyright (c) 1998, 2001 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_compat_43.c,v 1.54.8.1 2020/01/21 18:12:54 martin Exp $");
31
32 #if defined(_KERNEL_OPT)
33 #include "opt_compat_43.h"
34 #endif
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/fcntl.h>
39 #include <sys/filedesc.h>
40 #include <sys/mbuf.h>
41 #include <sys/mount.h>
42 #include <sys/namei.h>
43 #include <sys/socket.h>
44 #include <sys/proc.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/stat.h>
48 #include <sys/syscallargs.h>
49 #include <sys/time.h>
50 #include <sys/ucred.h>
51 #include <sys/vfs_syscalls.h>
52 #include <uvm/uvm_extern.h>
53 #include <sys/sysctl.h>
54 #include <sys/swap.h>
55
56 #include <compat/netbsd32/netbsd32.h>
57 #include <compat/netbsd32/netbsd32_syscallargs.h>
58
59 #include <compat/sys/stat.h>
60 #include <compat/sys/signal.h>
61 #include <compat/sys/signalvar.h>
62 #include <compat/sys/socket.h>
63
64 #define SYS_DEF(foo) struct foo##_args; \
65 int foo(struct lwp *, const struct foo##_args *, register_t *)
66
67 SYS_DEF(compat_43_netbsd32_sethostid);
68 SYS_DEF(compat_43_netbsd32_killpg);
69 SYS_DEF(compat_43_netbsd32_sigblock);
70 SYS_DEF(compat_43_netbsd32_sigblock);
71 SYS_DEF(compat_43_netbsd32_sigsetmask);
72 #undef SYS_DEF
73
74 static void
75 netbsd32_from_stat(const struct stat *sb, struct netbsd32_stat43 *sp32)
76 {
77
78 memset(sp32, 0, sizeof(*sp32));
79 sp32->st_dev = sb->st_dev;
80 sp32->st_ino = sb->st_ino;
81 sp32->st_mode = sb->st_mode;
82 sp32->st_nlink = sb->st_nlink;
83 sp32->st_uid = sb->st_uid;
84 sp32->st_gid = sb->st_gid;
85 sp32->st_rdev = sb->st_rdev;
86 sp32->st_size = sb->st_size < (quad_t)1 << 32 ? sb->st_size : -2;
87 sp32->st_atimespec.tv_sec = sb->st_atimespec.tv_sec;
88 sp32->st_atimespec.tv_nsec = sb->st_atimespec.tv_nsec;
89 sp32->st_mtimespec.tv_sec = sb->st_mtimespec.tv_sec;
90 sp32->st_mtimespec.tv_nsec = sb->st_mtimespec.tv_nsec;
91 sp32->st_ctimespec.tv_sec = sb->st_ctimespec.tv_sec;
92 sp32->st_ctimespec.tv_nsec = sb->st_ctimespec.tv_nsec;
93 sp32->st_blksize = sb->st_blksize;
94 sp32->st_blocks = sb->st_blocks;
95 sp32->st_flags = sb->st_flags;
96 sp32->st_gen = sb->st_gen;
97 }
98
99 /* file system syscalls */
100 int
101 compat_43_netbsd32_ocreat(struct lwp *l, const struct compat_43_netbsd32_ocreat_args *uap, register_t *retval)
102 {
103 /* {
104 syscallarg(const netbsd32_charp) path;
105 syscallarg(mode_t) mode;
106 } */
107 struct sys_open_args ua;
108
109 NETBSD32TOP_UAP(path, const char);
110 NETBSD32TO64_UAP(mode);
111 SCARG(&ua, flags) = O_WRONLY | O_CREAT | O_TRUNC;
112
113 return (sys_open(l, &ua, retval));
114 }
115
116 int
117 compat_43_netbsd32_olseek(struct lwp *l, const struct compat_43_netbsd32_olseek_args *uap, register_t *retval)
118 {
119 /* {
120 syscallarg(int) fd;
121 syscallarg(netbsd32_long) offset;
122 syscallarg(int) whence;
123 } */
124 struct sys_lseek_args ua;
125
126 SCARG(&ua, fd) = SCARG(uap, fd);
127 NETBSD32TOX_UAP(offset, long);
128 NETBSD32TO64_UAP(whence);
129 /* Maybe offsets > 2^32 should generate an error ? */
130 return sys_lseek(l, &ua, retval);
131 }
132
133 int
134 compat_43_netbsd32_stat43(struct lwp *l, const struct compat_43_netbsd32_stat43_args *uap, register_t *retval)
135 {
136 /* {
137 syscallarg(const netbsd32_charp) path;
138 syscallarg(netbsd32_stat43p_t) ub;
139 } */
140 struct stat sb;
141 struct netbsd32_stat43 sb32;
142 int error;
143
144 error = do_sys_stat(SCARG_P32(uap, path), FOLLOW, &sb);
145 if (error == 0) {
146 netbsd32_from_stat(&sb, &sb32);
147 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
148 }
149 return error;
150 }
151
152 int
153 compat_43_netbsd32_lstat43(struct lwp *l, const struct compat_43_netbsd32_lstat43_args *uap, register_t *retval)
154 {
155 /* {
156 syscallarg(const netbsd32_charp) path;
157 syscallarg(netbsd32_stat43p_t) ub;
158 } */
159 struct stat sb;
160 struct netbsd32_stat43 sb32;
161 int error;
162
163 error = do_sys_stat(SCARG_P32(uap, path), NOFOLLOW, &sb);
164 if (error == 0) {
165 netbsd32_from_stat(&sb, &sb32);
166 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
167 }
168 return error;
169 }
170
171 int
172 compat_43_netbsd32_fstat43(struct lwp *l, const struct compat_43_netbsd32_fstat43_args *uap, register_t *retval)
173 {
174 /* {
175 syscallarg(int) fd;
176 syscallarg(netbsd32_stat43p_t) sb;
177 } */
178 struct stat sb;
179 struct netbsd32_stat43 sb32;
180 int error;
181
182 error = do_sys_fstat(SCARG(uap, fd), &sb);
183 if (error == 0) {
184 netbsd32_from_stat(&sb, &sb32);
185 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
186 }
187 return error;
188 }
189
190 int
191 compat_43_netbsd32_otruncate(struct lwp *l, const struct compat_43_netbsd32_otruncate_args *uap, register_t *retval)
192 {
193 /* {
194 syscallarg(const netbsd32_charp) path;
195 syscallarg(netbsd32_long) length;
196 } */
197 struct sys_truncate_args ua;
198
199 NETBSD32TOP_UAP(path, const char);
200 NETBSD32TO64_UAP(length);
201 return (sys_truncate(l, &ua, retval));
202 }
203
204 int
205 compat_43_netbsd32_oftruncate(struct lwp *l, const struct compat_43_netbsd32_oftruncate_args *uap, register_t *retval)
206 {
207 /* {
208 syscallarg(int) fd;
209 syscallarg(netbsd32_long) length;
210 } */
211 struct sys_ftruncate_args ua;
212
213 NETBSD32TO64_UAP(fd);
214 NETBSD32TO64_UAP(length);
215 return (sys_ftruncate(l, &ua, retval));
216 }
217
218 int
219 compat_43_netbsd32_ogetdirentries(struct lwp *l, const struct compat_43_netbsd32_ogetdirentries_args *uap, register_t *retval)
220 {
221 /* {
222 syscallarg(int) fd;
223 syscallarg(netbsd32_charp) buf;
224 syscallarg(u_int) count;
225 syscallarg(netbsd32_longp) basep;
226 } */
227 struct compat_43_sys_getdirentries_args ua;
228
229 NETBSD32TO64_UAP(fd);
230 NETBSD32TOP_UAP(buf, char);
231 NETBSD32TO64_UAP(count);
232 NETBSD32TOP_UAP(basep, long);
233 return (compat_43_sys_getdirentries(l, &ua, retval));
234 }
235
236 /* kernel syscalls */
237 int
238 compat_43_netbsd32_ogetkerninfo(struct lwp *l, const struct compat_43_netbsd32_ogetkerninfo_args *uap, register_t *retval)
239 {
240 /* {
241 syscallarg(int) op;
242 syscallarg(netbsd32_charp) where;
243 syscallarg(netbsd32_intp) size;
244 syscallarg(int) arg;
245 } */
246 struct compat_43_sys_getkerninfo_args ua;
247
248 NETBSD32TO64_UAP(op);
249 NETBSD32TOP_UAP(where, char);
250 NETBSD32TOP_UAP(size, int);
251 NETBSD32TO64_UAP(arg);
252 return (compat_43_sys_getkerninfo(l, &ua, retval));
253 }
254
255 int
256 compat_43_netbsd32_ogethostname(struct lwp *l, const struct compat_43_netbsd32_ogethostname_args *uap, register_t *retval)
257 {
258 /* {
259 syscallarg(netbsd32_charp) hostname;
260 syscallarg(u_int) len;
261 } */
262 int name[2];
263 size_t sz;
264
265 name[0] = CTL_KERN;
266 name[1] = KERN_HOSTNAME;
267 sz = SCARG(uap, len);
268 return (old_sysctl(&name[0], 2,
269 SCARG_P32(uap, hostname), &sz, 0, 0, l));
270 }
271
272 int
273 compat_43_netbsd32_osethostname(struct lwp *l, const struct compat_43_netbsd32_osethostname_args *uap, register_t *retval)
274 {
275 /* {
276 syscallarg(netbsd32_charp) hostname;
277 syscallarg(u_int) len;
278 } */
279 int name[2];
280
281 name[0] = CTL_KERN;
282 name[1] = KERN_HOSTNAME;
283 return old_sysctl(&name[0], 2, 0, 0, (char *)SCARG_P32(uap,
284 hostname), SCARG(uap, len), l);
285 }
286
287 int
288 compat_43_netbsd32_sethostid(struct lwp *l, const struct compat_43_netbsd32_sethostid_args *uap, register_t *retval)
289 {
290 /* {
291 syscallarg(int32_t) hostid;
292 } */
293 struct compat_43_sys_sethostid_args ua;
294
295 NETBSD32TO64_UAP(hostid);
296 return (compat_43_sys_sethostid(l, &ua, retval));
297 }
298
299 int
300 compat_43_netbsd32_ogetrlimit(struct lwp *l, const struct compat_43_netbsd32_ogetrlimit_args *uap, register_t *retval)
301 {
302 /* {
303 syscallarg(int) which;
304 syscallarg(netbsd32_orlimitp_t) rlp;
305 } */
306 struct compat_43_sys_getrlimit_args ua;
307
308 NETBSD32TO64_UAP(which);
309 NETBSD32TOP_UAP(rlp, struct orlimit);
310 return (compat_43_sys_getrlimit(l, &ua, retval));
311 }
312
313 int
314 compat_43_netbsd32_osetrlimit(struct lwp *l, const struct compat_43_netbsd32_osetrlimit_args *uap, register_t *retval)
315 {
316 /* {
317 syscallarg(int) which;
318 syscallarg(netbsd32_orlimitp_t) rlp;
319 } */
320 struct compat_43_sys_setrlimit_args ua;
321
322 NETBSD32TO64_UAP(which);
323 NETBSD32TOP_UAP(rlp, struct orlimit);
324 return (compat_43_sys_setrlimit(l, &ua, retval));
325 }
326
327 int
328 compat_43_netbsd32_killpg(struct lwp *l, const struct compat_43_netbsd32_killpg_args *uap, register_t *retval)
329 {
330 /* {
331 syscallarg(int) pgid;
332 syscallarg(int) signum;
333 } */
334 struct compat_43_sys_killpg_args ua;
335
336 NETBSD32TO64_UAP(pgid);
337 NETBSD32TO64_UAP(signum);
338 return (compat_43_sys_killpg(l, &ua, retval));
339 }
340
341 /* virtual memory syscalls */
342 int
343 compat_43_netbsd32_ommap(struct lwp *l, const struct compat_43_netbsd32_ommap_args *uap, register_t *retval)
344 {
345 /* {
346 syscallarg(netbsd32_voidp) addr;
347 syscallarg(netbsd32_size_t) len;
348 syscallarg(int) prot;
349 syscallarg(int) flags;
350 syscallarg(int) fd;
351 syscallarg(netbsd32_long) pos;
352 } */
353 struct compat_43_sys_mmap_args ua;
354
355 NETBSD32TOP_UAP(addr, void *);
356 NETBSD32TOX_UAP(len, size_t);
357 NETBSD32TO64_UAP(prot);
358 NETBSD32TO64_UAP(flags);
359 NETBSD32TO64_UAP(fd);
360 NETBSD32TOX_UAP(pos, long);
361 return (compat_43_sys_mmap(l, &ua, retval));
362 }
363
364 /* network syscalls */
365 int
366 compat_43_netbsd32_oaccept(struct lwp *l, const struct compat_43_netbsd32_oaccept_args *uap, register_t *retval)
367 {
368 /* {
369 syscallarg(int) s;
370 syscallarg(netbsd32_voidp) name;
371 syscallarg(netbsd32_intp) anamelen;
372 } */
373 struct compat_43_sys_accept_args ua;
374
375 NETBSD32TOX_UAP(s, int);
376 NETBSD32TOP_UAP(name, void *);
377 NETBSD32TOP_UAP(anamelen, int);
378 return (compat_43_sys_accept(l, &ua, retval));
379 }
380
381 int
382 compat_43_netbsd32_osend(struct lwp *l, const struct compat_43_netbsd32_osend_args *uap, register_t *retval)
383 {
384 /* {
385 syscallarg(int) s;
386 syscallarg(netbsd32_voidp) buf;
387 syscallarg(int) len;
388 syscallarg(int) flags;
389 } */
390 struct compat_43_sys_send_args ua;
391
392 NETBSD32TO64_UAP(s);
393 NETBSD32TOP_UAP(buf, void *);
394 NETBSD32TO64_UAP(len);
395 NETBSD32TO64_UAP(flags);
396 return (compat_43_sys_send(l, &ua, retval));
397 }
398
399 int
400 compat_43_netbsd32_orecv(struct lwp *l, const struct compat_43_netbsd32_orecv_args *uap, register_t *retval)
401 {
402 /* {
403 syscallarg(int) s;
404 syscallarg(netbsd32_voidp) buf;
405 syscallarg(int) len;
406 syscallarg(int) flags;
407 } */
408 struct compat_43_sys_recv_args ua;
409
410 NETBSD32TO64_UAP(s);
411 NETBSD32TOP_UAP(buf, void *);
412 NETBSD32TO64_UAP(len);
413 NETBSD32TO64_UAP(flags);
414 return (compat_43_sys_recv(l, &ua, retval));
415 }
416
417 /*
418 * This is a brutal clone of compat_43_sys_recvmsg().
419 */
420 int
421 compat_43_netbsd32_orecvmsg(struct lwp *l, const struct compat_43_netbsd32_orecvmsg_args *uap, register_t *retval)
422 {
423 /* {
424 syscallarg(int) s;
425 syscallarg(netbsd32_omsghdrp_t) msg;
426 syscallarg(int) flags;
427 } */
428 struct netbsd32_omsghdr omsg;
429 struct msghdr msg;
430 struct mbuf *from, *control;
431 struct iovec *iov, aiov[UIO_SMALLIOV];
432 int error;
433
434 error = copyin(SCARG_P32(uap, msg), &omsg, sizeof(omsg));
435 if (error)
436 return (error);
437
438 if (NETBSD32PTR64(omsg.msg_accrights) == NULL)
439 omsg.msg_accrightslen = 0;
440 /* it was this way in 4.4BSD */
441 if (omsg.msg_accrightslen > MLEN)
442 return EINVAL;
443
444 iov = netbsd32_get_iov(NETBSD32PTR64(omsg.msg_iov), omsg.msg_iovlen,
445 aiov, __arraycount(aiov));
446 if (iov == NULL)
447 return EFAULT;
448
449 msg.msg_name = NETBSD32PTR64(omsg.msg_name);
450 msg.msg_namelen = omsg.msg_namelen;
451 msg.msg_iovlen = omsg.msg_iovlen;
452 msg.msg_iov = iov;
453 msg.msg_flags = SCARG(uap, flags) & MSG_USERFLAGS;
454
455 error = do_sys_recvmsg(l, SCARG(uap, s), &msg, NULL, 0, &from,
456 NETBSD32PTR64(omsg.msg_accrights) != NULL ? &control : NULL,
457 retval);
458 if (error != 0)
459 goto out;
460
461 /*
462 * If there is any control information and it's SCM_RIGHTS,
463 * pass it back to the program.
464 * XXX: maybe there can be more than one chunk of control data?
465 */
466 if (NETBSD32PTR64(omsg.msg_accrights) != NULL && control != NULL) {
467 struct cmsghdr *cmsg = mtod(control, void *);
468
469 if (cmsg->cmsg_level == SOL_SOCKET
470 && cmsg->cmsg_type == SCM_RIGHTS
471 && cmsg->cmsg_len < omsg.msg_accrightslen
472 && copyout(CMSG_DATA(cmsg),
473 NETBSD32PTR64(omsg.msg_accrights),
474 cmsg->cmsg_len) == 0) {
475 omsg.msg_accrightslen = cmsg->cmsg_len;
476 free_control_mbuf(l, control, control->m_next);
477 } else {
478 omsg.msg_accrightslen = 0;
479 free_control_mbuf(l, control, control);
480 }
481 } else
482 omsg.msg_accrightslen = 0;
483
484 if (from != NULL)
485 /* convert from sockaddr sa_family to osockaddr one here */
486 mtod(from, struct osockaddr *)->sa_family =
487 mtod(from, struct sockaddr *)->sa_family;
488
489 error = copyout_sockname(NETBSD32PTR64(omsg.msg_name),
490 &omsg.msg_namelen, 0, from);
491 if (from != NULL)
492 m_free(from);
493
494 if (error != 0)
495 error = copyout(&omsg, SCARG_P32(uap, msg), sizeof(omsg));
496 out:
497 if (iov != aiov) {
498 kmem_free(iov, omsg.msg_iovlen * sizeof(*iov));
499 }
500 return error;
501 }
502
503 int
504 compat_43_netbsd32_osendmsg(struct lwp *l, const struct compat_43_netbsd32_osendmsg_args *uap, register_t *retval)
505 {
506 /* {
507 syscallarg(int) s;
508 syscallarg(netbsd32_voidp) msg;
509 syscallarg(int) flags;
510 } */
511 struct iovec *iov, aiov[UIO_SMALLIOV];
512 struct netbsd32_omsghdr omsg;
513 struct msghdr msg;
514 struct mbuf *nam;
515 struct osockaddr *osa;
516 struct sockaddr *sa;
517 int error;
518
519 error = copyin(SCARG_P32(uap, msg), &omsg, sizeof(omsg));
520 if (error != 0)
521 return (error);
522
523 iov = netbsd32_get_iov(NETBSD32PTR64(omsg.msg_iov), omsg.msg_iovlen,
524 aiov, __arraycount(aiov));
525 if (iov == NULL)
526 return EFAULT;
527
528 msg.msg_iovlen = omsg.msg_iovlen;
529 msg.msg_iov = iov;
530 msg.msg_flags = MSG_NAMEMBUF;
531
532 error = sockargs(&nam, NETBSD32PTR64(omsg.msg_name), omsg.msg_namelen,
533 MT_SONAME);
534 if (error != 0)
535 goto out;
536
537 sa = mtod(nam, void *);
538 osa = mtod(nam, void *);
539 sa->sa_family = osa->sa_family;
540 sa->sa_len = omsg.msg_namelen;
541
542 msg.msg_name = nam;
543 msg.msg_namelen = omsg.msg_namelen;
544 error = compat43_set_accrights(&msg, NETBSD32PTR64(omsg.msg_accrights),
545 omsg.msg_accrightslen);
546 if (error != 0) {
547 m_free(nam);
548 goto out;
549 }
550
551 error = do_sys_sendmsg(l, SCARG(uap, s), &msg, SCARG(uap, flags),
552 &omsg, sizeof(omsg), retval);
553
554 out:
555 if (iov != aiov)
556 kmem_free(iov, omsg.msg_iovlen * sizeof(*iov));
557 return (error);
558 }
559
560 int
561 compat_43_netbsd32_orecvfrom(struct lwp *l, const struct compat_43_netbsd32_orecvfrom_args *uap, register_t *retval)
562 {
563 /* {
564 syscallarg(int) s;
565 syscallarg(netbsd32_voidp) buf;
566 syscallarg(netbsd32_size_t) len;
567 syscallarg(int) flags;
568 syscallarg(netbsd32_voidp) from;
569 syscallarg(netbsd32_intp) fromlenaddr;
570 } */
571 struct compat_43_sys_recvfrom_args ua;
572
573 NETBSD32TO64_UAP(s);
574 NETBSD32TOP_UAP(buf, void *);
575 NETBSD32TOX_UAP(len, size_t);
576 NETBSD32TO64_UAP(flags);
577 NETBSD32TOP_UAP(from, void *);
578 NETBSD32TOP_UAP(fromlenaddr, int);
579 return (compat_43_sys_recvfrom(l, &ua, retval));
580 }
581
582 int
583 compat_43_netbsd32_ogetsockname(struct lwp *l, const struct compat_43_netbsd32_ogetsockname_args *uap, register_t *retval)
584 {
585 /* {
586 syscallarg(int) fdec;
587 syscallarg(netbsd32_voidp) asa;
588 syscallarg(netbsd32_intp) alen;
589 } */
590 struct compat_43_sys_getsockname_args ua;
591
592 NETBSD32TO64_UAP(fdec);
593 NETBSD32TOP_UAP(asa, void *);
594 NETBSD32TOP_UAP(alen, int *);
595 return (compat_43_sys_getsockname(l, &ua, retval));
596 }
597
598 int
599 compat_43_netbsd32_ogetpeername(struct lwp *l, const struct compat_43_netbsd32_ogetpeername_args *uap, register_t *retval)
600 {
601 /* {
602 syscallarg(int) fdes;
603 syscallarg(netbsd32_voidp) asa;
604 syscallarg(netbsd32_intp) alen;
605 } */
606 struct compat_43_sys_getpeername_args ua;
607
608 NETBSD32TO64_UAP(fdes);
609 NETBSD32TOP_UAP(asa, void *);
610 NETBSD32TOP_UAP(alen, int *);
611 return (compat_43_sys_getpeername(l, &ua, retval));
612 }
613
614 /* signal syscalls */
615 int
616 compat_43_netbsd32_osigvec(struct lwp *l, const struct compat_43_netbsd32_osigvec_args *uap, register_t *retval)
617 {
618 /* {
619 syscallarg(int) signum;
620 syscallarg(netbsd32_sigvecp_t) nsv;
621 syscallarg(netbsd32_sigvecp_t) osv;
622 } */
623 struct netbsd32_sigvec sv32;
624 struct sigaction nsa, osa;
625 int error;
626
627 if (SCARG(uap, signum) >= 32)
628 return EINVAL;
629
630 if (SCARG_P32(uap, nsv)) {
631 error = copyin(SCARG_P32(uap, nsv), &sv32, sizeof(sv32));
632 if (error)
633 return error;
634 nsa.sa_handler = NETBSD32PTR64(sv32.sv_handler);
635 nsa.sa_mask.__bits[0] = sv32.sv_mask;
636 nsa.sa_mask.__bits[1] = 0;
637 nsa.sa_mask.__bits[2] = 0;
638 nsa.sa_mask.__bits[3] = 0;
639 nsa.sa_flags = sv32.sv_flags ^ SA_RESTART;
640 error = sigaction1(l, SCARG(uap, signum), &nsa, &osa, NULL, 0);
641 } else
642 error = sigaction1(l, SCARG(uap, signum), NULL, &osa, NULL, 0);
643 if (error)
644 return error;
645
646 if (SCARG_P32(uap, osv)) {
647 NETBSD32PTR32(sv32.sv_handler, osa.sa_handler);
648 sv32.sv_mask = osa.sa_mask.__bits[0];
649 sv32.sv_flags = osa.sa_flags ^ SA_RESTART;
650 error = copyout(&sv32, SCARG_P32(uap, osv), sizeof(sv32));
651 }
652
653 return error;
654 }
655
656 int
657 compat_43_netbsd32_sigblock(struct lwp *l, const struct compat_43_netbsd32_sigblock_args *uap, register_t *retval)
658 {
659 /* {
660 syscallarg(int) mask;
661 } */
662 struct compat_43_sys_sigblock_args ua;
663
664 NETBSD32TO64_UAP(mask);
665 return (compat_43_sys_sigblock(l, &ua, retval));
666 }
667
668 int
669 compat_43_netbsd32_sigsetmask(struct lwp *l, const struct compat_43_netbsd32_sigsetmask_args *uap, register_t *retval)
670 {
671 /* {
672 syscallarg(int) mask;
673 } */
674 struct compat_43_sys_sigsetmask_args ua;
675
676 NETBSD32TO64_UAP(mask);
677 return (compat_43_sys_sigsetmask(l, &ua, retval));
678 }
679
680 int
681 compat_43_netbsd32_osigstack(struct lwp *l, const struct compat_43_netbsd32_osigstack_args *uap, register_t *retval)
682 {
683 /* {
684 syscallarg(netbsd32_sigstackp_t) nss;
685 syscallarg(netbsd32_sigstackp_t) oss;
686 } */
687 struct netbsd32_sigstack ss32;
688 struct sigaltstack nsa, osa;
689 int error;
690
691 if (SCARG_P32(uap, nss)) {
692 error = copyin(SCARG_P32(uap, nss), &ss32, sizeof(ss32));
693 if (error)
694 return error;
695 nsa.ss_sp = NETBSD32PTR64(ss32.ss_sp);
696 nsa.ss_size = SIGSTKSZ; /* Use the recommended size */
697 nsa.ss_flags = ss32.ss_onstack ? SS_ONSTACK : 0;
698 error = sigaltstack1(l, &nsa, &osa);
699 } else
700 error = sigaltstack1(l, NULL, &osa);
701 if (error)
702 return error;
703
704 if (SCARG_P32(uap, oss)) {
705 NETBSD32PTR32(ss32.ss_sp, osa.ss_sp);
706 ss32.ss_onstack = (osa.ss_flags & SS_ONSTACK) != 0;
707 error = copyout(&ss32, SCARG_P32(uap, oss), sizeof(ss32));
708 }
709
710 return error;
711 }
712