2006-07-10 05:45:13 -06:00
|
|
|
/*
|
2007-10-16 02:27:00 -06:00
|
|
|
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-04-16 16:20:36 -06:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
2008-02-04 23:31:14 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <asm/siginfo.h>
|
|
|
|
#include <asm/signal.h>
|
|
|
|
#include <asm/unistd.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include "frame_kern.h"
|
2007-10-16 02:27:00 -06:00
|
|
|
#include "kern_util.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(block_signals);
|
|
|
|
EXPORT_SYMBOL(unblock_signals);
|
|
|
|
|
|
|
|
#define _S(nr) (1<<((nr)-1))
|
|
|
|
|
|
|
|
#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OK, we're invoking a handler
|
2006-07-10 05:45:13 -06:00
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
static int handle_signal(struct pt_regs *regs, unsigned long signr,
|
|
|
|
struct k_sigaction *ka, siginfo_t *info,
|
|
|
|
sigset_t *oldset)
|
|
|
|
{
|
|
|
|
unsigned long sp;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Always make any pending restarted system calls return -EINTR */
|
|
|
|
current_thread_info()->restart_block.fn = do_no_restart_syscall;
|
|
|
|
|
|
|
|
/* Did we come from a system call? */
|
2007-10-16 02:27:00 -06:00
|
|
|
if (PT_REGS_SYSCALL_NR(regs) >= 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* If so, check system call restarting.. */
|
2008-02-04 23:31:14 -07:00
|
|
|
switch (PT_REGS_SYSCALL_RET(regs)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
case -ERESTART_RESTARTBLOCK:
|
|
|
|
case -ERESTARTNOHAND:
|
|
|
|
PT_REGS_SYSCALL_RET(regs) = -EINTR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -ERESTARTSYS:
|
|
|
|
if (!(ka->sa.sa_flags & SA_RESTART)) {
|
|
|
|
PT_REGS_SYSCALL_RET(regs) = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
|
|
|
case -ERESTARTNOINTR:
|
|
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
|
|
|
PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sp = PT_REGS_SP(regs);
|
2007-10-16 02:27:00 -06:00
|
|
|
if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
|
2005-04-16 16:20:36 -06:00
|
|
|
sp = current->sas_ss_sp + current->sas_ss_size;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAS_SC_SIGNALS
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!(ka->sa.sa_flags & SA_SIGINFO))
|
2005-04-16 16:20:36 -06:00
|
|
|
err = setup_signal_stack_sc(sp, signr, ka, regs, oldset);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
err = setup_signal_stack_si(sp, signr, ka, regs, info, oldset);
|
|
|
|
|
2012-03-23 16:01:49 -06:00
|
|
|
if (err)
|
2005-04-16 16:20:36 -06:00
|
|
|
force_sigsegv(signr, current);
|
2012-03-23 16:01:49 -06:00
|
|
|
else {
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
2006-07-10 05:45:13 -06:00
|
|
|
sigorsets(¤t->blocked, ¤t->blocked,
|
2005-04-16 16:20:36 -06:00
|
|
|
&ka->sa.sa_mask);
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!(ka->sa.sa_flags & SA_NODEFER))
|
[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
|
|
|
sigaddset(¤t->blocked, signr);
|
2005-04-16 16:20:36 -06:00
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-01-18 18:44:02 -07:00
|
|
|
static int kern_do_signal(struct pt_regs *regs)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct k_sigaction ka_copy;
|
|
|
|
siginfo_t info;
|
2006-01-18 18:44:02 -07:00
|
|
|
sigset_t *oldset;
|
2005-04-16 16:20:36 -06:00
|
|
|
int sig, handled_sig = 0;
|
|
|
|
|
2006-01-18 18:44:02 -07:00
|
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK))
|
|
|
|
oldset = ¤t->saved_sigmask;
|
|
|
|
else
|
|
|
|
oldset = ¤t->blocked;
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) {
|
2005-04-16 16:20:36 -06:00
|
|
|
handled_sig = 1;
|
|
|
|
/* Whee! Actually deliver the signal. */
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!handle_signal(regs, sig, &ka_copy, &info, oldset)) {
|
|
|
|
/*
|
|
|
|
* a signal was successfully delivered; the saved
|
2006-01-18 18:44:02 -07:00
|
|
|
* sigmask will have been stored in the signal frame,
|
|
|
|
* and will be restored by sigreturn, so we can simply
|
2007-10-16 02:27:00 -06:00
|
|
|
* clear the TIF_RESTORE_SIGMASK flag
|
|
|
|
*/
|
2006-01-18 18:44:02 -07:00
|
|
|
if (test_thread_flag(TIF_RESTORE_SIGMASK))
|
|
|
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
2006-01-18 18:44:02 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we come from a system call? */
|
2007-10-16 02:27:00 -06:00
|
|
|
if (!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Restart the system call - no handlers present */
|
2008-02-04 23:31:14 -07:00
|
|
|
switch (PT_REGS_SYSCALL_RET(regs)) {
|
2006-01-18 18:44:02 -07:00
|
|
|
case -ERESTARTNOHAND:
|
|
|
|
case -ERESTARTSYS:
|
|
|
|
case -ERESTARTNOINTR:
|
2005-04-16 16:20:36 -06:00
|
|
|
PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
|
|
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
2006-01-18 18:44:02 -07:00
|
|
|
break;
|
|
|
|
case -ERESTART_RESTARTBLOCK:
|
2006-07-10 05:45:13 -06:00
|
|
|
PT_REGS_ORIG_SYSCALL(regs) = __NR_restart_syscall;
|
2005-04-16 16:20:36 -06:00
|
|
|
PT_REGS_RESTART_SYSCALL(regs);
|
2006-01-18 18:44:02 -07:00
|
|
|
break;
|
2007-10-16 02:27:00 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
/*
|
|
|
|
* This closes a way to execute a system call on the host. If
|
2005-04-16 16:20:36 -06:00
|
|
|
* you set a breakpoint on a system call instruction and singlestep
|
|
|
|
* from it, the tracing thread used to PTRACE_SINGLESTEP the process
|
|
|
|
* rather than PTRACE_SYSCALL it, allowing the system call to execute
|
2006-07-10 05:45:13 -06:00
|
|
|
* on the host. The tracing thread will check this flag and
|
2005-04-16 16:20:36 -06:00
|
|
|
* PTRACE_SYSCALL if necessary.
|
|
|
|
*/
|
2007-10-16 02:27:00 -06:00
|
|
|
if (current->ptrace & PT_DTRACE)
|
2005-04-16 16:20:36 -06:00
|
|
|
current->thread.singlestep_syscall =
|
|
|
|
is_syscall(PT_REGS_IP(¤t->thread.regs));
|
2006-01-18 18:44:02 -07:00
|
|
|
|
2007-10-16 02:27:00 -06:00
|
|
|
/*
|
|
|
|
* if there's no signal to deliver, we just put the saved sigmask
|
|
|
|
* back
|
|
|
|
*/
|
2006-01-18 18:44:02 -07:00
|
|
|
if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) {
|
|
|
|
clear_thread_flag(TIF_RESTORE_SIGMASK);
|
|
|
|
sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
|
|
|
|
}
|
2007-03-06 02:42:18 -07:00
|
|
|
return handled_sig;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int do_signal(void)
|
|
|
|
{
|
2007-03-06 02:42:18 -07:00
|
|
|
return kern_do_signal(¤t->thread.regs);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Atomically swap in the new signal mask, and wait for a signal.
|
|
|
|
*/
|
|
|
|
long sys_sigsuspend(int history0, int history1, old_sigset_t mask)
|
|
|
|
{
|
|
|
|
mask &= _BLOCKABLE;
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
2006-01-18 18:44:02 -07:00
|
|
|
current->saved_sigmask = current->blocked;
|
2005-04-16 16:20:36 -06:00
|
|
|
siginitset(¤t->blocked, mask);
|
|
|
|
recalc_sigpending();
|
|
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
|
2006-01-18 18:44:02 -07:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
schedule();
|
|
|
|
set_thread_flag(TIF_RESTORE_SIGMASK);
|
|
|
|
return -ERESTARTNOHAND;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
|
|
|
|
{
|
2007-03-06 02:42:18 -07:00
|
|
|
return do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|