11.24Smaxv/* $NetBSD: compat_13_machdep.c,v 1.24 2017/08/22 09:12:49 maxv Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.1Sthorpej * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 81.1Sthorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 91.1Sthorpej * NASA Ames Research Center. 101.1Sthorpej * 111.1Sthorpej * Redistribution and use in source and binary forms, with or without 121.1Sthorpej * modification, are permitted provided that the following conditions 131.1Sthorpej * are met: 141.1Sthorpej * 1. Redistributions of source code must retain the above copyright 151.1Sthorpej * notice, this list of conditions and the following disclaimer. 161.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 171.1Sthorpej * notice, this list of conditions and the following disclaimer in the 181.1Sthorpej * documentation and/or other materials provided with the distribution. 191.1Sthorpej * 201.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 211.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 221.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 231.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 241.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 261.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 271.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 281.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 291.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 311.1Sthorpej */ 321.14Slukem 331.14Slukem#include <sys/cdefs.h> 341.24Smaxv__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.24 2017/08/22 09:12:49 maxv Exp $"); 351.7Smrg 361.22Snakayama#ifdef _KERNEL_OPT 371.7Smrg#include "opt_ddb.h" 381.22Snakayama#endif 391.1Sthorpej 401.1Sthorpej#include <sys/param.h> 411.1Sthorpej#include <sys/systm.h> 421.1Sthorpej#include <sys/proc.h> 431.1Sthorpej#include <sys/kernel.h> 441.1Sthorpej#include <sys/mount.h> 451.1Sthorpej#include <sys/signal.h> 461.1Sthorpej#include <sys/signalvar.h> 471.1Sthorpej 481.1Sthorpej#include <sys/syscallargs.h> 491.5Seeh#include <sparc64/sparc64/sigdebug.h> 501.1Sthorpej 511.15Schristos#include <compat/sys/signal.h> 521.15Schristos#include <compat/sys/signalvar.h> 531.1Sthorpej/* 541.1Sthorpej * System call to cleanup state after a signal 551.1Sthorpej * has been taken. Reset signal mask and 561.1Sthorpej * stack state from context left by sendsig (above), 571.1Sthorpej * and return to the given trap frame (if there is one). 581.1Sthorpej * Check carefully to make sure that the user has not 591.1Sthorpej * modified the state to gain improper privileges or to cause 601.1Sthorpej * a machine fault. 611.1Sthorpej */ 621.1Sthorpej/* ARGSUSED */ 631.1Sthorpejint 641.19Sdslcompat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval) 651.1Sthorpej{ 661.19Sdsl /* { 671.1Sthorpej syscallarg(struct sigcontext13 *) sigcntxp; 681.19Sdsl } */ 691.1Sthorpej struct sigcontext13 sc, *scp; 701.13Sthorpej struct trapframe64 *tf; 711.17Sad struct proc *p = l->l_proc; 721.1Sthorpej sigset_t mask; 731.1Sthorpej 741.1Sthorpej /* First ensure consistent stack state (see sendsig). */ 751.1Sthorpej write_user_windows(); 761.13Sthorpej if (rwindow_save(l)) { 771.5Seeh#ifdef DEBUG 781.13Sthorpej printf("compat_13_sys_sigreturn: rwindow_save(%p) failed, sending SIGILL\n", l); 791.8Spk#ifdef DDB 801.5Seeh Debugger(); 811.5Seeh#endif 821.8Spk#endif 831.20Sad mutex_enter(p->p_lock); 841.13Sthorpej sigexit(l, SIGILL); 851.5Seeh } 861.5Seeh#ifdef DEBUG 871.5Seeh if (sigdebug & SDB_FOLLOW) { 881.5Seeh printf("compat_13_sys_sigreturn: %s[%d], sigcntxp %p\n", 891.5Seeh p->p_comm, p->p_pid, SCARG(uap, sigcntxp)); 901.8Spk#ifdef DDB 911.5Seeh if (sigdebug & SDB_DDB) Debugger(); 921.8Spk#endif 931.5Seeh } 941.5Seeh#endif 951.1Sthorpej 961.1Sthorpej scp = SCARG(uap, sigcntxp); 971.18Schristos if ((vaddr_t)scp & 3 || (copyin((void *)scp, &sc, sizeof sc) != 0)) 981.5Seeh#ifdef DEBUG 991.5Seeh { 1001.5Seeh printf("compat_13_sys_sigreturn: copyin failed: scp=%p\n", scp); 1011.8Spk#ifdef DDB 1021.5Seeh Debugger(); 1031.8Spk#endif 1041.1Sthorpej return (EFAULT); 1051.5Seeh } 1061.5Seeh#else 1071.5Seeh return (EFAULT); 1081.5Seeh#endif 1091.5Seeh 1101.1Sthorpej scp = ≻ 1111.1Sthorpej 1121.13Sthorpej tf = l->l_md.md_tf; 1131.1Sthorpej /* 1141.1Sthorpej * Only the icc bits in the psr are used, so it need not be 1151.1Sthorpej * verified. pc and npc must be multiples of 4. This is all 1161.1Sthorpej * that is required; if it holds, just do it. 1171.1Sthorpej */ 1181.3Seeh if (((scp->sc_pc | scp->sc_npc) & 3) != 0 || scp->sc_pc == 0 || scp->sc_npc == 0) 1191.3Seeh#ifdef DEBUG 1201.3Seeh { 1211.12Seeh printf("compat_13_sys_sigreturn: pc %p or npc %p invalid\n", 1221.12Seeh (void *)scp->sc_pc, (void *)scp->sc_npc); 1231.8Spk#ifdef DDB 1241.3Seeh Debugger(); 1251.8Spk#endif 1261.3Seeh return (EINVAL); 1271.3Seeh } 1281.3Seeh#endif 1291.1Sthorpej return (EINVAL); 1301.1Sthorpej /* take only psr ICC field */ 1311.4Smrg#ifdef __arch64__ 1321.24Smaxv tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | (scp->sc_tstate & TSTATE_CCR); 1331.2Seeh#else 1341.1Sthorpej tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(scp->sc_psr); 1351.2Seeh#endif 1361.1Sthorpej tf->tf_pc = scp->sc_pc; 1371.1Sthorpej tf->tf_npc = scp->sc_npc; 1381.1Sthorpej tf->tf_global[1] = scp->sc_g1; 1391.1Sthorpej tf->tf_out[0] = scp->sc_o0; 1401.1Sthorpej tf->tf_out[6] = scp->sc_sp; 1411.5Seeh#ifdef DEBUG 1421.5Seeh if (sigdebug & SDB_FOLLOW) { 1431.12Seeh printf("compat_13_sys_sigreturn: return trapframe pc=%llx sp=%llx tstate=%llx\n", 1441.12Seeh (long long)tf->tf_pc, (long long)tf->tf_out[6], 1451.12Seeh (long long)tf->tf_tstate); 1461.8Spk#ifdef DDB 1471.5Seeh if (sigdebug & SDB_DDB) Debugger(); 1481.8Spk#endif 1491.5Seeh } 1501.5Seeh#endif 1511.1Sthorpej 1521.20Sad mutex_enter(p->p_lock); 1531.1Sthorpej if (scp->sc_onstack & SS_ONSTACK) 1541.17Sad l->l_sigstk.ss_flags |= SS_ONSTACK; 1551.1Sthorpej else 1561.17Sad l->l_sigstk.ss_flags &= ~SS_ONSTACK; 1571.1Sthorpej 1581.1Sthorpej /* Restore signal mask */ 1591.1Sthorpej native_sigset13_to_sigset(&scp->sc_mask, &mask); 1601.17Sad (void) sigprocmask1(l, SIG_SETMASK, &mask, 0); 1611.20Sad mutex_exit(p->p_lock); 1621.1Sthorpej 1631.1Sthorpej return (EJUSTRETURN); 1641.1Sthorpej} 165