1 /* $NetBSD: compat_13_machdep.c,v 1.19 2021/02/01 19:31:34 skrll Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1998 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * This code is derived from software written for Brini by Mark Brinicombe 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by Mark Brinicombe 21 * for the NetBSD Project. 22 * 4. The name of the company nor the name of the author may be used to 23 * endorse or promote products derived from this software without specific 24 * prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 41 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.19 2021/02/01 19:31:34 skrll Exp $"); 42 43 #include <sys/systm.h> 44 #include <sys/signalvar.h> 45 #include <sys/kernel.h> 46 #include <sys/proc.h> 47 #include <sys/mount.h> 48 #include <sys/syscallargs.h> 49 50 #include <compat/sys/signal.h> 51 #include <compat/sys/signalvar.h> 52 53 #include <arm/locore.h> 54 55 int 56 compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval) 57 { 58 /* { 59 syscallarg(struct sigcontext13 *) sigcntxp; 60 } */ 61 struct sigcontext13 *scp, context; 62 struct trapframe * const tf = lwp_trapframe(l); 63 struct proc * const p = l->l_proc; 64 sigset_t mask; 65 66 /* 67 * The trampoline code hands us the context. 68 * It is unsafe to keep track of it ourselves, in the event that a 69 * program jumps out of a signal handler. 70 */ 71 scp = SCARG(uap, sigcntxp); 72 if (copyin((void *)scp, &context, sizeof(*scp)) != 0) 73 return (EFAULT); 74 75 /* 76 * Make sure the processor mode has not been tampered with and 77 * interrupts have not been disabled. 78 */ 79 if (!VALID_PSR(context.sc_spsr)) 80 return EINVAL; 81 82 /* Restore register context. */ 83 tf->tf_r0 = context.sc_r0; 84 tf->tf_r1 = context.sc_r1; 85 tf->tf_r2 = context.sc_r2; 86 tf->tf_r3 = context.sc_r3; 87 tf->tf_r4 = context.sc_r4; 88 tf->tf_r5 = context.sc_r5; 89 tf->tf_r6 = context.sc_r6; 90 tf->tf_r7 = context.sc_r7; 91 tf->tf_r8 = context.sc_r8; 92 tf->tf_r9 = context.sc_r9; 93 tf->tf_r10 = context.sc_r10; 94 tf->tf_r11 = context.sc_r11; 95 tf->tf_r12 = context.sc_r12; 96 tf->tf_usr_sp = context.sc_usr_sp; 97 tf->tf_usr_lr = context.sc_usr_lr; 98 tf->tf_svc_lr = context.sc_svc_lr; 99 tf->tf_pc = context.sc_pc; 100 tf->tf_spsr = context.sc_spsr; 101 102 mutex_enter(p->p_lock); 103 104 /* Restore signal stack. */ 105 if (context.sc_onstack & SS_ONSTACK) 106 l->l_sigstk.ss_flags |= SS_ONSTACK; 107 else 108 l->l_sigstk.ss_flags &= ~SS_ONSTACK; 109 110 /* Restore signal mask. */ 111 native_sigset13_to_sigset(&context.sc_mask, &mask); 112 (void) sigprocmask1(l, SIG_SETMASK, &mask, 0); 113 114 mutex_exit(p->p_lock); 115 116 return (EJUSTRETURN); 117 } 118