compat_13_machdep.c revision 1.7
11.7Smrg/*	$NetBSD: compat_13_machdep.c,v 1.7 2000/04/06 12:17:27 mrg 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.7Smrg
401.7Smrg#include "opt_ddb.h"
411.1Sthorpej
421.1Sthorpej#include <sys/param.h>
431.1Sthorpej#include <sys/systm.h>
441.1Sthorpej#include <sys/proc.h>
451.1Sthorpej#include <sys/user.h>
461.1Sthorpej#include <sys/kernel.h>
471.1Sthorpej#include <sys/mount.h>
481.1Sthorpej#include <sys/signal.h>
491.1Sthorpej#include <sys/signalvar.h>
501.1Sthorpej
511.1Sthorpej#include <sys/syscallargs.h>
521.5Seeh#include <sparc64/sparc64/sigdebug.h>
531.1Sthorpej
541.1Sthorpej/*
551.1Sthorpej * System call to cleanup state after a signal
561.1Sthorpej * has been taken.  Reset signal mask and
571.1Sthorpej * stack state from context left by sendsig (above),
581.1Sthorpej * and return to the given trap frame (if there is one).
591.1Sthorpej * Check carefully to make sure that the user has not
601.1Sthorpej * modified the state to gain improper privileges or to cause
611.1Sthorpej * a machine fault.
621.1Sthorpej */
631.1Sthorpej/* ARGSUSED */
641.1Sthorpejint
651.1Sthorpejcompat_13_sys_sigreturn(p, v, retval)
661.1Sthorpej	struct proc *p;
671.1Sthorpej	void *v;
681.1Sthorpej	register_t *retval;
691.1Sthorpej{
701.1Sthorpej	struct compat_13_sys_sigreturn_args /* {
711.1Sthorpej		syscallarg(struct sigcontext13 *) sigcntxp;
721.1Sthorpej	} */ *uap = v;
731.1Sthorpej	struct sigcontext13 sc, *scp;
741.1Sthorpej	sigset_t mask;
751.6Seeh	struct trapframe64 *tf;
761.1Sthorpej
771.1Sthorpej	/* First ensure consistent stack state (see sendsig). */
781.1Sthorpej	write_user_windows();
791.1Sthorpej#if 0
801.1Sthorpej	/* Make sure our D$ is not polluted w/bad data */
811.1Sthorpej	blast_vcache();
821.1Sthorpej#endif
831.5Seeh	if (rwindow_save(p)) {
841.5Seeh#ifdef DEBUG
851.5Seeh		printf("compat_13_sys_sigreturn: rwindow_save(%p) failed, sending SIGILL\n", p);
861.5Seeh		Debugger();
871.5Seeh#endif
881.1Sthorpej		sigexit(p, SIGILL);
891.5Seeh	}
901.5Seeh#ifdef DEBUG
911.5Seeh	if (sigdebug & SDB_FOLLOW) {
921.5Seeh		printf("compat_13_sys_sigreturn: %s[%d], sigcntxp %p\n",
931.5Seeh		    p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
941.5Seeh		if (sigdebug & SDB_DDB) Debugger();
951.5Seeh	}
961.5Seeh#endif
971.1Sthorpej
981.1Sthorpej	scp = SCARG(uap, sigcntxp);
991.2Seeh	if ((vaddr_t)scp & 3 || (copyin((caddr_t)scp, &sc, sizeof sc) != 0))
1001.5Seeh#ifdef DEBUG
1011.5Seeh	{
1021.5Seeh		printf("compat_13_sys_sigreturn: copyin failed: scp=%p\n", scp);
1031.5Seeh		Debugger();
1041.1Sthorpej		return (EFAULT);
1051.5Seeh	}
1061.5Seeh#else
1071.5Seeh		return (EFAULT);
1081.5Seeh#endif
1091.5Seeh
1101.1Sthorpej	scp = &sc;
1111.1Sthorpej
1121.1Sthorpej	tf = p->p_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.5Seeh		printf("compat_13_sys_sigreturn: pc %p or npc %p invalid\n", scp->sc_pc, scp->sc_npc);
1221.3Seeh		Debugger();
1231.3Seeh		return (EINVAL);
1241.3Seeh	}
1251.3Seeh#endif
1261.1Sthorpej		return (EINVAL);
1271.1Sthorpej	/* take only psr ICC field */
1281.4Smrg#ifdef __arch64__
1291.2Seeh	tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | scp->sc_tstate;
1301.2Seeh#else
1311.1Sthorpej	tf->tf_tstate = (int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(scp->sc_psr);
1321.2Seeh#endif
1331.1Sthorpej	tf->tf_pc = scp->sc_pc;
1341.1Sthorpej	tf->tf_npc = scp->sc_npc;
1351.1Sthorpej	tf->tf_global[1] = scp->sc_g1;
1361.1Sthorpej	tf->tf_out[0] = scp->sc_o0;
1371.1Sthorpej	tf->tf_out[6] = scp->sc_sp;
1381.5Seeh#ifdef DEBUG
1391.5Seeh	if (sigdebug & SDB_FOLLOW) {
1401.5Seeh		printf("compat_13_sys_sigreturn: return trapframe pc=%p sp=%p tstate=%llx\n",
1411.5Seeh		       (vaddr_t)tf->tf_pc, (vaddr_t)tf->tf_out[6], tf->tf_tstate);
1421.5Seeh		if (sigdebug & SDB_DDB) Debugger();
1431.5Seeh	}
1441.5Seeh#endif
1451.1Sthorpej
1461.1Sthorpej	if (scp->sc_onstack & SS_ONSTACK)
1471.1Sthorpej		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
1481.1Sthorpej	else
1491.1Sthorpej		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
1501.1Sthorpej
1511.1Sthorpej	/* Restore signal mask */
1521.1Sthorpej	native_sigset13_to_sigset(&scp->sc_mask, &mask);
1531.1Sthorpej	(void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
1541.1Sthorpej
1551.1Sthorpej	return (EJUSTRETURN);
1561.1Sthorpej}
157