1 1.28 thorpej /* $NetBSD: sig_machdep.c,v 1.28 2021/10/27 04:14:59 thorpej Exp $ */ 2 1.1 fredette 3 1.1 fredette /*- 4 1.1 fredette * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 1.1 fredette * All rights reserved. 6 1.1 fredette * 7 1.1 fredette * This code is derived from software contributed to The NetBSD Foundation 8 1.1 fredette * by Matthew Fredette. 9 1.1 fredette * 10 1.1 fredette * Redistribution and use in source and binary forms, with or without 11 1.1 fredette * modification, are permitted provided that the following conditions 12 1.1 fredette * are met: 13 1.1 fredette * 1. Redistributions of source code must retain the above copyright 14 1.1 fredette * notice, this list of conditions and the following disclaimer. 15 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 fredette * notice, this list of conditions and the following disclaimer in the 17 1.1 fredette * documentation and/or other materials provided with the distribution. 18 1.1 fredette * 19 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 fredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 fredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 fredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 fredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 fredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 fredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 fredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 fredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 fredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 fredette * POSSIBILITY OF SUCH DAMAGE. 30 1.1 fredette */ 31 1.1 fredette 32 1.1 fredette /* 33 1.25 rmind * Copyright (c) 1988 University of Utah. 34 1.1 fredette * Copyright (c) 1982, 1986, 1990, 1993 35 1.1 fredette * The Regents of the University of California. All rights reserved. 36 1.1 fredette * 37 1.1 fredette * This code is derived from software contributed to Berkeley by 38 1.1 fredette * the Systems Programming Group of the University of Utah Computer 39 1.1 fredette * Science Department. 40 1.1 fredette * 41 1.1 fredette * Redistribution and use in source and binary forms, with or without 42 1.1 fredette * modification, are permitted provided that the following conditions 43 1.1 fredette * are met: 44 1.1 fredette * 1. Redistributions of source code must retain the above copyright 45 1.1 fredette * notice, this list of conditions and the following disclaimer. 46 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright 47 1.1 fredette * notice, this list of conditions and the following disclaimer in the 48 1.1 fredette * documentation and/or other materials provided with the distribution. 49 1.4 agc * 3. Neither the name of the University nor the names of its contributors 50 1.4 agc * may be used to endorse or promote products derived from this software 51 1.4 agc * without specific prior written permission. 52 1.4 agc * 53 1.4 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 1.4 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 1.4 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 1.4 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 1.4 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 1.4 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 1.4 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 1.4 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 1.4 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 1.4 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 1.4 agc * SUCH DAMAGE. 64 1.4 agc * 65 1.4 agc * from: Utah Hdr: machdep.c 1.74 92/12/20 66 1.4 agc * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94 67 1.4 agc */ 68 1.3 lukem 69 1.3 lukem #include <sys/cdefs.h> 70 1.28 thorpej __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.28 2021/10/27 04:14:59 thorpej Exp $"); 71 1.1 fredette 72 1.1 fredette #include "opt_compat_netbsd.h" 73 1.1 fredette 74 1.1 fredette #include <sys/param.h> 75 1.1 fredette #include <sys/systm.h> 76 1.1 fredette #include <sys/kernel.h> 77 1.1 fredette #include <sys/proc.h> 78 1.1 fredette #include <sys/signal.h> 79 1.1 fredette #include <sys/signalvar.h> 80 1.1 fredette 81 1.1 fredette #include <sys/mount.h> 82 1.1 fredette #include <sys/syscallargs.h> 83 1.1 fredette 84 1.1 fredette #include <machine/cpu.h> 85 1.24 rmind #include <machine/pcb.h> 86 1.1 fredette #include <machine/reg.h> 87 1.10 chs #include <machine/frame.h> 88 1.1 fredette 89 1.1 fredette #ifdef DEBUG 90 1.9 chs int sigdebug = 0; 91 1.1 fredette int sigpid = 0; 92 1.1 fredette #define SDB_FOLLOW 0x01 93 1.1 fredette #define SDB_KSTACK 0x02 94 1.1 fredette #define SDB_FPSTATE 0x04 95 1.1 fredette #endif 96 1.1 fredette 97 1.12 chs static void *getframe(struct lwp *, int, int *); 98 1.12 chs static void * 99 1.10 chs getframe(struct lwp *l, int sig, int *onstack) 100 1.10 chs { 101 1.10 chs struct proc *p = l->l_proc; 102 1.10 chs struct trapframe *tf = l->l_md.md_regs; 103 1.27 skrll 104 1.10 chs /* Do we need to jump onto the signal stack? */ 105 1.15 ad *onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 106 1.10 chs && (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; 107 1.10 chs if (*onstack) 108 1.19 skrll return (void *)HPPA_FRAME_ROUND(l->l_sigstk.ss_sp); 109 1.10 chs else 110 1.19 skrll return (void *)HPPA_FRAME_ROUND(tf->tf_sp); 111 1.10 chs } 112 1.10 chs 113 1.10 chs struct sigframe_siginfo { 114 1.10 chs siginfo_t sf_si; 115 1.10 chs ucontext_t sf_uc; 116 1.10 chs }; 117 1.10 chs 118 1.10 chs void 119 1.22 he sendsig_siginfo(const struct ksiginfo *ksi, const sigset_t *mask) 120 1.10 chs { 121 1.10 chs struct lwp *l = curlwp; 122 1.10 chs struct proc *p = l->l_proc; 123 1.23 rmind struct pcb *pcb = lwp_getpcb(l); 124 1.10 chs struct sigacts *ps = p->p_sigacts; 125 1.10 chs struct sigframe_siginfo *fp, frame; 126 1.10 chs struct trapframe *tf; 127 1.10 chs int sig = ksi->ksi_signo; 128 1.10 chs sig_t catcher = SIGACTION(p, sig).sa_handler; 129 1.15 ad int onstack, error; 130 1.10 chs 131 1.10 chs fp = getframe(l, sig, &onstack); 132 1.10 chs tf = (struct trapframe *)l->l_md.md_regs; 133 1.10 chs 134 1.10 chs /* Build stack frame for signal trampoline. */ 135 1.10 chs switch (ps->sa_sigdesc[sig].sd_vers) { 136 1.10 chs default: 137 1.10 chs printf("sendsig_siginfo: bad version %d\n", 138 1.10 chs ps->sa_sigdesc[sig].sd_vers); 139 1.10 chs sigexit(l, SIGILL); 140 1.28 thorpej case __SIGTRAMP_SIGINFO_VERSION: 141 1.10 chs break; 142 1.10 chs } 143 1.10 chs 144 1.26 maxv memset(&frame, 0, sizeof(frame)); 145 1.11 chs frame.sf_si._info = ksi->ksi_info; 146 1.10 chs frame.sf_uc.uc_flags = _UC_SIGMASK | 147 1.15 ad ((l->l_sigstk.ss_flags & SS_ONSTACK) ? 148 1.10 chs _UC_SETSTACK : _UC_CLRSTACK); 149 1.10 chs frame.sf_uc.uc_sigmask = *mask; 150 1.16 pooka frame.sf_uc.uc_link = l->l_ctxlink; 151 1.15 ad sendsig_reset(l, sig); 152 1.20 ad mutex_exit(p->p_lock); 153 1.10 chs cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags); 154 1.15 ad error = copyout(&frame, fp, sizeof(frame)); 155 1.20 ad mutex_enter(p->p_lock); 156 1.10 chs 157 1.15 ad if (error != 0) { 158 1.10 chs 159 1.10 chs /* 160 1.10 chs * Process has trashed its stack; give it an illegal 161 1.10 chs * instruction to halt it in its tracks. 162 1.10 chs */ 163 1.10 chs sigexit(l, SIGILL); 164 1.10 chs /* NOTREACHED */ 165 1.10 chs } 166 1.10 chs 167 1.10 chs /* 168 1.10 chs * Set up the registers to invoke the signal trampoline. 169 1.10 chs */ 170 1.10 chs tf->tf_arg0 = sig; 171 1.10 chs tf->tf_arg1 = (__greg_t)&fp->sf_si; 172 1.10 chs tf->tf_arg2 = (__greg_t)&fp->sf_uc; 173 1.10 chs tf->tf_r3 = (__greg_t)&fp->sf_uc; 174 1.10 chs 175 1.19 skrll fp++; 176 1.23 rmind tf->tf_iisq_head = tf->tf_iisq_tail = pcb->pcb_space; 177 1.10 chs tf->tf_iioq_head = 178 1.10 chs (__greg_t)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER; 179 1.10 chs tf->tf_iioq_tail = tf->tf_iioq_head + 4; 180 1.10 chs tf->tf_arg3 = (__greg_t)catcher; 181 1.19 skrll tf->tf_sp = HPPA_FRAME_ROUND(fp); 182 1.10 chs 183 1.10 chs /* Remember that we're now on the signal stack. */ 184 1.10 chs if (onstack) 185 1.15 ad l->l_sigstk.ss_flags |= SS_ONSTACK; 186 1.10 chs } 187