2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include "linux/config.h"
7 #include "linux/stddef.h"
9 #include "linux/sched.h"
10 #include "linux/wait.h"
11 #include "linux/kernel.h"
12 #include "linux/smp_lock.h"
13 #include "linux/module.h"
14 #include "linux/slab.h"
15 #include "linux/tty.h"
16 #include "linux/binfmts.h"
17 #include "linux/ptrace.h"
18 #include "asm/signal.h"
19 #include "asm/uaccess.h"
20 #include "asm/unistd.h"
21 #include "user_util.h"
22 #include "asm/ucontext.h"
23 #include "kern_util.h"
24 #include "signal_kern.h"
25 #include "signal_user.h"
27 #include "frame_kern.h"
28 #include "sigcontext.h"
31 EXPORT_SYMBOL(block_signals);
32 EXPORT_SYMBOL(unblock_signals);
34 #define _S(nr) (1<<((nr)-1))
36 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
39 * OK, we're invoking a handler
41 static int handle_signal(struct pt_regs *regs, unsigned long signr,
42 struct k_sigaction *ka, siginfo_t *info,
48 /* Always make any pending restarted system calls return -EINTR */
49 current_thread_info()->restart_block.fn = do_no_restart_syscall;
51 /* Did we come from a system call? */
52 if(PT_REGS_SYSCALL_NR(regs) >= 0){
53 /* If so, check system call restarting.. */
54 switch(PT_REGS_SYSCALL_RET(regs)){
55 case -ERESTART_RESTARTBLOCK:
57 PT_REGS_SYSCALL_RET(regs) = -EINTR;
61 if (!(ka->sa.sa_flags & SA_RESTART)) {
62 PT_REGS_SYSCALL_RET(regs) = -EINTR;
67 PT_REGS_RESTART_SYSCALL(regs);
68 PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
73 sp = PT_REGS_SP(regs);
74 if((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
75 sp = current->sas_ss_sp + current->sas_ss_size;
77 #ifdef CONFIG_ARCH_HAS_SC_SIGNALS
78 if(!(ka->sa.sa_flags & SA_SIGINFO))
79 err = setup_signal_stack_sc(sp, signr, ka, regs, oldset);
82 err = setup_signal_stack_si(sp, signr, ka, regs, info, oldset);
85 spin_lock_irq(¤t->sighand->siglock);
86 current->blocked = *oldset;
88 spin_unlock_irq(¤t->sighand->siglock);
89 force_sigsegv(signr, current);
91 else if(!(ka->sa.sa_flags & SA_NODEFER)){
92 spin_lock_irq(¤t->sighand->siglock);
93 sigorsets(¤t->blocked, ¤t->blocked,
95 sigaddset(¤t->blocked, signr);
97 spin_unlock_irq(¤t->sighand->siglock);
103 static int kern_do_signal(struct pt_regs *regs, sigset_t *oldset)
105 struct k_sigaction ka_copy;
107 int sig, handled_sig = 0;
109 while((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0){
111 /* Whee! Actually deliver the signal. */
112 if(!handle_signal(regs, sig, &ka_copy, &info, oldset))
116 /* Did we come from a system call? */
117 if(!handled_sig && (PT_REGS_SYSCALL_NR(regs) >= 0)){
118 /* Restart the system call - no handlers present */
119 if(PT_REGS_SYSCALL_RET(regs) == -ERESTARTNOHAND ||
120 PT_REGS_SYSCALL_RET(regs) == -ERESTARTSYS ||
121 PT_REGS_SYSCALL_RET(regs) == -ERESTARTNOINTR){
122 PT_REGS_ORIG_SYSCALL(regs) = PT_REGS_SYSCALL_NR(regs);
123 PT_REGS_RESTART_SYSCALL(regs);
125 else if(PT_REGS_SYSCALL_RET(regs) == -ERESTART_RESTARTBLOCK){
126 PT_REGS_SYSCALL_RET(regs) = __NR_restart_syscall;
127 PT_REGS_RESTART_SYSCALL(regs);
131 /* This closes a way to execute a system call on the host. If
132 * you set a breakpoint on a system call instruction and singlestep
133 * from it, the tracing thread used to PTRACE_SINGLESTEP the process
134 * rather than PTRACE_SYSCALL it, allowing the system call to execute
135 * on the host. The tracing thread will check this flag and
136 * PTRACE_SYSCALL if necessary.
138 if(current->ptrace & PT_DTRACE)
139 current->thread.singlestep_syscall =
140 is_syscall(PT_REGS_IP(¤t->thread.regs));
146 return(kern_do_signal(¤t->thread.regs, ¤t->blocked));
150 * Atomically swap in the new signal mask, and wait for a signal.
152 long sys_sigsuspend(int history0, int history1, old_sigset_t mask)
157 spin_lock_irq(¤t->sighand->siglock);
158 saveset = current->blocked;
159 siginitset(¤t->blocked, mask);
161 spin_unlock_irq(¤t->sighand->siglock);
163 PT_REGS_SYSCALL_RET(¤t->thread.regs) = -EINTR;
165 current->state = TASK_INTERRUPTIBLE;
167 if(kern_do_signal(¤t->thread.regs, &saveset))
172 long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize)
174 sigset_t saveset, newset;
176 /* XXX: Don't preclude handling different sized sigset_t's. */
177 if (sigsetsize != sizeof(sigset_t))
180 if (copy_from_user(&newset, unewset, sizeof(newset)))
182 sigdelsetmask(&newset, ~_BLOCKABLE);
184 spin_lock_irq(¤t->sighand->siglock);
185 saveset = current->blocked;
186 current->blocked = newset;
188 spin_unlock_irq(¤t->sighand->siglock);
190 PT_REGS_SYSCALL_RET(¤t->thread.regs) = -EINTR;
192 current->state = TASK_INTERRUPTIBLE;
194 if (kern_do_signal(¤t->thread.regs, &saveset))
199 long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
201 return(do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs)));
205 * Overrides for Emacs so that we follow Linus's tabbing style.
206 * Emacs will notice this stuff at the end of the file and automatically
207 * adjust the settings for this buffer only. This must remain at the end
209 * ---------------------------------------------------------------------------
211 * c-file-style: "linux"