compat_13_machdep.c revision 1.15
11.15Schristos/*	$NetBSD: compat_13_machdep.c,v 1.15 2005/09/13 03:23:34 christos 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 * 3. All advertising materials mentioning features or use of this software
201.1Sthorpej *    must display the following acknowledgement:
211.1Sthorpej *	This product includes software developed by the NetBSD
221.1Sthorpej *	Foundation, Inc. and its contributors.
231.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
241.1Sthorpej *    contributors may be used to endorse or promote products derived
251.1Sthorpej *    from this software without specific prior written permission.
261.1Sthorpej *
271.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
291.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301.1Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
311.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
331.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371.1Sthorpej * POSSIBILITY OF SUCH DAMAGE.
381.1Sthorpej */
391.14Slukem
401.14Slukem#include <sys/cdefs.h>
411.15Schristos__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.15 2005/09/13 03:23:34 christos Exp $");
421.7Smrg
431.7Smrg#include "opt_ddb.h"
441.1Sthorpej
451.1Sthorpej#include <sys/param.h>
461.1Sthorpej#include <sys/systm.h>
471.1Sthorpej#include <sys/proc.h>
481.1Sthorpej#include <sys/user.h>
491.1Sthorpej#include <sys/kernel.h>
501.1Sthorpej#include <sys/mount.h>
511.1Sthorpej#include <sys/signal.h>
521.1Sthorpej#include <sys/signalvar.h>
531.1Sthorpej
541.13Sthorpej#include <sys/sa.h>
551.1Sthorpej#include <sys/syscallargs.h>
561.5Seeh#include <sparc64/sparc64/sigdebug.h>
571.1Sthorpej
581.15Schristos#include <compat/sys/signal.h>
591.15Schristos#include <compat/sys/signalvar.h>
601.1Sthorpej/*
611.1Sthorpej * System call to cleanup state after a signal
621.1Sthorpej * has been taken.  Reset signal mask and
631.1Sthorpej * stack state from context left by sendsig (above),
641.1Sthorpej * and return to the given trap frame (if there is one).
651.1Sthorpej * Check carefully to make sure that the user has not
661.1Sthorpej * modified the state to gain improper privileges or to cause
671.1Sthorpej * a machine fault.
681.1Sthorpej */
691.1Sthorpej/* ARGSUSED */
701.1Sthorpejint
711.13Sthorpejcompat_13_sys_sigreturn(l, v, retval)
721.13Sthorpej	struct lwp *l;
731.1Sthorpej	void *v;
741.1Sthorpej	register_t *retval;
751.1Sthorpej{
761.1Sthorpej	struct compat_13_sys_sigreturn_args /* {
771.1Sthorpej		syscallarg(struct sigcontext13 *) sigcntxp;
781.1Sthorpej	} */ *uap = v;
791.13Sthorpej	struct proc *p = l->l_proc;
801.1Sthorpej	struct sigcontext13 sc, *scp;
811.13Sthorpej	struct trapframe64 *tf;
821.1Sthorpej	sigset_t mask;
831.1Sthorpej
841.1Sthorpej	/* First ensure consistent stack state (see sendsig). */
851.1Sthorpej	write_user_windows();
861.13Sthorpej	if (rwindow_save(l)) {
871.5Seeh#ifdef DEBUG
881.13Sthorpej		printf("compat_13_sys_sigreturn: rwindow_save(%p) failed, sending SIGILL\n", l);
891.8Spk#ifdef DDB
901.5Seeh		Debugger();
911.5Seeh#endif
921.8Spk#endif
931.13Sthorpej		sigexit(l, SIGILL);
941.5Seeh	}
951.5Seeh#ifdef DEBUG
961.5Seeh	if (sigdebug & SDB_FOLLOW) {
971.5Seeh		printf("compat_13_sys_sigreturn: %s[%d], sigcntxp %p\n",
981.5Seeh		    p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
991.8Spk#ifdef DDB
1001.5Seeh		if (sigdebug & SDB_DDB) Debugger();
1011.8Spk#endif
1021.5Seeh	}
1031.5Seeh#endif
1041.1Sthorpej
1051.1Sthorpej	scp = SCARG(uap, sigcntxp);
1061.2Seeh	if ((vaddr_t)scp & 3 || (copyin((caddr_t)scp, &sc, sizeof sc) != 0))
1071.5Seeh#ifdef DEBUG
1081.5Seeh	{
1091.5Seeh		printf("compat_13_sys_sigreturn: copyin failed: scp=%p\n", scp);
1101.8Spk#ifdef DDB
1111.5Seeh		Debugger();
1121.8Spk#endif
1131.1Sthorpej		return (EFAULT);
1141.5Seeh	}
1151.5Seeh#else
1161.5Seeh		return (EFAULT);
1171.5Seeh#endif
1181.5Seeh
1191.1Sthorpej	scp = &sc;
1201.1Sthorpej
1211.13Sthorpej	tf = l->l_md.md_tf;
1221.1Sthorpej	/*
1231.1Sthorpej	 * Only the icc bits in the psr are used, so it need not be
1241.1Sthorpej	 * verified.  pc and npc must be multiples of 4.  This is all
1251.1Sthorpej	 * that is required; if it holds, just do it.
1261.1Sthorpej	 */
1271.3Seeh	if (((scp->sc_pc | scp->sc_npc) & 3) != 0 || scp->sc_pc == 0 || scp->sc_npc == 0)
1281.3Seeh#ifdef DEBUG
1291.3Seeh	{
1301.12Seeh		printf("compat_13_sys_sigreturn: pc %p or npc %p invalid\n",
1311.12Seeh			(void *)scp->sc_pc, (void *)scp->sc_npc);
1321.8Spk#ifdef DDB
1331.3Seeh		Debugger();
1341.8Spk#endif
1351.3Seeh		return (EINVAL);
1361.3Seeh	}
1371.3Seeh#endif
1381.1Sthorpej		return (EINVAL);
1391.1Sthorpej	/* take only psr ICC field */
1401.4Smrg#ifdef __arch64__
1411.2Seeh	tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | scp->sc_tstate;
1421.2Seeh#else
1431.1Sthorpej	tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(scp->sc_psr);
1441.2Seeh#endif
1451.1Sthorpej	tf->tf_pc = scp->sc_pc;
1461.1Sthorpej	tf->tf_npc = scp->sc_npc;
1471.1Sthorpej	tf->tf_global[1] = scp->sc_g1;
1481.1Sthorpej	tf->tf_out[0] = scp->sc_o0;
1491.1Sthorpej	tf->tf_out[6] = scp->sc_sp;
1501.5Seeh#ifdef DEBUG
1511.5Seeh	if (sigdebug & SDB_FOLLOW) {
1521.12Seeh		printf("compat_13_sys_sigreturn: return trapframe pc=%llx sp=%llx tstate=%llx\n",
1531.12Seeh			(long long)tf->tf_pc, (long long)tf->tf_out[6],
1541.12Seeh			(long long)tf->tf_tstate);
1551.8Spk#ifdef DDB
1561.5Seeh		if (sigdebug & SDB_DDB) Debugger();
1571.8Spk#endif
1581.5Seeh	}
1591.5Seeh#endif
1601.1Sthorpej
1611.1Sthorpej	if (scp->sc_onstack & SS_ONSTACK)
1621.11Sjdolecek		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
1631.1Sthorpej	else
1641.11Sjdolecek		p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
1651.1Sthorpej
1661.1Sthorpej	/* Restore signal mask */
1671.1Sthorpej	native_sigset13_to_sigset(&scp->sc_mask, &mask);
1681.1Sthorpej	(void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
1691.1Sthorpej
1701.1Sthorpej	return (EJUSTRETURN);
1711.1Sthorpej}
172