184 lines
5.6 KiB
C
184 lines
5.6 KiB
C
/* $NetBSD: sunos_machdep.c,v 1.7 1998/09/17 02:30:02 thorpej Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1995 Matthew R. Green
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/proc.h>
|
|
#include <sys/user.h>
|
|
#include <sys/kernel.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/signal.h>
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/syscallargs.h>
|
|
#include <compat/sunos/sunos.h>
|
|
#include <compat/sunos/sunos_syscallargs.h>
|
|
|
|
#include <machine/frame.h>
|
|
#include <machine/cpu.h>
|
|
|
|
#ifdef DEBUG
|
|
int sunos_sigdebug = 0;
|
|
int sunos_sigpid = 0;
|
|
#define SDB_FOLLOW 0x01
|
|
#define SDB_KSTACK 0x02
|
|
#define SDB_FPSTATE 0x04
|
|
#endif
|
|
|
|
struct sunos_sigframe {
|
|
int sf_signo; /* signal number */
|
|
int sf_code; /* code */
|
|
struct sigcontext13 *sf_scp; /* SunOS user addr of sigcontext */
|
|
int sf_addr; /* SunOS compat, always 0 for now */
|
|
struct sigcontext13 sf_sc; /* actual sigcontext */
|
|
};
|
|
|
|
void
|
|
sunos_sendsig(catcher, sig, mask, code)
|
|
sig_t catcher;
|
|
int sig;
|
|
sigset_t *mask;
|
|
u_long code;
|
|
{
|
|
struct proc *p = curproc;
|
|
struct sigacts *psp = p->p_sigacts;
|
|
struct sunos_sigframe *fp;
|
|
struct trapframe *tf;
|
|
int addr, onstack, oldsp, newsp;
|
|
struct sunos_sigframe sf;
|
|
|
|
tf = p->p_md.md_tf;
|
|
oldsp = tf->tf_out[6];
|
|
|
|
/*
|
|
* Compute new user stack addresses, subtract off
|
|
* one signal frame, and align.
|
|
*/
|
|
onstack =
|
|
(psp->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
|
|
(psp->ps_sigact[sig].sa_flags & SA_ONSTACK) != 0;
|
|
|
|
if (onstack)
|
|
fp = (struct sunos_sigframe *)
|
|
((caddr_t)psp->ps_sigstk.ss_sp + psp->ps_sigstk.ss_size);
|
|
else
|
|
fp = (struct sunos_sigframe *)oldsp;
|
|
|
|
fp = (struct sunos_sigframe *)((int)(fp - 1) & ~7);
|
|
|
|
#ifdef DEBUG
|
|
if ((sunos_sigdebug & SDB_KSTACK) && p->p_pid == sunos_sigpid)
|
|
printf("sendsig: %s[%d] sig %d newusp %p scp %p\n",
|
|
p->p_comm, p->p_pid, sig, fp, &fp->sf_sc);
|
|
#endif
|
|
/*
|
|
* Now set up the signal frame. We build it in kernel space
|
|
* and then copy it out. We probably ought to just build it
|
|
* directly in user space....
|
|
*/
|
|
sf.sf_signo = sig;
|
|
sf.sf_code = code;
|
|
sf.sf_scp = &fp->sf_sc;
|
|
sf.sf_addr = 0; /* XXX */
|
|
|
|
/*
|
|
* Build the signal context to be used by sigreturn.
|
|
*/
|
|
sf.sf_sc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
|
|
native_sigset_to_sigset13(mask, &sf.sf_sc.sc_mask);
|
|
sf.sf_sc.sc_sp = oldsp;
|
|
sf.sf_sc.sc_pc = tf->tf_pc;
|
|
sf.sf_sc.sc_npc = tf->tf_npc;
|
|
sf.sf_sc.sc_psr = tf->tf_psr;
|
|
sf.sf_sc.sc_g1 = tf->tf_global[1];
|
|
sf.sf_sc.sc_o0 = tf->tf_out[0];
|
|
|
|
/*
|
|
* Put the stack in a consistent state before we whack away
|
|
* at it. Note that write_user_windows may just dump the
|
|
* registers into the pcb; we need them in the process's memory.
|
|
* We also need to make sure that when we start the signal handler,
|
|
* its %i6 (%fp), which is loaded from the newly allocated stack area,
|
|
* joins seamlessly with the frame it was in when the signal occurred,
|
|
* so that the debugger and _longjmp code can back up through it.
|
|
*/
|
|
newsp = (int)fp - sizeof(struct rwindow);
|
|
write_user_windows();
|
|
if (rwindow_save(p) || copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf) ||
|
|
suword(&((struct rwindow *)newsp)->rw_in[6], oldsp)) {
|
|
/*
|
|
* Process has trashed its stack; give it an illegal
|
|
* instruction to halt it in its tracks.
|
|
*/
|
|
#ifdef DEBUG
|
|
if ((sunos_sigdebug & SDB_KSTACK) && p->p_pid == sunos_sigpid)
|
|
printf("sendsig: window save or copyout error\n");
|
|
#endif
|
|
sigexit(p, SIGILL);
|
|
/* NOTREACHED */
|
|
}
|
|
#ifdef DEBUG
|
|
if (sunos_sigdebug & SDB_FOLLOW)
|
|
printf("sendsig: %s[%d] sig %d scp %p\n",
|
|
p->p_comm, p->p_pid, sig, &fp->sf_sc);
|
|
#endif
|
|
/*
|
|
* Arrange to continue execution at the code copied out in exec().
|
|
* It needs the function to call in %g1, and a new stack pointer.
|
|
*/
|
|
addr = (int)catcher; /* user does his own trampolining */
|
|
tf->tf_pc = addr;
|
|
tf->tf_npc = addr + 4;
|
|
tf->tf_out[6] = newsp;
|
|
|
|
/* Remember that we're now on the signal stack. */
|
|
if (onstack)
|
|
psp->ps_sigstk.ss_flags |= SS_ONSTACK;
|
|
|
|
#ifdef DEBUG
|
|
if ((sunos_sigdebug & SDB_KSTACK) && p->p_pid == sunos_sigpid)
|
|
printf("sendsig: about to return to catcher\n");
|
|
#endif
|
|
}
|
|
|
|
int
|
|
sunos_sys_sigreturn(p, v, retval)
|
|
register struct proc *p;
|
|
void *v;
|
|
register_t *retval;
|
|
{
|
|
struct sunos_sys_sigreturn_args *uap = v;
|
|
|
|
return (compat_13_sys_sigreturn(p,
|
|
(struct compat_13_sys_sigreturn_args *)uap, retval));
|
|
}
|