[POWERPC] Remove obsolete freezer bits
[deliverable/linux.git] / arch / powerpc / kernel / signal.c
CommitLineData
22e38f29
BH
1/*
2 * Common signal handling code for both 32 and 64 bits
3 *
4 * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration
5 * Extracted from signal_32.c and signal_64.c
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file README.legal in the main directory of
9 * this archive for more details.
10 */
11
12#include <linux/ptrace.h>
13#include <linux/signal.h>
14#include <asm/unistd.h>
15
db277e9a
CH
16#include "signal.h"
17
18
f478f543
CH
19#ifdef CONFIG_PPC64
20static inline int is_32bit_task(void)
21{
22 return test_thread_flag(TIF_32BIT);
23}
24#else
25static inline int is_32bit_task(void)
26{
27 return 1;
28}
29#endif
30
31
db277e9a
CH
32/*
33 * Restore the user process's signal mask
34 */
35void restore_sigmask(sigset_t *set)
36{
37 sigdelsetmask(set, ~_BLOCKABLE);
38 spin_lock_irq(&current->sighand->siglock);
39 current->blocked = *set;
40 recalc_sigpending();
41 spin_unlock_irq(&current->sighand->siglock);
42}
43
f478f543
CH
44static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
45 int has_handler)
22e38f29
BH
46{
47 unsigned long ret = regs->gpr[3];
48 int restart = 1;
49
50 /* syscall ? */
51 if (TRAP(regs) != 0x0C00)
52 return;
53
54 /* error signalled ? */
55 if (!(regs->ccr & 0x10000000))
56 return;
57
58 switch (ret) {
59 case ERESTART_RESTARTBLOCK:
60 case ERESTARTNOHAND:
61 /* ERESTARTNOHAND means that the syscall should only be
62 * restarted if there was no handler for the signal, and since
63 * we only get here if there is a handler, we dont restart.
64 */
65 restart = !has_handler;
66 break;
67 case ERESTARTSYS:
68 /* ERESTARTSYS means to restart the syscall if there is no
69 * handler or the handler was registered with SA_RESTART
70 */
71 restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
72 break;
73 case ERESTARTNOINTR:
74 /* ERESTARTNOINTR means that the syscall should be
75 * called again after the signal handler returns.
76 */
77 break;
78 default:
79 return;
80 }
81 if (restart) {
82 if (ret == ERESTART_RESTARTBLOCK)
83 regs->gpr[0] = __NR_restart_syscall;
84 else
85 regs->gpr[3] = regs->orig_gpr3;
86 regs->nip -= 4;
87 regs->result = 0;
88 } else {
89 regs->result = -EINTR;
90 regs->gpr[3] = EINTR;
91 regs->ccr |= 0x10000000;
92 }
93}
69d15f6b 94
f478f543
CH
95int do_signal(sigset_t *oldset, struct pt_regs *regs)
96{
97 siginfo_t info;
98 int signr;
99 struct k_sigaction ka;
100 int ret;
101 int is32 = is_32bit_task();
102
f478f543
CH
103 if (test_thread_flag(TIF_RESTORE_SIGMASK))
104 oldset = &current->saved_sigmask;
105 else if (!oldset)
106 oldset = &current->blocked;
107
108 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
109
f478f543
CH
110 /* Is there any syscall restart business here ? */
111 check_syscall_restart(regs, &ka, signr > 0);
112
113 if (signr <= 0) {
114 /* No signal to deliver -- put the saved sigmask back */
115 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
116 clear_thread_flag(TIF_RESTORE_SIGMASK);
117 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
118 }
119 return 0; /* no signals delivered */
120 }
121
122#ifdef CONFIG_PPC64
123 /*
124 * Reenable the DABR before delivering the signal to
125 * user space. The DABR will have been cleared if it
126 * triggered inside the kernel.
127 */
128 if (current->thread.dabr)
129 set_dabr(current->thread.dabr);
130#endif
131
132 if (is32) {
133 unsigned int newsp;
134
135 if ((ka.sa.sa_flags & SA_ONSTACK) &&
136 current->sas_ss_size && !on_sig_stack(regs->gpr[1]))
137 newsp = current->sas_ss_sp + current->sas_ss_size;
138 else
139 newsp = regs->gpr[1];
140
141 if (ka.sa.sa_flags & SA_SIGINFO)
142 ret = handle_rt_signal32(signr, &ka, &info, oldset,
143 regs, newsp);
144 else
145 ret = handle_signal32(signr, &ka, &info, oldset,
146 regs, newsp);
147#ifdef CONFIG_PPC64
148 } else {
149 ret = handle_rt_signal64(signr, &ka, &info, oldset, regs);
150#endif
151 }
152
153 if (ret) {
154 spin_lock_irq(&current->sighand->siglock);
155 sigorsets(&current->blocked, &current->blocked,
156 &ka.sa.sa_mask);
157 if (!(ka.sa.sa_flags & SA_NODEFER))
158 sigaddset(&current->blocked, signr);
159 recalc_sigpending();
160 spin_unlock_irq(&current->sighand->siglock);
161
162 /*
163 * A signal was successfully delivered; the saved sigmask is in
164 * its frame, and we can clear the TIF_RESTORE_SIGMASK flag.
165 */
166 if (test_thread_flag(TIF_RESTORE_SIGMASK))
167 clear_thread_flag(TIF_RESTORE_SIGMASK);
168 }
169
170 return ret;
171}
172
69d15f6b
CH
173long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
174 unsigned long r5, unsigned long r6, unsigned long r7,
175 unsigned long r8, struct pt_regs *regs)
176{
177 return do_sigaltstack(uss, uoss, regs->gpr[1]);
178}
This page took 0.030748 seconds and 5 git commands to generate.