1 /* $NetBSD: netbsd32_signal.c,v 1.53 2021/11/06 20:42:56 thorpej 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_signal.c,v 1.53 2021/11/06 20:42:56 thorpej Exp $"); 31 32 #if defined(_KERNEL_OPT) 33 #include "opt_ktrace.h" 34 #endif 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/mount.h> 39 #include <sys/stat.h> 40 #include <sys/time.h> 41 #include <sys/signalvar.h> 42 #include <sys/ktrace.h> 43 #include <sys/proc.h> 44 #include <sys/wait.h> 45 #include <sys/dirent.h> 46 #include <sys/module.h> 47 #include <sys/exec.h> 48 49 #include <uvm/uvm_extern.h> 50 51 #include <compat/netbsd32/netbsd32.h> 52 #include <compat/netbsd32/netbsd32_conv.h> 53 #include <compat/netbsd32/netbsd32_exec.h> 54 #include <compat/netbsd32/netbsd32_syscallargs.h> 55 56 #include <compat/sys/signal.h> 57 #include <compat/sys/signalvar.h> 58 #include <compat/sys/siginfo.h> 59 #include <compat/sys/ucontext.h> 60 #include <compat/common/compat_sigaltstack.h> 61 62 int 63 netbsd32_sigaction(struct lwp *l, const struct netbsd32_sigaction_args *uap, register_t *retval) 64 { 65 /* { 66 syscallarg(int) signum; 67 syscallarg(const netbsd32_sigactionp_t) nsa; 68 syscallarg(netbsd32_sigactionp_t) osa; 69 } */ 70 struct sigaction nsa, osa; 71 struct netbsd32_sigaction13 *sa32p, sa32; 72 int error; 73 74 if (SCARG_P32(uap, nsa)) { 75 sa32p = SCARG_P32(uap, nsa); 76 if (copyin(sa32p, &sa32, sizeof(sa32))) 77 return EFAULT; 78 nsa.sa_handler = (void *)NETBSD32PTR64(sa32.netbsd32_sa_handler); 79 memset(&nsa.sa_mask, 0, sizeof(nsa.sa_mask)); 80 nsa.sa_mask.__bits[0] = sa32.netbsd32_sa_mask; 81 nsa.sa_flags = sa32.netbsd32_sa_flags; 82 } 83 error = sigaction1(l, SCARG(uap, signum), 84 SCARG_P32(uap, nsa) ? &nsa : 0, 85 SCARG_P32(uap, osa) ? &osa : 0, 86 NULL, 0); 87 88 if (error) 89 return error; 90 91 if (SCARG_P32(uap, osa)) { 92 memset(&sa32, 0, sizeof(sa32)); 93 NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler); 94 sa32.netbsd32_sa_mask = osa.sa_mask.__bits[0]; 95 sa32.netbsd32_sa_flags = osa.sa_flags; 96 sa32p = SCARG_P32(uap, osa); 97 if (copyout(&sa32, sa32p, sizeof(sa32))) 98 return EFAULT; 99 } 100 101 return 0; 102 } 103 104 int 105 netbsd32___sigaltstack14(struct lwp *l, const struct netbsd32___sigaltstack14_args *uap, register_t *retval) 106 { 107 /* { 108 syscallarg(const netbsd32_sigaltstackp_t) nss; 109 syscallarg(netbsd32_sigaltstackp_t) oss; 110 } */ 111 compat_sigaltstack(uap, netbsd32_sigaltstack, SS_ONSTACK, SS_DISABLE); 112 } 113 114 /* ARGSUSED */ 115 int 116 netbsd32___sigaction14(struct lwp *l, const struct netbsd32___sigaction14_args *uap, register_t *retval) 117 { 118 /* { 119 syscallarg(int) signum; 120 syscallarg(const struct sigaction *) nsa; 121 syscallarg(struct sigaction *) osa; 122 } */ 123 struct netbsd32_sigaction sa32; 124 struct sigaction nsa, osa; 125 int error; 126 127 if (SCARG_P32(uap, nsa)) { 128 error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32)); 129 if (error) 130 return error; 131 nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler); 132 nsa.sa_mask = sa32.netbsd32_sa_mask; 133 nsa.sa_flags = sa32.netbsd32_sa_flags; 134 } 135 error = sigaction1(l, SCARG(uap, signum), 136 SCARG_P32(uap, nsa) ? &nsa : 0, 137 SCARG_P32(uap, osa) ? &osa : 0, 138 NULL, 0); 139 if (error) 140 return error; 141 if (SCARG_P32(uap, osa)) { 142 memset(&sa32, 0, sizeof(sa32)); 143 NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler); 144 sa32.netbsd32_sa_mask = osa.sa_mask; 145 sa32.netbsd32_sa_flags = osa.sa_flags; 146 error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32)); 147 if (error) 148 return error; 149 } 150 return 0; 151 } 152 153 /* ARGSUSED */ 154 int 155 netbsd32___sigaction_sigtramp(struct lwp *l, const struct netbsd32___sigaction_sigtramp_args *uap, register_t *retval) 156 { 157 /* { 158 syscallarg(int) signum; 159 syscallarg(const netbsd32_sigactionp_t) nsa; 160 syscallarg(netbsd32_sigactionp_t) osa; 161 syscallarg(netbsd32_voidp) tramp; 162 syscallarg(int) vers; 163 } */ 164 struct netbsd32_sigaction sa32; 165 struct sigaction nsa, osa; 166 int error, vers; 167 168 if (SCARG_P32(uap, nsa)) { 169 error = copyin(SCARG_P32(uap, nsa), &sa32, sizeof(sa32)); 170 if (error) 171 return error; 172 nsa.sa_handler = NETBSD32PTR64(sa32.netbsd32_sa_handler); 173 nsa.sa_mask = sa32.netbsd32_sa_mask; 174 nsa.sa_flags = sa32.netbsd32_sa_flags; 175 } 176 vers = SCARG(uap, vers); 177 #ifndef __HAVE_MD_NETBSD32_SENDSIG /* XXX paying for yesterday's sins */ 178 if (vers < __SIGTRAMP_SIGINFO_VERSION_MIN) { 179 /* 180 * sigaction1() doesn't enforce sigcontext-ness for 181 * __SIGTRAMP_SIGCODE_VERSION because it might be 182 * a foreign emulation. However, we know these are 183 * native NetBSD 32-bit binaries, so we do. 184 */ 185 #ifdef __HAVE_STRUCT_SIGCONTEXT 186 struct proc *p = l->l_proc; 187 bool sigcontext_valid = false; 188 189 /* 190 * We need to ensure the compat_netbsd32_16 module 191 * is loaded, because sigaction1() gives a free pass 192 * to processes marked PK_32 (it can't be sure which 193 * 32-bit compat module is needed). 194 */ 195 if ((p->p_lflag & PL_SIGCOMPAT) == 0) { 196 kernconfig_lock(); 197 (void)module_autoload("compat_netbsd32_16", 198 MODULE_CLASS_ANY); 199 if (netbsd32_sendsig_sigcontext_16_hook.hooked) { 200 sigcontext_valid = true; 201 } 202 mutex_enter(&proc_lock); 203 /* 204 * Prevent unload of compat module while 205 * this process remains. 206 */ 207 p->p_lflag |= PL_SIGCOMPAT; 208 mutex_exit(&proc_lock); 209 kernconfig_unlock(); 210 } 211 if (!sigcontext_valid) { 212 return EINVAL; 213 } 214 #else /* ! __HAVE_STRUCT_SIGCONTEXT */ 215 return EINVAL; 216 #endif /* __HAVE_STRUCT_SIGCONTEXT */ 217 } 218 #endif /* __HAVE_MD_NETBSD32_SENDSIG */ 219 error = sigaction1(l, SCARG(uap, signum), 220 SCARG_P32(uap, nsa) ? &nsa : 0, 221 SCARG_P32(uap, osa) ? &osa : 0, 222 SCARG_P32(uap, tramp), vers); 223 if (error) 224 return error; 225 if (SCARG_P32(uap, osa)) { 226 memset(&sa32, 0, sizeof(sa32)); 227 NETBSD32PTR32(sa32.netbsd32_sa_handler, osa.sa_handler); 228 sa32.netbsd32_sa_mask = osa.sa_mask; 229 sa32.netbsd32_sa_flags = osa.sa_flags; 230 error = copyout(&sa32, SCARG_P32(uap, osa), sizeof(sa32)); 231 if (error) 232 return error; 233 } 234 return 0; 235 } 236 237 #ifndef __HAVE_MD_NETBSD32_SENDSIG /* XXX paying for yesterday's sins */ 238 #ifdef __HAVE_STRUCT_SIGCONTEXT 239 struct netbsd32_sendsig_sigcontext_16_hook_t netbsd32_sendsig_sigcontext_16_hook; 240 #endif 241 242 void 243 netbsd32_sendsig(const struct ksiginfo *ksi, const sigset_t *mask) 244 { 245 struct sigacts *sa; 246 int sig; 247 248 sig = ksi->ksi_signo; 249 sa = curproc->p_sigacts; 250 251 switch (sa->sa_sigdesc[sig].sd_vers) { 252 #ifdef __HAVE_STRUCT_SIGCONTEXT 253 case __SIGTRAMP_SIGCODE_VERSION: 254 case __SIGTRAMP_SIGCONTEXT_VERSION_MIN ... 255 __SIGTRAMP_SIGCONTEXT_VERSION_MAX: 256 /* Compat for 1.6 and earlier. */ 257 MODULE_HOOK_CALL_VOID(netbsd32_sendsig_sigcontext_16_hook, 258 (ksi, mask), break); 259 return; 260 #endif /* __HAVE_STRUCT_SIGCONTEXT */ 261 case __SIGTRAMP_SIGINFO_VERSION_MIN ... 262 __SIGTRAMP_SIGINFO_VERSION_MAX: 263 netbsd32_sendsig_siginfo(ksi, mask); 264 return; 265 default: 266 break; 267 } 268 269 printf("%s: bad version %d\n", __func__, sa->sa_sigdesc[sig].sd_vers); 270 sigexit(curlwp, SIGILL); 271 } 272 #endif /* __HAVE_MD_NETBSD32_SENDSIG */ 273 274 void 275 netbsd32_ksi32_to_ksi(struct _ksiginfo *si, const struct __ksiginfo32 *si32) 276 { 277 size_t i; 278 279 memset(si, 0, sizeof (*si)); 280 si->_signo = si32->_signo; 281 si->_code = si32->_code; 282 si->_errno = si32->_errno; 283 284 if (si32->_code == SI_NOINFO) 285 return; 286 else if (si32->_code <= 0) /* codes described in siginfo(2) */ 287 goto fill_rt; 288 289 switch (si32->_signo) { 290 case SIGILL: 291 case SIGFPE: 292 case SIGBUS: 293 case SIGSEGV: 294 fill_fault: 295 si->_reason._fault._addr = 296 NETBSD32IPTR64(si32->_reason._fault._addr); 297 si->_reason._fault._trap = si32->_reason._fault._trap; 298 break; 299 case SIGTRAP: 300 switch (si32->_code) { 301 case TRAP_EXEC: 302 break; 303 case TRAP_CHLD: 304 case TRAP_LWP: 305 si->_reason._ptrace_state._pe_report_event = 306 si32->_reason._ptrace_state._pe_report_event; 307 CTASSERT(sizeof(si->_reason._ptrace_state._option._pe_other_pid) == 308 sizeof(si->_reason._ptrace_state._option._pe_lwp)); 309 si->_reason._ptrace_state._option._pe_other_pid = 310 si32->_reason._ptrace_state._option._pe_other_pid; 311 break; 312 case TRAP_SCE: 313 case TRAP_SCX: 314 si->_reason._syscall._sysnum = 315 si32->_reason._syscall._sysnum; 316 si->_reason._syscall._retval[0] = 317 si32->_reason._syscall._retval[0]; 318 si->_reason._syscall._retval[1] = 319 si32->_reason._syscall._retval[1]; 320 si->_reason._syscall._error = 321 si32->_reason._syscall._error; 322 for (i = 0; 323 i < __arraycount(si->_reason._syscall._args); i++) 324 si->_reason._syscall._args[i] = 325 si32->_reason._syscall._args[i]; 326 break; 327 default: 328 goto fill_fault; 329 } 330 break; 331 case SIGALRM: 332 case SIGVTALRM: 333 case SIGPROF: 334 default: /* see sigqueue() and kill1() */ 335 fill_rt: 336 si->_reason._rt._pid = si32->_reason._rt._pid; 337 si->_reason._rt._uid = si32->_reason._rt._uid; 338 si->_reason._rt._value.sival_int = 339 si32->_reason._rt._value.sival_int; 340 break; 341 case SIGURG: 342 case SIGIO: 343 si->_reason._poll._band = si32->_reason._poll._band; 344 si->_reason._poll._fd = si32->_reason._poll._fd; 345 break; 346 case SIGCHLD: 347 si->_reason._child._pid = si32->_reason._child._pid; 348 si->_reason._child._uid = si32->_reason._child._uid; 349 si->_reason._child._status = si32->_reason._child._status; 350 si->_reason._child._utime = si32->_reason._child._utime; 351 si->_reason._child._stime = si32->_reason._child._stime; 352 break; 353 } 354 } 355 356 void 357 netbsd32_si32_to_si(siginfo_t *si, const siginfo32_t *si32) 358 { 359 360 memset(si, 0, sizeof (*si)); 361 netbsd32_ksi32_to_ksi(&si->_info, &si32->_info); 362 } 363 364 static void 365 netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si) 366 { 367 size_t i; 368 369 memset(si32, 0, sizeof (*si32)); 370 si32->_signo = si->_signo; 371 si32->_code = si->_code; 372 si32->_errno = si->_errno; 373 374 if (si->_code == SI_NOINFO) 375 return; 376 else if (si->_code <= 0) /* codes described in siginfo(2) */ 377 goto fill_rt; 378 379 switch (si->_signo) { 380 case SIGILL: 381 case SIGFPE: 382 case SIGBUS: 383 case SIGSEGV: 384 fill_fault: 385 si32->_reason._fault._addr = 386 NETBSD32PTR32I(si->_reason._fault._addr); 387 si32->_reason._fault._trap = si->_reason._fault._trap; 388 break; 389 case SIGTRAP: 390 switch (si->_code) { 391 case TRAP_EXEC: 392 break; 393 case TRAP_CHLD: 394 case TRAP_LWP: 395 si32->_reason._ptrace_state._pe_report_event = 396 si->_reason._ptrace_state._pe_report_event; 397 CTASSERT(sizeof(si32->_reason._ptrace_state._option._pe_other_pid) == 398 sizeof(si32->_reason._ptrace_state._option._pe_lwp)); 399 si32->_reason._ptrace_state._option._pe_other_pid = 400 si->_reason._ptrace_state._option._pe_other_pid; 401 break; 402 case TRAP_SCE: 403 case TRAP_SCX: 404 si32->_reason._syscall._sysnum = 405 si->_reason._syscall._sysnum; 406 si32->_reason._syscall._retval[0] = 407 si->_reason._syscall._retval[0]; 408 si32->_reason._syscall._retval[1] = 409 si->_reason._syscall._retval[1]; 410 si32->_reason._syscall._error = 411 si->_reason._syscall._error; 412 for (i = 0; 413 i < __arraycount(si->_reason._syscall._args); i++) 414 si32->_reason._syscall._args[i] = 415 si->_reason._syscall._args[i]; 416 break; 417 default: 418 goto fill_fault; 419 } 420 break; 421 case SIGALRM: 422 case SIGVTALRM: 423 case SIGPROF: 424 default: /* see sigqueue() and kill1() */ 425 fill_rt: 426 si32->_reason._rt._pid = si->_reason._rt._pid; 427 si32->_reason._rt._uid = si->_reason._rt._uid; 428 si32->_reason._rt._value.sival_int = 429 si->_reason._rt._value.sival_int; 430 break; 431 case SIGURG: 432 case SIGIO: 433 si32->_reason._poll._band = si->_reason._poll._band; 434 si32->_reason._poll._fd = si->_reason._poll._fd; 435 break; 436 case SIGCHLD: 437 si32->_reason._child._pid = si->_reason._child._pid; 438 si32->_reason._child._uid = si->_reason._child._uid; 439 si32->_reason._child._status = si->_reason._child._status; 440 si32->_reason._child._utime = si->_reason._child._utime; 441 si32->_reason._child._stime = si->_reason._child._stime; 442 break; 443 } 444 } 445 446 void 447 netbsd32_si_to_si32(siginfo32_t *si32, const siginfo_t *si) 448 { 449 450 memset(si32, 0, sizeof (*si32)); 451 netbsd32_ksi_to_ksi32(&si32->_info, &si->_info); 452 } 453 454 void 455 getucontext32(struct lwp *l, ucontext32_t *ucp) 456 { 457 struct proc *p = l->l_proc; 458 459 KASSERT(mutex_owned(p->p_lock)); 460 461 ucp->uc_flags = 0; 462 ucp->uc_link = (uint32_t)(intptr_t)l->l_ctxlink; 463 ucp->uc_sigmask = l->l_sigmask; 464 ucp->uc_flags |= _UC_SIGMASK; 465 466 /* 467 * The (unsupplied) definition of the `current execution stack' 468 * in the System V Interface Definition appears to allow returning 469 * the main context stack. 470 */ 471 if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) { 472 ucp->uc_stack.ss_sp = USRSTACK32; 473 ucp->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize); 474 ucp->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */ 475 } else { 476 /* Simply copy alternate signal execution stack. */ 477 ucp->uc_stack.ss_sp = 478 (uint32_t)(intptr_t)l->l_sigstk.ss_sp; 479 ucp->uc_stack.ss_size = l->l_sigstk.ss_size; 480 ucp->uc_stack.ss_flags = l->l_sigstk.ss_flags; 481 } 482 ucp->uc_flags |= _UC_STACK; 483 mutex_exit(p->p_lock); 484 cpu_getmcontext32(l, &ucp->uc_mcontext, &ucp->uc_flags); 485 mutex_enter(p->p_lock); 486 } 487 488 int 489 netbsd32_getcontext(struct lwp *l, const struct netbsd32_getcontext_args *uap, register_t *retval) 490 { 491 /* { 492 syscallarg(netbsd32_ucontextp) ucp; 493 } */ 494 struct proc *p = l->l_proc; 495 ucontext32_t uc; 496 497 memset(&uc, 0, sizeof(uc)); 498 499 mutex_enter(p->p_lock); 500 getucontext32(l, &uc); 501 mutex_exit(p->p_lock); 502 503 return copyout(&uc, SCARG_P32(uap, ucp), sizeof (ucontext32_t)); 504 } 505 506 int 507 setucontext32(struct lwp *l, const ucontext32_t *ucp) 508 { 509 struct proc *p = l->l_proc; 510 int error; 511 512 KASSERT(mutex_owned(p->p_lock)); 513 514 if ((ucp->uc_flags & _UC_SIGMASK) != 0) { 515 error = sigprocmask1(l, SIG_SETMASK, &ucp->uc_sigmask, NULL); 516 if (error != 0) 517 return error; 518 } 519 520 mutex_exit(p->p_lock); 521 error = cpu_setmcontext32(l, &ucp->uc_mcontext, ucp->uc_flags); 522 mutex_enter(p->p_lock); 523 if (error != 0) 524 return error; 525 526 l->l_ctxlink = (void *)(intptr_t)ucp->uc_link; 527 528 /* 529 * If there was stack information, update whether or not we are 530 * still running on an alternate signal stack. 531 */ 532 if ((ucp->uc_flags & _UC_STACK) != 0) { 533 if (ucp->uc_stack.ss_flags & SS_ONSTACK) 534 l->l_sigstk.ss_flags |= SS_ONSTACK; 535 else 536 l->l_sigstk.ss_flags &= ~SS_ONSTACK; 537 } 538 539 return 0; 540 } 541 542 /* ARGSUSED */ 543 int 544 netbsd32_setcontext(struct lwp *l, const struct netbsd32_setcontext_args *uap, register_t *retval) 545 { 546 /* { 547 syscallarg(netbsd32_ucontextp) ucp; 548 } */ 549 ucontext32_t uc; 550 int error; 551 struct proc *p = l->l_proc; 552 553 error = copyin(SCARG_P32(uap, ucp), &uc, sizeof (uc)); 554 if (error) 555 return error; 556 if (!(uc.uc_flags & _UC_CPU)) 557 return EINVAL; 558 mutex_enter(p->p_lock); 559 error = setucontext32(l, &uc); 560 mutex_exit(p->p_lock); 561 if (error) 562 return error; 563 564 return EJUSTRETURN; 565 } 566 567 static int 568 netbsd32_sigtimedwait_put_info(const void *src, void *dst, size_t size) 569 { 570 const siginfo_t *info = src; 571 siginfo32_t info32; 572 573 netbsd32_si_to_si32(&info32, info); 574 575 return copyout(&info32, dst, sizeof(info32)); 576 } 577 578 static int 579 netbsd32_sigtimedwait_fetch_timeout(const void *src, void *dst, size_t size) 580 { 581 struct timespec *ts = dst; 582 struct netbsd32_timespec ts32; 583 int error; 584 585 error = copyin(src, &ts32, sizeof(ts32)); 586 if (error) 587 return error; 588 589 netbsd32_to_timespec(&ts32, ts); 590 return 0; 591 } 592 593 static int 594 netbsd32_sigtimedwait_put_timeout(const void *src, void *dst, size_t size) 595 { 596 const struct timespec *ts = src; 597 struct netbsd32_timespec ts32; 598 599 netbsd32_from_timespec(ts, &ts32); 600 601 return copyout(&ts32, dst, sizeof(ts32)); 602 } 603 604 int 605 netbsd32_____sigtimedwait50(struct lwp *l, const struct netbsd32_____sigtimedwait50_args *uap, register_t *retval) 606 { 607 /* { 608 syscallarg(netbsd32_sigsetp_t) set; 609 syscallarg(netbsd32_siginfop_t) info; 610 syscallarg(netbsd32_timespec50p_t) timeout; 611 } */ 612 struct sys_____sigtimedwait50_args ua; 613 614 NETBSD32TOP_UAP(set, const sigset_t); 615 NETBSD32TOP_UAP(info, siginfo_t); 616 NETBSD32TOP_UAP(timeout, struct timespec); 617 618 return sigtimedwait1(l, &ua, retval, 619 copyin, 620 netbsd32_sigtimedwait_put_info, 621 netbsd32_sigtimedwait_fetch_timeout, 622 netbsd32_sigtimedwait_put_timeout); 623 } 624 625 int 626 netbsd32_sigqueueinfo(struct lwp *l, 627 const struct netbsd32_sigqueueinfo_args *uap, register_t *retval) 628 { 629 /* { 630 syscallarg(pid_t) pid; 631 syscallarg(const netbsd32_siginfop_t) info; 632 } */ 633 struct __ksiginfo32 ksi32; 634 ksiginfo_t ksi; 635 int error; 636 637 if ((error = copyin(SCARG_P32(uap, info), &ksi32, 638 sizeof(ksi32))) != 0) 639 return error; 640 641 KSI_INIT(&ksi); 642 netbsd32_ksi32_to_ksi(&ksi.ksi_info, &ksi32); 643 644 return kill1(l, SCARG(uap, pid), &ksi, retval); 645 } 646 647 struct netbsd32_ktr_psig { 648 int signo; 649 netbsd32_pointer_t action; 650 sigset_t mask; 651 int code; 652 /* and optional siginfo_t */ 653 }; 654 655 #ifdef notyet 656 #ifdef KTRACE 657 void 658 netbsd32_ktrpsig(int sig, sig_t action, const sigset_t *mask, 659 const ksiginfo_t *ksi) 660 { 661 struct ktrace_entry *kte; 662 lwp_t *l = curlwp; 663 struct { 664 struct netbsd32_ktr_psig kp; 665 siginfo32_t si; 666 } *kbuf; 667 668 if (!KTRPOINT(l->l_proc, KTR_PSIG)) 669 return; 670 671 if (ktealloc(&kte, (void *)&kbuf, l, KTR_PSIG, sizeof(*kbuf))) 672 return; 673 674 kbuf->kp.signo = (char)sig; 675 NETBSD32PTR32(kbuf->kp.action, action); 676 kbuf->kp.mask = *mask; 677 678 if (ksi) { 679 kbuf->kp.code = KSI_TRAPCODE(ksi); 680 (void)memset(&kbuf->si, 0, sizeof(kbuf->si)); 681 netbsd32_ksi_to_ksi32(&kbuf->si._info, &ksi->ksi_info); 682 ktesethdrlen(kte, sizeof(*kbuf)); 683 } else { 684 kbuf->kp.code = 0; 685 ktesethdrlen(kte, sizeof(struct netbsd32_ktr_psig)); 686 } 687 688 ktraddentry(l, kte, KTA_WAITOK); 689 } 690 #endif 691 #endif 692