Initial siginfo support for sparc64 (untested). COMPAT_16 sigcontext signal

delivery tested.
This commit is contained in:
christos 2003-10-26 08:05:26 +00:00
parent 4e7d0870dc
commit 3d54c93f8e
8 changed files with 475 additions and 312 deletions

View File

@ -0,0 +1,355 @@
/* $NetBSD: compat_16_machdep.c,v 1.1 2003/10/26 08:05:26 christos Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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 <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.1 2003/10/26 08:05:26 christos Exp $");
#include "opt_compat_netbsd.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signal.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/mount.h>
#include <sys/sa.h>
#include <sys/syscallargs.h>
#include <machine/signal.h>
#include <machine/frame.h>
#if defined(COMPAT_16)
#ifdef DEBUG
/* See sigdebug.h */
#include <sparc64/sparc64/sigdebug.h>
int sigdebug = 0x0;
int sigpid = 0;
#endif
#ifdef __arch64__
#define STACK_OFFSET BIAS
#define CPOUTREG(l,v) copyout(&(v), (l), sizeof(v))
#undef CCFSZ
#define CCFSZ CC64FSZ
#else
#define STACK_OFFSET 0
#define CPOUTREG(l,v) copyout(&(v), (l), sizeof(v))
#endif
struct sigframe_sigcontext {
int sf_signo; /* signal number */
int sf_code; /* code */
#ifndef __arch64__
struct sigcontext *sf_scp; /* SunOS user addr of sigcontext */
int sf_addr; /* SunOS compat, always 0 for now */
#endif
struct sigcontext sf_sc; /* actual sigcontext */
};
/*
* Send an interrupt to process.
*/
void
sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
struct sigacts *ps = p->p_sigacts;
void *addr;
struct rwindow *newsp;
#ifdef NOT_DEBUG
struct rwindow tmpwin;
#endif
int onstack;
int sig = ksi->ksi_signo;
struct sigframe_sigcontext *fp = getframe(l, sig, &onstack);
struct sigframe_sigcontext sf;
sig_t catcher = SIGACTION(p, sig).sa_handler;
struct trapframe64 *tf = l->l_md.md_tf;
/* Allocate an aligned sigframe */
fp = (void *)((u_long)(fp - 1) & ~0x0f);
#ifdef DEBUG
sigpid = p->p_pid;
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) {
printf("sendsig_sigcontext: %s[%d] sig %d newusp %p scp %p\n",
p->p_comm, p->p_pid, sig, fp, &fp->sf_sc);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#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 = ksi->ksi_trap;
#ifndef __arch64__
sf.sf_scp = 0;
sf.sf_addr = 0; /* XXX */
#endif
/*
* Build the signal context to be used by sigreturn.
*/
sf.sf_sc.sc_onstack = p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK;
sf.sf_sc.sc_mask = *mask;
#ifdef COMPAT_13
/*
* XXX We always have to save an old style signal mask because
* XXX we might be delivering a signal to a process which will
* XXX escape from the signal in a non-standard way and invoke
* XXX sigreturn() directly.
*/
native_sigset_to_sigset13(mask, &sf.sf_sc.__sc_mask13);
#endif
/* Save register context. */
sf.sf_sc.sc_sp = (long)tf->tf_out[6];
sf.sf_sc.sc_pc = tf->tf_pc;
sf.sf_sc.sc_npc = tf->tf_npc;
#ifdef __arch64__
sf.sf_sc.sc_tstate = tf->tf_tstate; /* XXX */
#else
sf.sf_sc.sc_psr = TSTATECCR_TO_PSR(tf->tf_tstate); /* XXX */
#endif
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 = (struct rwindow *)((vaddr_t)fp - sizeof(struct rwindow));
write_user_windows();
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK))
printf("sendsig: saving sf to %p, setting stack pointer %p to %p\n",
fp, &(((struct rwindow *)newsp)->rw_in[6]),
(void *)(unsigned long)tf->tf_out[6]);
#endif
if (rwindow_save(l) || copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf) ||
#ifdef NOT_DEBUG
copyin(oldsp, &tmpwin, sizeof(tmpwin)) || copyout(&tmpwin, newsp, sizeof(tmpwin)) ||
#endif
CPOUTREG(&(((struct rwindow *)newsp)->rw_in[6]), tf->tf_out[6])) {
/*
* Process has trashed its stack; give it an illegal
* instruction to halt it in its tracks.
*/
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
printf("sendsig: window save or copyout error\n");
printf("sendsig: stack was trashed trying to send sig %d, sending SIGILL\n", sig);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
#endif
sigexit(l, SIGILL);
/* NOTREACHED */
}
#ifdef DEBUG
if (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.
*/
switch (ps->sa_sigdesc[sig].sd_vers) {
case 0: /* legacy on-stack sigtramp */
addr = (void *)p->p_sigctx.ps_sigcode;
break;
case 1:
addr = (void *)ps->sa_sigdesc[sig].sd_tramp;
break;
default:
/* Don't know what trampoline version; kill it. */
sigexit(l, SIGILL);
}
buildcontext(l, catcher, addr, newsp);
/* Remember that we're now on the signal stack. */
if (onstack)
p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) {
printf("sendsig: about to return to catcher %p thru %p\n",
catcher, (void *)(unsigned long)addr);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
}
/*
* System call to cleanup state after a signal
* has been taken. Reset signal mask and
* stack state from context left by sendsig (above),
* and return to the given trap frame (if there is one).
* Check carefully to make sure that the user has not
* modified the state to gain improper privileges or to cause
* a machine fault.
*/
int compat_16_sys___sigreturn14(struct lwp *, void *, register_t *);
/* ARGSUSED */
int
compat_16_sys___sigreturn14(l, v, retval)
register struct lwp *l;
void *v;
register_t *retval;
{
struct proc *p = l->l_proc;
struct compat_16_sys___sigreturn14_args /* {
syscallarg(struct sigcontext *) sigcntxp;
} */ *uap = v;
struct sigcontext sc, *scp;
register struct trapframe64 *tf;
int error = EINVAL;
/* First ensure consistent stack state (see sendsig). */
write_user_windows();
if (rwindow_save(l)) {
#ifdef DEBUG
printf("sigreturn14: rwindow_save(%p) failed, sending SIGILL\n", p);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
#endif
sigexit(l, SIGILL);
}
#ifdef DEBUG
if (sigdebug & SDB_FOLLOW) {
printf("sigreturn14: %s[%d], sigcntxp %p\n",
p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
scp = SCARG(uap, sigcntxp);
if ((vaddr_t)scp & 3 || (error = copyin((caddr_t)scp, &sc, sizeof sc) != 0))
#ifdef DEBUG
{
printf("sigreturn14: copyin failed: scp=%p\n", scp);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
return (error);
}
#else
return (error);
#endif
scp = &sc;
tf = l->l_md.md_tf;
/*
* Only the icc bits in the psr are used, so it need not be
* verified. pc and npc must be multiples of 4. This is all
* that is required; if it holds, just do it.
*/
if (((sc.sc_pc | sc.sc_npc) & 3) != 0 || (sc.sc_pc == 0) || (sc.sc_npc == 0))
#ifdef DEBUG
{
printf("sigreturn14: pc %p or npc %p invalid\n",
(void *)(unsigned long)sc.sc_pc,
(void *)(unsigned long)sc.sc_npc);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
return (EINVAL);
}
#else
return (EINVAL);
#endif
/* take only psr ICC field */
#ifdef __arch64__
tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | (scp->sc_tstate & TSTATE_CCR);
#else
tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(scp->sc_psr);
#endif
tf->tf_pc = (u_int64_t)scp->sc_pc;
tf->tf_npc = (u_int64_t)scp->sc_npc;
tf->tf_global[1] = (u_int64_t)scp->sc_g1;
tf->tf_out[0] = (u_int64_t)scp->sc_o0;
tf->tf_out[6] = (u_int64_t)scp->sc_sp;
#ifdef DEBUG
if (sigdebug & SDB_FOLLOW) {
printf("sigreturn14: return trapframe pc=%p sp=%p tstate=%llx\n",
(void *)(unsigned long)tf->tf_pc,
(void *)(unsigned long)tf->tf_out[6],
(unsigned long long)tf->tf_tstate);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
/* Restore signal stack. */
if (sc.sc_onstack & SS_ONSTACK)
p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
/* Restore signal mask. */
(void) sigprocmask1(p, SIG_SETMASK, &sc.sc_mask, 0);
return (EJUSTRETURN);
}
#endif /* COMPAT_16 */

View File

@ -1,4 +1,4 @@
# $NetBSD: genassym.cf,v 1.30 2003/04/03 22:19:16 martin Exp $
# $NetBSD: genassym.cf,v 1.31 2003/10/26 08:05:26 christos Exp $
#
# Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -186,7 +186,6 @@ define FPRS_DU FPRS_DU
define FPRS_DL FPRS_DL
# system calls
define SYS___sigreturn14 SYS___sigreturn14
define SYS_execve SYS_execve
define SYS_exit SYS_exit

View File

@ -1,4 +1,4 @@
/* $NetBSD: locore.s,v 1.179 2003/08/24 17:52:38 chs Exp $ */
/* $NetBSD: locore.s,v 1.180 2003/10/26 08:05:26 christos Exp $ */
/*
* Copyright (c) 1996-2002 Eduardo Horvath
@ -78,6 +78,8 @@
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_multiprocessor.h"
#include "opt_compat_netbsd.h"
#include "opt_compat_netbsd32.h"
#include "opt_lockdebug.h"
#include "assym.h"
@ -92,6 +94,7 @@
#include <machine/pte.h>
#include <machine/pmap.h>
#include <machine/asm.h>
#include <sys/syscall.h>
#include "ksyms.h"
@ -6608,6 +6611,7 @@ ENTRY(cache_flush_phys)
retl
nop
#ifdef COMPAT_16
#ifdef _LP64
/*
* XXXXX Still needs lotsa cleanup after sendsig is complete and offsets are known
@ -6719,7 +6723,7 @@ _C_LABEL(sigcode):
mov %l7, %g7
membar #Sync
restore %g0, SYS___sigreturn14, %g1 ! get registers back & set syscall #
restore %g0, SYS_compat_16___sigreturn14, %g1 ! get registers back & set syscall #
add %sp, BIAS + 128 + 8, %o0! compute scp
! andn %o0, 0x0f, %o0
t ST_SYSCALL ! sigreturn(scp)
@ -6734,11 +6738,12 @@ _C_LABEL(esigcode):
#define SIGCODE_NAME sigcode
#define ESIGCODE_NAME esigcode
#define SIGRETURN_NAME SYS___sigreturn14
#define SIGRETURN_NAME SYS_compat_16___sigreturn14
#define EXIT_NAME SYS_exit
#include "sigcode32.s"
#endif
#endif
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.150 2003/10/21 08:31:11 petrov Exp $ */
/* $NetBSD: machdep.c,v 1.151 2003/10/26 08:05:26 christos Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@ -78,11 +78,10 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.150 2003/10/21 08:31:11 petrov Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.151 2003/10/26 08:05:26 christos Exp $");
#include "opt_compat_sunos.h"
#include "opt_compat_sunos.h"
#include "opt_ddb.h"
#include "opt_compat_netbsd.h"
#include <sys/param.h>
#include <sys/extent.h>
@ -380,24 +379,6 @@ setregs(l, pack, stack)
#endif
}
#ifdef DEBUG
/* See sigdebug.h */
#include <sparc64/sparc64/sigdebug.h>
int sigdebug = 0x0;
int sigpid = 0;
#endif
struct sigframe {
int sf_signo; /* signal number */
int sf_code; /* code */
#ifndef __arch64__
struct sigcontext *sf_scp; /* SunOS user addr of sigcontext */
int sf_addr; /* SunOS compat, always 0 for now */
#endif
struct sigcontext sf_sc; /* actual sigcontext */
};
static char *parse_bootfile(char *);
static char *parse_bootargs(char *);
@ -518,182 +499,117 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
/* NOTREACHED */
}
/*
* Send an interrupt to process.
*/
void
sendsig(sig, mask, code)
int sig;
const sigset_t *mask;
u_long code;
void *
getframe(struct lwp *l, int sig, int *onstack)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
struct sigacts *ps = p->p_sigacts;
struct sigframe *fp;
struct trapframe64 *tf;
vaddr_t addr;
struct rwindow *oldsp, *newsp;
#ifdef NOT_DEBUG
struct rwindow tmpwin;
#endif
struct sigframe sf;
int onstack;
sig_t catcher = SIGACTION(p, sig).sa_handler;
tf = l->l_md.md_tf;
oldsp = (struct rwindow *)(u_long)(tf->tf_out[6] + STACK_OFFSET);
struct sigctx *ctx = &p->p_sigctx;
struct trapframe64 *tf = l->l_md.md_tf;
/*
* Compute new user stack addresses, subtract off
* one signal frame, and align.
*/
onstack =
(p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
(SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
*onstack = (ctx->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0
&& (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
if (onstack)
fp = (struct sigframe *)((caddr_t)p->p_sigctx.ps_sigstk.ss_sp +
p->p_sigctx.ps_sigstk.ss_size);
if (*onstack)
return ((caddr_t)ctx->ps_sigstk.ss_sp + ctx->ps_sigstk.ss_size);
else
fp = (struct sigframe *)oldsp;
return (void *)(tf->tf_out[6] + STACK_OFFSET);
}
/*
* Build context to run handler in. We invoke the handler
* directly, only returning via the trampoline. Note the
* trampoline version numbers are coordinated with machine-
* dependent code in libc.
*/
void
buildcontext(struct lwp *l, void *catcher, const void *addr, void *newsp)
{
struct trapframe64 *tf = l->l_md.md_tf;
tf->tf_global[1] = (vaddr_t)catcher;
tf->tf_pc = (const vaddr_t)addr;
tf->tf_npc = (const vaddr_t)addr + 4;
tf->tf_out[6] = (vaddr_t)newsp - STACK_OFFSET;
}
struct sigframe_siginfo {
int sf_signum; /* "signum" argument for handler */
siginfo_t *sf_sip; /* "sip" argument for handler */
ucontext_t *sf_ucp; /* "ucp" argument for handler */
siginfo_t sf_si; /* actual saved siginfo */
ucontext_t sf_uc; /* actual saved ucontext */
};
static void
sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
{
struct lwp *l = curlwp;
struct proc *p = l->l_proc;
struct sigacts *ps = p->p_sigacts;
int onstack;
int sig = ksi->ksi_signo;
struct sigframe_siginfo *fp = getframe(l, sig, &onstack), frame;
sig_t catcher = SIGACTION(p, sig).sa_handler;
struct trapframe *tf = l->l_md.md_tf;
struct rwindow *newsp = (void *)((vaddr_t)fp - sizeof(struct rwindow));
/* Allocate an aligned sigframe */
fp = (struct sigframe *)((long)(fp - 1) & ~0x0f);
fp = (void *)((u_long)(fp - 1) & ~0x0f);
#ifdef DEBUG
sigpid = p->p_pid;
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) {
printf("sendsig: %s[%d] sig %d newusp %p scp %p oldsp %p\n",
p->p_comm, p->p_pid, sig, fp, &fp->sf_sc, oldsp);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
/* Build stack frame for signal trampoline. */
switch (ps->sa_sigdesc[sig].sd_vers) {
case 0: /* handled by sendsig_sigcontext */
case 1: /* handled by sendsig_sigcontext */
default: /* unknown version */
printf("sendsig_siginfo: bad version %d\n",
ps->sa_sigdesc[sig].sd_vers);
sigexit(l, SIGILL);
case 2:
break;
}
#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;
#ifndef __arch64__
sf.sf_scp = 0;
sf.sf_addr = 0; /* XXX */
#endif
frame.sf_signum = sig;
frame.sf_sip = &fp->sf_si;
frame.sf_ucp = &fp->sf_uc;
frame.sf_si._info = ksi->ksi_info;
frame.sf_uc.uc_flags = _UC_SIGMASK|_UC_CPU;
frame.sf_uc.uc_sigmask = *mask;
frame.sf_uc.uc_link = NULL;
frame.sf_uc.uc_flags |= (p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK)
? _UC_SETSTACK : _UC_CLRSTACK;
memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
/*
* Build the signal context to be used by sigreturn.
*/
sf.sf_sc.sc_onstack = p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK;
sf.sf_sc.sc_mask = *mask;
#ifdef COMPAT_13
/*
* XXX We always have to save an old style signal mask because
* XXX we might be delivering a signal to a process which will
* XXX escape from the signal in a non-standard way and invoke
* XXX sigreturn() directly.
*/
native_sigset_to_sigset13(mask, &sf.sf_sc.__sc_mask13);
#endif
/* Save register context. */
sf.sf_sc.sc_sp = (long)tf->tf_out[6];
sf.sf_sc.sc_pc = tf->tf_pc;
sf.sf_sc.sc_npc = tf->tf_npc;
#ifdef __arch64__
sf.sf_sc.sc_tstate = tf->tf_tstate; /* XXX */
#else
sf.sf_sc.sc_psr = TSTATECCR_TO_PSR(tf->tf_tstate); /* XXX */
#endif
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 = (struct rwindow *)((vaddr_t)fp - sizeof(struct rwindow));
write_user_windows();
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK))
printf("sendsig: saving sf to %p, setting stack pointer %p to %p\n",
fp, &(((struct rwindow *)newsp)->rw_in[6]),
(void *)(unsigned long)tf->tf_out[6]);
#endif
if (rwindow_save(l) || copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf) ||
#ifdef NOT_DEBUG
copyin(oldsp, &tmpwin, sizeof(tmpwin)) || copyout(&tmpwin, newsp, sizeof(tmpwin)) ||
#endif
if (rwindow_save(l) || copyout(&frame, fp, sizeof(frame)) != 0 ||
CPOUTREG(&(((struct rwindow *)newsp)->rw_in[6]), tf->tf_out[6])) {
/*
* Process has trashed its stack; give it an illegal
* instruction to halt it in its tracks.
*/
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
printf("sendsig: window save or copyout error\n");
printf("sendsig: stack was trashed trying to send sig %d, sending SIGILL\n", sig);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
#endif
sigexit(l, SIGILL);
/* NOTREACHED */
}
#ifdef DEBUG
if (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.
*/
switch (ps->sa_sigdesc[sig].sd_vers) {
#if 1 /* COMPAT_16 */
case 0: /* legacy on-stack sigtramp */
addr = (vaddr_t)p->p_sigctx.ps_sigcode;
break;
#endif /* COMPAT_16 */
case 1:
addr = (vaddr_t)ps->sa_sigdesc[sig].sd_tramp;
break;
default:
/* Don't know what trampoline version; kill it. */
sigexit(l, SIGILL);
}
tf->tf_global[1] = (vaddr_t)catcher;
tf->tf_pc = addr;
tf->tf_npc = addr + 4;
tf->tf_out[6] = (vaddr_t)newsp - STACK_OFFSET;
buildcontext(l, catcher, ps->sa_sigdesc[sig].sd_tramp, newsp);
/* Remember that we're now on the signal stack. */
if (onstack)
p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
#ifdef DEBUG
if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) {
printf("sendsig: about to return to catcher %p thru %p\n",
catcher, (void *)(unsigned long)addr);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
}
void
sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
{
#ifdef COMPAT_16
if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
sendsig_sigcontext(ksi, mask);
else
#endif
sendsig_siginfo(ksi, mask);
}
/*
* Set the lwp to begin execution in the upcall handler. The upcall
@ -734,120 +650,6 @@ cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted,
tf->tf_out[7] = -1; /* "you lose" if upcall returns */
}
/*
* System call to cleanup state after a signal
* has been taken. Reset signal mask and
* stack state from context left by sendsig (above),
* and return to the given trap frame (if there is one).
* Check carefully to make sure that the user has not
* modified the state to gain improper privileges or to cause
* a machine fault.
*/
/* ARGSUSED */
int
sys___sigreturn14(l, v, retval)
register struct lwp *l;
void *v;
register_t *retval;
{
struct proc *p = l->l_proc;
struct sys___sigreturn14_args /* {
syscallarg(struct sigcontext *) sigcntxp;
} */ *uap = v;
struct sigcontext sc, *scp;
register struct trapframe64 *tf;
int error = EINVAL;
/* First ensure consistent stack state (see sendsig). */
write_user_windows();
if (rwindow_save(l)) {
#ifdef DEBUG
printf("sigreturn14: rwindow_save(%p) failed, sending SIGILL\n", p);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
#endif
sigexit(l, SIGILL);
}
#ifdef DEBUG
if (sigdebug & SDB_FOLLOW) {
printf("sigreturn14: %s[%d], sigcntxp %p\n",
p->p_comm, p->p_pid, SCARG(uap, sigcntxp));
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
scp = SCARG(uap, sigcntxp);
if ((vaddr_t)scp & 3 || (error = copyin((caddr_t)scp, &sc, sizeof sc) != 0))
#ifdef DEBUG
{
printf("sigreturn14: copyin failed: scp=%p\n", scp);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
return (error);
}
#else
return (error);
#endif
scp = &sc;
tf = l->l_md.md_tf;
/*
* Only the icc bits in the psr are used, so it need not be
* verified. pc and npc must be multiples of 4. This is all
* that is required; if it holds, just do it.
*/
if (((sc.sc_pc | sc.sc_npc) & 3) != 0 || (sc.sc_pc == 0) || (sc.sc_npc == 0))
#ifdef DEBUG
{
printf("sigreturn14: pc %p or npc %p invalid\n",
(void *)(unsigned long)sc.sc_pc,
(void *)(unsigned long)sc.sc_npc);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
return (EINVAL);
}
#else
return (EINVAL);
#endif
/* take only psr ICC field */
#ifdef __arch64__
tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | (scp->sc_tstate & TSTATE_CCR);
#else
tf->tf_tstate = (u_int64_t)(tf->tf_tstate & ~TSTATE_CCR) | PSRCC_TO_TSTATE(scp->sc_psr);
#endif
tf->tf_pc = (u_int64_t)scp->sc_pc;
tf->tf_npc = (u_int64_t)scp->sc_npc;
tf->tf_global[1] = (u_int64_t)scp->sc_g1;
tf->tf_out[0] = (u_int64_t)scp->sc_o0;
tf->tf_out[6] = (u_int64_t)scp->sc_sp;
#ifdef DEBUG
if (sigdebug & SDB_FOLLOW) {
printf("sigreturn14: return trapframe pc=%p sp=%p tstate=%llx\n",
(void *)(unsigned long)tf->tf_pc,
(void *)(unsigned long)tf->tf_out[6],
(unsigned long long)tf->tf_tstate);
#ifdef DDB
if (sigdebug & SDB_DDB) Debugger();
#endif
}
#endif
/* Restore signal stack. */
if (sc.sc_onstack & SS_ONSTACK)
p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
/* Restore signal mask. */
(void) sigprocmask1(p, SIG_SETMASK, &sc.sc_mask, 0);
return (EJUSTRETURN);
}
int waittime = -1;
void
@ -2243,6 +2045,11 @@ cpu_setmcontext(l, mcp, flags)
/* XXX mcp->__xrs */
/* XXX mcp->__asrs */
if (flags & _UC_SETSTACK)
l->l_proc->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
if (flags & _UC_CLRSTACK)
l->l_proc->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_machdep.c,v 1.39 2003/10/21 01:54:23 fvdl Exp $ */
/* $NetBSD: netbsd32_machdep.c,v 1.40 2003/10/26 08:05:27 christos Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.39 2003/10/21 01:54:23 fvdl Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.40 2003/10/26 08:05:27 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -163,8 +163,9 @@ extern int sigdebug;
#endif
void
netbsd32_sendsig(int sig, const sigset_t *mask, u_long code)
netbsd32_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
{
int sig = ksi->ksi_signo;
register struct lwp *l = curlwp;
struct proc *p = l->l_proc;
register struct sparc32_sigframe *fp;
@ -205,7 +206,7 @@ netbsd32_sendsig(int sig, const sigset_t *mask, u_long code)
* directly in user space....
*/
sf.sf_signo = sig;
sf.sf_code = (u_int)code;
sf.sf_code = (u_int)ksi->ksi_trap;
#if defined(COMPAT_SUNOS) || defined(LKM)
sf.sf_scp = (u_long)&fp->sf_sc;
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: sunos32_machdep.c,v 1.13 2003/10/21 12:08:11 kleink Exp $ */
/* $NetBSD: sunos32_machdep.c,v 1.14 2003/10/26 08:05:27 christos Exp $ */
/* from: NetBSD: sunos_machdep.c,v 1.14 2001/01/29 01:37:56 mrg Exp */
/*
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sunos32_machdep.c,v 1.13 2003/10/21 12:08:11 kleink Exp $");
__KERNEL_RCSID(0, "$NetBSD: sunos32_machdep.c,v 1.14 2003/10/26 08:05:27 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -159,11 +159,9 @@ sunos32_setregs(l, pack, stack)
}
void
sunos32_sendsig(sig, mask, code)
int sig;
const sigset_t *mask;
u_long code;
sunos32_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
{
int sig = ksi->ksi_signo;
struct lwp *l = curlwp; /* XXX */
struct proc *p = l->l_proc;
struct sunos32_sigframe *fp;
@ -212,7 +210,7 @@ sunos32_sendsig(sig, mask, code)
* directly in user space....
*/
sf.sf_signo = sig;
sf.sf_code = (u_int32_t)code;
sf.sf_code = (u_int32_t)ksi->ksi_trap;
scp = &fp->sf_sc;
if ((u_long)scp >= 0x100000000)
printf("sunos32_sendsig: sf_scp overflow %p > 0x100000000\n", scp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_32_machdep.c,v 1.16 2003/09/28 10:27:25 martin Exp $ */
/* $NetBSD: svr4_32_machdep.c,v 1.17 2003/10/26 08:05:27 christos Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_32_machdep.c,v 1.16 2003/09/28 10:27:25 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_32_machdep.c,v 1.17 2003/10/26 08:05:27 christos Exp $");
#ifndef _LKM
#include "opt_ddb.h"
@ -468,11 +468,9 @@ svr4_32_getsiginfo(si, sig, code, addr)
* will return to the user pc, psl.
*/
void
svr4_32_sendsig(sig, mask, code)
int sig;
const sigset_t *mask;
u_long code;
svr4_32_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
{
int sig = ksi->ksi_signo;
register struct lwp *l = curlwp;
struct proc *p = l->l_proc;
register struct trapframe64 *tf;
@ -513,7 +511,8 @@ svr4_32_sendsig(sig, mask, code)
* Build the argument list for the signal handler.
*/
svr4_32_getcontext(l, &frame.sf_uc, mask);
svr4_32_getsiginfo(&frame.sf_si, sig, code, (caddr_t)(u_long)tf->tf_pc);
svr4_32_getsiginfo(&frame.sf_si, sig, ksi->ksi_trap,
(caddr_t)(u_long)tf->tf_pc);
/* Build stack frame for signal trampoline. */
frame.sf_signum = frame.sf_si.si_signo;

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_machdep.c,v 1.33 2003/09/26 12:02:56 simonb Exp $ */
/* $NetBSD: svr4_machdep.c,v 1.34 2003/10/26 08:05:27 christos Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.33 2003/09/26 12:02:56 simonb Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.34 2003/10/26 08:05:27 christos Exp $");
#ifndef _LKM
#include "opt_ddb.h"
@ -502,11 +502,9 @@ svr4_getsiginfo(si, sig, code, addr)
#endif
void
svr4_sendsig(sig, mask, code)
int sig;
const sigset_t *mask;
u_long code;
svr4_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
{
int sig = ksi->ksi_signo;
register struct lwp *l = curlwp;
struct proc *p = l->l_proc;
register struct trapframe64 *tf;
@ -547,7 +545,8 @@ svr4_sendsig(sig, mask, code)
* Build the argument list for the signal handler.
*/
svr4_getcontext(l, &frame.sf_uc);
svr4_getsiginfo(&frame.sf_si, sig, code, (caddr_t)(u_long)tf->tf_pc);
svr4_getsiginfo(&frame.sf_si, sig, ksi->ksi_trap,
(caddr_t)(u_long)tf->tf_pc);
/* Build stack frame for signal trampoline. */
frame.sf_signum = frame.sf_si.si_signo;