2008-05-19 17:52:27 -06:00
|
|
|
/*
|
2005-04-16 16:20:36 -06:00
|
|
|
* arch/sparc64/kernel/signal.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
* Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
|
|
|
|
* Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
|
|
|
|
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
|
|
|
|
* Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
|
|
|
|
*/
|
|
|
|
|
2008-04-26 04:17:12 -06:00
|
|
|
#ifdef CONFIG_COMPAT
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/compat.h> /* for compat_old_sigset_t */
|
|
|
|
#endif
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/unistd.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/fpumacro.h>
|
|
|
|
#include <asm/uctx.h>
|
|
|
|
#include <asm/siginfo.h>
|
|
|
|
#include <asm/visasm.h>
|
|
|
|
|
2008-03-26 02:52:18 -06:00
|
|
|
#include "entry.h"
|
|
|
|
#include "systbls.h"
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
|
|
|
|
|
|
|
|
/* {set, get}context() needed for 64-bit SparcLinux userland. */
|
|
|
|
asmlinkage void sparc64_set_context(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct ucontext __user *ucp = (struct ucontext __user *)
|
|
|
|
regs->u_regs[UREG_I0];
|
|
|
|
mc_gregset_t __user *grp;
|
|
|
|
unsigned long pc, npc, tstate;
|
|
|
|
unsigned long fp, i7;
|
|
|
|
unsigned char fenab;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
flush_user_windows();
|
|
|
|
if (get_thread_wsaved() ||
|
|
|
|
(((unsigned long)ucp) & (sizeof(unsigned long)-1)) ||
|
|
|
|
(!__access_ok(ucp, sizeof(*ucp))))
|
|
|
|
goto do_sigsegv;
|
|
|
|
grp = &ucp->uc_mcontext.mc_gregs;
|
|
|
|
err = __get_user(pc, &((*grp)[MC_PC]));
|
|
|
|
err |= __get_user(npc, &((*grp)[MC_NPC]));
|
|
|
|
if (err || ((pc | npc) & 3))
|
|
|
|
goto do_sigsegv;
|
|
|
|
if (regs->u_regs[UREG_I1]) {
|
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
if (_NSIG_WORDS == 1) {
|
|
|
|
if (__get_user(set.sig[0], &ucp->uc_sigmask.sig[0]))
|
|
|
|
goto do_sigsegv;
|
|
|
|
} else {
|
|
|
|
if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
|
|
|
|
goto do_sigsegv;
|
|
|
|
}
|
|
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
current->blocked = set;
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
}
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
pc &= 0xffffffff;
|
|
|
|
npc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
regs->tpc = pc;
|
|
|
|
regs->tnpc = npc;
|
|
|
|
err |= __get_user(regs->y, &((*grp)[MC_Y]));
|
|
|
|
err |= __get_user(tstate, &((*grp)[MC_TSTATE]));
|
|
|
|
regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
|
|
|
|
regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G1], (&(*grp)[MC_G1]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G2], (&(*grp)[MC_G2]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G3], (&(*grp)[MC_G3]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G4], (&(*grp)[MC_G4]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G5], (&(*grp)[MC_G5]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G6], (&(*grp)[MC_G6]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_G7], (&(*grp)[MC_G7]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I0], (&(*grp)[MC_O0]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I1], (&(*grp)[MC_O1]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I2], (&(*grp)[MC_O2]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I3], (&(*grp)[MC_O3]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I4], (&(*grp)[MC_O4]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I5], (&(*grp)[MC_O5]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I6], (&(*grp)[MC_O6]));
|
|
|
|
err |= __get_user(regs->u_regs[UREG_I7], (&(*grp)[MC_O7]));
|
|
|
|
|
|
|
|
err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp));
|
|
|
|
err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7));
|
|
|
|
err |= __put_user(fp,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
|
|
|
|
err |= __put_user(i7,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
|
|
|
|
|
|
|
|
err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab));
|
|
|
|
if (fenab) {
|
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
|
|
|
unsigned long fprs;
|
|
|
|
|
|
|
|
fprs_write(0);
|
|
|
|
err |= __get_user(fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs));
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_from_user(fpregs,
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs),
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_from_user(fpregs+16,
|
|
|
|
((unsigned long __user *)&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs))+16,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __get_user(current_thread_info()->xfsr[0],
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr));
|
|
|
|
err |= __get_user(current_thread_info()->gsr[0],
|
|
|
|
&(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr));
|
|
|
|
regs->tstate &= ~TSTATE_PEF;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto do_sigsegv;
|
|
|
|
|
|
|
|
return;
|
|
|
|
do_sigsegv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
asmlinkage void sparc64_get_context(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct ucontext __user *ucp = (struct ucontext __user *)
|
|
|
|
regs->u_regs[UREG_I0];
|
|
|
|
mc_gregset_t __user *grp;
|
|
|
|
mcontext_t __user *mcp;
|
|
|
|
unsigned long fp, i7;
|
|
|
|
unsigned char fenab;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
synchronize_user_stack();
|
|
|
|
if (get_thread_wsaved() || clear_user(ucp, sizeof(*ucp)))
|
|
|
|
goto do_sigsegv;
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
fenab = 0; /* IMO get_context is like any other system call, thus modifies FPU state -jj */
|
|
|
|
#else
|
|
|
|
fenab = (current_thread_info()->fpsaved[0] & FPRS_FEF);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mcp = &ucp->uc_mcontext;
|
|
|
|
grp = &mcp->mc_gregs;
|
|
|
|
|
|
|
|
/* Skip over the trap instruction, first. */
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc = (regs->tnpc & 0xffffffff);
|
|
|
|
regs->tnpc = (regs->tnpc + 4) & 0xffffffff;
|
|
|
|
} else {
|
|
|
|
regs->tpc = regs->tnpc;
|
|
|
|
regs->tnpc += 4;
|
|
|
|
}
|
|
|
|
err = 0;
|
|
|
|
if (_NSIG_WORDS == 1)
|
|
|
|
err |= __put_user(current->blocked.sig[0],
|
|
|
|
(unsigned long __user *)&ucp->uc_sigmask);
|
|
|
|
else
|
|
|
|
err |= __copy_to_user(&ucp->uc_sigmask, ¤t->blocked,
|
|
|
|
sizeof(sigset_t));
|
|
|
|
|
|
|
|
err |= __put_user(regs->tstate, &((*grp)[MC_TSTATE]));
|
|
|
|
err |= __put_user(regs->tpc, &((*grp)[MC_PC]));
|
|
|
|
err |= __put_user(regs->tnpc, &((*grp)[MC_NPC]));
|
|
|
|
err |= __put_user(regs->y, &((*grp)[MC_Y]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G1], &((*grp)[MC_G1]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G2], &((*grp)[MC_G2]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G3], &((*grp)[MC_G3]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G4], &((*grp)[MC_G4]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G5], &((*grp)[MC_G5]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G6], &((*grp)[MC_G6]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_G7], &((*grp)[MC_G7]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I0], &((*grp)[MC_O0]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I1], &((*grp)[MC_O1]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I2], &((*grp)[MC_O2]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I3], &((*grp)[MC_O3]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I4], &((*grp)[MC_O4]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I5], &((*grp)[MC_O5]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I6], &((*grp)[MC_O6]));
|
|
|
|
err |= __put_user(regs->u_regs[UREG_I7], &((*grp)[MC_O7]));
|
|
|
|
|
|
|
|
err |= __get_user(fp,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
|
|
|
|
err |= __get_user(i7,
|
|
|
|
(&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
|
|
|
|
err |= __put_user(fp, &(mcp->mc_fp));
|
|
|
|
err |= __put_user(i7, &(mcp->mc_i7));
|
|
|
|
|
|
|
|
err |= __put_user(fenab, &(mcp->mc_fpregs.mcfpu_enab));
|
|
|
|
if (fenab) {
|
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
|
|
|
unsigned long fprs;
|
|
|
|
|
|
|
|
fprs = current_thread_info()->fpsaved[0];
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_to_user(&(mcp->mc_fpregs.mcfpu_fregs), fpregs,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_to_user(
|
|
|
|
((unsigned long __user *)&(mcp->mc_fpregs.mcfpu_fregs))+16, fpregs+16,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __put_user(current_thread_info()->xfsr[0], &(mcp->mc_fpregs.mcfpu_fsr));
|
|
|
|
err |= __put_user(current_thread_info()->gsr[0], &(mcp->mc_fpregs.mcfpu_gsr));
|
|
|
|
err |= __put_user(fprs, &(mcp->mc_fpregs.mcfpu_fprs));
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto do_sigsegv;
|
|
|
|
|
|
|
|
return;
|
|
|
|
do_sigsegv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rt_signal_frame {
|
|
|
|
struct sparc_stackf ss;
|
|
|
|
siginfo_t info;
|
|
|
|
struct pt_regs regs;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
stack_t stack;
|
|
|
|
sigset_t mask;
|
|
|
|
__siginfo_fpu_t fpu_state;
|
|
|
|
};
|
|
|
|
|
2006-01-19 03:42:49 -07:00
|
|
|
static long _sigpause_common(old_sigset_t set)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
set &= _BLOCKABLE;
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
2006-01-19 03:42:49 -07:00
|
|
|
current->saved_sigmask = current->blocked;
|
2005-04-16 16:20:36 -06:00
|
|
|
siginitset(¤t->blocked, set);
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
|
2006-01-19 03:42:49 -07:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
schedule();
|
2008-05-12 23:45:15 -06:00
|
|
|
|
|
|
|
set_restore_sigmask();
|
|
|
|
|
2006-01-19 03:42:49 -07:00
|
|
|
return -ERESTARTNOHAND;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-19 03:42:49 -07:00
|
|
|
asmlinkage long sys_sigpause(unsigned int set)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-19 03:42:49 -07:00
|
|
|
return _sigpause_common(set);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-19 03:42:49 -07:00
|
|
|
asmlinkage long sys_sigsuspend(old_sigset_t set)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-19 03:42:49 -07:00
|
|
|
return _sigpause_common(set);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
|
|
|
|
{
|
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
|
|
|
unsigned long fprs;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = __get_user(fprs, &fpu->si_fprs);
|
|
|
|
fprs_write(0);
|
|
|
|
regs->tstate &= ~TSTATE_PEF;
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_from_user(fpregs, &fpu->si_float_regs[0],
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32],
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
|
|
|
|
err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr);
|
|
|
|
current_thread_info()->fpsaved[0] |= fprs;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_rt_sigreturn(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
|
|
|
unsigned long tpc, tnpc, tstate;
|
|
|
|
__siginfo_fpu_t __user *fpu_save;
|
|
|
|
sigset_t set;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
|
|
|
current_thread_info()->restart_block.fn = do_no_restart_syscall;
|
|
|
|
|
|
|
|
synchronize_user_stack ();
|
|
|
|
sf = (struct rt_signal_frame __user *)
|
|
|
|
(regs->u_regs [UREG_FP] + STACK_BIAS);
|
|
|
|
|
|
|
|
/* 1. Make sure we are not getting garbage from the user */
|
|
|
|
if (((unsigned long) sf) & 3)
|
|
|
|
goto segv;
|
|
|
|
|
|
|
|
err = get_user(tpc, &sf->regs.tpc);
|
|
|
|
err |= __get_user(tnpc, &sf->regs.tnpc);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
tpc &= 0xffffffff;
|
|
|
|
tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
err |= ((tpc | tnpc) & 3);
|
|
|
|
|
|
|
|
/* 2. Restore the state */
|
|
|
|
err |= __get_user(regs->y, &sf->regs.y);
|
|
|
|
err |= __get_user(tstate, &sf->regs.tstate);
|
|
|
|
err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs));
|
|
|
|
|
|
|
|
/* User can only change condition codes and %asi in %tstate. */
|
|
|
|
regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
|
|
|
|
regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
|
|
|
|
|
|
|
|
err |= __get_user(fpu_save, &sf->fpu_save);
|
|
|
|
if (fpu_save)
|
|
|
|
err |= restore_fpu_state(regs, &sf->fpu_state);
|
|
|
|
|
|
|
|
err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
|
2007-07-17 15:37:54 -06:00
|
|
|
err |= do_sigaltstack(&sf->stack, NULL, (unsigned long)sf);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (err)
|
|
|
|
goto segv;
|
2007-07-17 15:37:54 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
regs->tpc = tpc;
|
|
|
|
regs->tnpc = tnpc;
|
|
|
|
|
2008-05-01 04:30:22 -06:00
|
|
|
/* Prevent syscall restart. */
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
pt_regs_clear_syscall(regs);
|
2008-05-01 04:30:22 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
sigdelsetmask(&set, ~_BLOCKABLE);
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
current->blocked = set;
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
return;
|
|
|
|
segv:
|
|
|
|
force_sig(SIGSEGV, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks if the fp is valid */
|
|
|
|
static int invalid_frame_pointer(void __user *fp, int fplen)
|
|
|
|
{
|
|
|
|
if (((unsigned long) fp) & 7)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
|
|
|
|
{
|
2008-04-03 16:07:24 -06:00
|
|
|
unsigned long *fpregs = current_thread_info()->fpregs;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long fprs;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
fprs = current_thread_info()->fpsaved[0];
|
|
|
|
if (fprs & FPRS_DL)
|
|
|
|
err |= copy_to_user(&fpu->si_float_regs[0], fpregs,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
if (fprs & FPRS_DU)
|
|
|
|
err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16,
|
|
|
|
(sizeof(unsigned int) * 32));
|
|
|
|
err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
|
|
|
|
err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr);
|
|
|
|
err |= __put_user(fprs, &fpu->si_fprs);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, unsigned long framesize)
|
|
|
|
{
|
2008-05-07 19:54:05 -06:00
|
|
|
unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-05-07 19:54:05 -06:00
|
|
|
/*
|
|
|
|
* If we are on the alternate signal stack and would overflow it, don't.
|
|
|
|
* Return an always-bogus address instead so we will die with SIGSEGV.
|
|
|
|
*/
|
|
|
|
if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
|
|
|
|
return (void __user *) -1L;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* This is the X/Open sanctioned signal stack switching. */
|
|
|
|
if (ka->sa.sa_flags & SA_ONSTACK) {
|
2008-05-07 19:54:05 -06:00
|
|
|
if (sas_ss_flags(sp) == 0)
|
2005-04-16 16:20:36 -06:00
|
|
|
sp = current->sas_ss_sp + current->sas_ss_size;
|
|
|
|
}
|
2008-05-07 19:54:05 -06:00
|
|
|
|
|
|
|
/* Always align the stack frame. This handles two cases. First,
|
|
|
|
* sigaltstack need not be mindful of platform specific stack
|
|
|
|
* alignment. Second, if we took this signal because the stack
|
|
|
|
* is not aligned properly, we'd like to take the signal cleanly
|
|
|
|
* and report that.
|
|
|
|
*/
|
|
|
|
sp &= ~7UL;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return (void __user *)(sp - framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
|
|
|
|
int signo, sigset_t *oldset, siginfo_t *info)
|
|
|
|
{
|
|
|
|
struct rt_signal_frame __user *sf;
|
|
|
|
int sigframe_size, err;
|
|
|
|
|
|
|
|
/* 1. Make sure everything is clean */
|
|
|
|
synchronize_user_stack();
|
|
|
|
save_and_clear_fpu();
|
|
|
|
|
2008-04-27 01:25:30 -06:00
|
|
|
sigframe_size = sizeof(struct rt_signal_frame);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!(current_thread_info()->fpsaved[0] & FPRS_FEF))
|
|
|
|
sigframe_size -= sizeof(__siginfo_fpu_t);
|
|
|
|
|
|
|
|
sf = (struct rt_signal_frame __user *)
|
|
|
|
get_sigframe(ka, regs, sigframe_size);
|
|
|
|
|
|
|
|
if (invalid_frame_pointer (sf, sigframe_size))
|
|
|
|
goto sigill;
|
|
|
|
|
|
|
|
if (get_thread_wsaved() != 0)
|
|
|
|
goto sigill;
|
|
|
|
|
|
|
|
/* 2. Save the current process state */
|
|
|
|
err = copy_to_user(&sf->regs, regs, sizeof (*regs));
|
|
|
|
|
|
|
|
if (current_thread_info()->fpsaved[0] & FPRS_FEF) {
|
|
|
|
err |= save_fpu_state(regs, &sf->fpu_state);
|
|
|
|
err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save);
|
|
|
|
} else {
|
|
|
|
err |= __put_user(0, &sf->fpu_save);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup sigaltstack */
|
|
|
|
err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
|
|
|
|
err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
|
|
|
|
err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
|
|
|
|
|
|
|
|
err |= copy_to_user(&sf->mask, oldset, sizeof(sigset_t));
|
|
|
|
|
|
|
|
err |= copy_in_user((u64 __user *)sf,
|
|
|
|
(u64 __user *)(regs->u_regs[UREG_FP]+STACK_BIAS),
|
|
|
|
sizeof(struct reg_window));
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
err |= copy_siginfo_to_user(&sf->info, info);
|
|
|
|
else {
|
|
|
|
err |= __put_user(signo, &sf->info.si_signo);
|
|
|
|
err |= __put_user(SI_NOINFO, &sf->info.si_code);
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto sigsegv;
|
|
|
|
|
|
|
|
/* 3. signal handler back-trampoline and parameters */
|
|
|
|
regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
|
|
|
|
regs->u_regs[UREG_I0] = signo;
|
|
|
|
regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* The sigcontext is passed in this way because of how it
|
|
|
|
* is defined in GLIBC's /usr/include/bits/sigcontext.h
|
|
|
|
* for sparc64. It includes the 128 bytes of siginfo_t.
|
|
|
|
*/
|
|
|
|
regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
|
|
|
|
|
|
|
|
/* 5. signal handler */
|
|
|
|
regs->tpc = (unsigned long) ka->sa.sa_handler;
|
|
|
|
regs->tnpc = (regs->tpc + 4);
|
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
|
|
|
regs->tpc &= 0xffffffff;
|
|
|
|
regs->tnpc &= 0xffffffff;
|
|
|
|
}
|
|
|
|
/* 4. return to kernel instructions */
|
|
|
|
regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
|
|
|
|
return;
|
|
|
|
|
|
|
|
sigill:
|
|
|
|
do_exit(SIGILL);
|
|
|
|
sigsegv:
|
|
|
|
force_sigsegv(signo, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void handle_signal(unsigned long signr, struct k_sigaction *ka,
|
|
|
|
siginfo_t *info,
|
|
|
|
sigset_t *oldset, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
setup_rt_frame(ka, regs, signr, oldset,
|
|
|
|
(ka->sa.sa_flags & SA_SIGINFO) ? info : NULL);
|
[PATCH] convert signal handling of NODEFER to act like other Unix boxes.
It has been reported that the way Linux handles NODEFER for signals is
not consistent with the way other Unix boxes handle it. I've written a
program to test the behavior of how this flag affects signals and had
several reports from people who ran this on various Unix boxes,
confirming that Linux seems to be unique on the way this is handled.
The way NODEFER affects signals on other Unix boxes is as follows:
1) If NODEFER is set, other signals in sa_mask are still blocked.
2) If NODEFER is set and the signal is in sa_mask, then the signal is
still blocked. (Note: this is the behavior of all tested but Linux _and_
NetBSD 2.0 *).
The way NODEFER affects signals on Linux:
1) If NODEFER is set, other signals are _not_ blocked regardless of
sa_mask (Even NetBSD doesn't do this).
2) If NODEFER is set and the signal is in sa_mask, then the signal being
handled is not blocked.
The patch converts signal handling in all current Linux architectures to
the way most Unix boxes work.
Unix boxes that were tested: DU4, AIX 5.2, Irix 6.5, NetBSD 2.0, SFU
3.5 on WinXP, AIX 5.3, Mac OSX, and of course Linux 2.6.13-rcX.
* NetBSD was the only other Unix to behave like Linux on point #2. The
main concern was brought up by point #1 which even NetBSD isn't like
Linux. So with this patch, we leave NetBSD as the lonely one that
behaves differently here with #2.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-29 09:44:09 -06:00
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
|
|
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
|
|
|
|
if (!(ka->sa.sa_flags & SA_NOMASK))
|
2005-04-16 16:20:36 -06:00
|
|
|
sigaddset(¤t->blocked,signr);
|
[PATCH] convert signal handling of NODEFER to act like other Unix boxes.
It has been reported that the way Linux handles NODEFER for signals is
not consistent with the way other Unix boxes handle it. I've written a
program to test the behavior of how this flag affects signals and had
several reports from people who ran this on various Unix boxes,
confirming that Linux seems to be unique on the way this is handled.
The way NODEFER affects signals on other Unix boxes is as follows:
1) If NODEFER is set, other signals in sa_mask are still blocked.
2) If NODEFER is set and the signal is in sa_mask, then the signal is
still blocked. (Note: this is the behavior of all tested but Linux _and_
NetBSD 2.0 *).
The way NODEFER affects signals on Linux:
1) If NODEFER is set, other signals are _not_ blocked regardless of
sa_mask (Even NetBSD doesn't do this).
2) If NODEFER is set and the signal is in sa_mask, then the signal being
handled is not blocked.
The patch converts signal handling in all current Linux architectures to
the way most Unix boxes work.
Unix boxes that were tested: DU4, AIX 5.2, Irix 6.5, NetBSD 2.0, SFU
3.5 on WinXP, AIX 5.3, Mac OSX, and of course Linux 2.6.13-rcX.
* NetBSD was the only other Unix to behave like Linux on point #2. The
main concern was brought up by point #1 which even NetBSD isn't like
Linux. So with this patch, we leave NetBSD as the lonely one that
behaves differently here with #2.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-29 09:44:09 -06:00
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
struct sigaction *sa)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
switch (regs->u_regs[UREG_I0]) {
|
|
|
|
case ERESTART_RESTARTBLOCK:
|
|
|
|
case ERESTARTNOHAND:
|
|
|
|
no_system_call_restart:
|
|
|
|
regs->u_regs[UREG_I0] = EINTR;
|
|
|
|
regs->tstate |= (TSTATE_ICARRY|TSTATE_XCARRY);
|
|
|
|
break;
|
|
|
|
case ERESTARTSYS:
|
|
|
|
if (!(sa->sa_flags & SA_RESTART))
|
|
|
|
goto no_system_call_restart;
|
|
|
|
/* fallthrough */
|
|
|
|
case ERESTARTNOINTR:
|
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that 'init' is a special process: it doesn't get signals it doesn't
|
|
|
|
* want to handle. Thus you cannot kill init even with a SIGKILL even by
|
|
|
|
* mistake.
|
|
|
|
*/
|
2008-04-24 04:01:48 -06:00
|
|
|
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct k_sigaction ka;
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
int restart_syscall;
|
2006-01-19 03:42:49 -07:00
|
|
|
sigset_t *oldset;
|
2008-04-24 04:01:48 -06:00
|
|
|
siginfo_t info;
|
2008-04-27 15:52:51 -06:00
|
|
|
int signr;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-05-01 04:30:22 -06:00
|
|
|
if (pt_regs_is_syscall(regs) &&
|
|
|
|
(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
restart_syscall = 1;
|
2008-04-24 04:01:48 -06:00
|
|
|
} else
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
restart_syscall = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-05-12 23:45:15 -06:00
|
|
|
if (current_thread_info()->status & TS_RESTORE_SIGMASK)
|
2006-01-19 03:42:49 -07:00
|
|
|
oldset = ¤t->saved_sigmask;
|
|
|
|
else
|
2005-04-16 16:20:36 -06:00
|
|
|
oldset = ¤t->blocked;
|
|
|
|
|
2008-04-26 04:17:12 -06:00
|
|
|
#ifdef CONFIG_COMPAT
|
2005-04-16 16:20:36 -06:00
|
|
|
if (test_thread_flag(TIF_32BIT)) {
|
2006-01-19 03:42:49 -07:00
|
|
|
extern void do_signal32(sigset_t *, struct pt_regs *,
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
int restart_syscall,
|
|
|
|
unsigned long orig_i0);
|
|
|
|
do_signal32(oldset, regs, restart_syscall, orig_i0);
|
2006-01-19 03:42:49 -07:00
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
|
|
|
|
|
|
|
|
/* If the debugger messes with the program counter, it clears
|
|
|
|
* the software "in syscall" bit, directing us to not perform
|
|
|
|
* a syscall restart.
|
|
|
|
*/
|
|
|
|
if (restart_syscall && !pt_regs_is_syscall(regs))
|
|
|
|
restart_syscall = 0;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (signr > 0) {
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
if (restart_syscall)
|
|
|
|
syscall_restart(orig_i0, regs, &ka.sa);
|
2005-04-16 16:20:36 -06:00
|
|
|
handle_signal(signr, &ka, &info, oldset, regs);
|
2006-01-19 03:42:49 -07:00
|
|
|
|
2008-05-12 23:45:15 -06:00
|
|
|
/* A signal was successfully delivered; the saved
|
2006-01-19 03:42:49 -07:00
|
|
|
* sigmask will have been stored in the signal frame,
|
|
|
|
* and will be restored by sigreturn, so we can simply
|
2008-05-12 23:45:15 -06:00
|
|
|
* clear the TS_RESTORE_SIGMASK flag.
|
2006-01-19 03:42:49 -07:00
|
|
|
*/
|
2008-05-12 23:45:15 -06:00
|
|
|
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
|
2006-01-19 03:42:49 -07:00
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
if (restart_syscall &&
|
2005-04-16 16:20:36 -06:00
|
|
|
(regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
|
|
|
|
regs->u_regs[UREG_I0] == ERESTARTSYS ||
|
|
|
|
regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
|
|
|
|
/* replay the system call when we are done */
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
regs->u_regs[UREG_I0] = orig_i0;
|
2005-04-16 16:20:36 -06:00
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
}
|
sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal. It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.
Problem is, this doesn't work.
The idea was that we should do the syscall restart business first, so
that the debugger captures that state. Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.
The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.
In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb. gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop(). The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal. But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.
Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:
1) Report a "in syscall" software bit in regs->{tstate,psr}.
It is set early on in trap entry to a system call and is fully
visible to the debugger via ptrace() and regsets.
2) Test this bit right before doing a syscall restart. We have
to do a final recheck right after get_signal_to_deliver() in
case the debugger cleared the bit during ptrace_stop().
3) Clear the bit in trap return so we don't accidently try to set
that bit in the real register.
As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.
M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook. It needs to be fixed in the same exact
way as sparc.
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 03:07:19 -06:00
|
|
|
if (restart_syscall &&
|
2005-04-16 16:20:36 -06:00
|
|
|
regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
|
|
|
|
regs->u_regs[UREG_G1] = __NR_restart_syscall;
|
|
|
|
regs->tpc -= 4;
|
|
|
|
regs->tnpc -= 4;
|
|
|
|
}
|
2006-01-19 03:42:49 -07:00
|
|
|
|
2008-05-12 23:45:15 -06:00
|
|
|
/* If there's no signal to deliver, we just put the saved sigmask
|
2006-01-19 03:42:49 -07:00
|
|
|
* back
|
|
|
|
*/
|
2008-05-12 23:45:15 -06:00
|
|
|
if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
|
|
|
|
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
|
2006-01-19 03:42:49 -07:00
|
|
|
sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-04-24 04:15:22 -06:00
|
|
|
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-05-12 23:45:15 -06:00
|
|
|
if (thread_info_flags & _TIF_SIGPENDING)
|
2008-04-24 04:01:48 -06:00
|
|
|
do_signal(regs, orig_i0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|