all arches, signal: move restart_block to struct task_struct
[deliverable/linux.git] / arch / blackfin / kernel / signal.c
CommitLineData
1394f032 1/*
e8f263df 2 * Copyright 2004-2010 Analog Devices Inc.
1394f032 3 *
96f1050d 4 * Licensed under the GPL-2 or later
1394f032
BW
5 */
6
7#include <linux/signal.h>
8#include <linux/syscalls.h>
9#include <linux/ptrace.h>
10#include <linux/tty.h>
11#include <linux/personality.h>
12#include <linux/binfmts.h>
1f83b8f1 13#include <linux/uaccess.h>
d1be2e48 14#include <linux/tracehook.h>
1394f032 15
1394f032
BW
16#include <asm/cacheflush.h>
17#include <asm/ucontext.h>
697a9d65 18#include <asm/fixed_code.h>
ddaebcab 19#include <asm/syscall.h>
1394f032 20
8513c42e
BS
21/* Location of the trace bit in SYSCFG. */
22#define TRACE_BITS 0x0001
23
1394f032
BW
24struct fdpic_func_descriptor {
25 unsigned long text;
26 unsigned long GOT;
27};
28
29struct rt_sigframe {
30 int sig;
31 struct siginfo *pinfo;
32 void *puc;
697a9d65
BS
33 /* This is no longer needed by the kernel, but unfortunately userspace
34 * code expects it to be there. */
1394f032
BW
35 char retcode[8];
36 struct siginfo info;
37 struct ucontext uc;
38};
39
1394f032 40static inline int
0ddeeca2 41rt_restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *pr0)
1394f032
BW
42{
43 unsigned long usp = 0;
44 int err = 0;
45
ddaebcab 46 /* Always make any pending restarted system calls return -EINTR */
f56141e3 47 current->restart_block.fn = do_no_restart_syscall;
ddaebcab 48
1394f032
BW
49#define RESTORE(x) err |= __get_user(regs->x, &sc->sc_##x)
50
51 /* restore passed registers */
52 RESTORE(r0); RESTORE(r1); RESTORE(r2); RESTORE(r3);
53 RESTORE(r4); RESTORE(r5); RESTORE(r6); RESTORE(r7);
54 RESTORE(p0); RESTORE(p1); RESTORE(p2); RESTORE(p3);
55 RESTORE(p4); RESTORE(p5);
56 err |= __get_user(usp, &sc->sc_usp);
57 wrusp(usp);
58 RESTORE(a0w); RESTORE(a1w);
59 RESTORE(a0x); RESTORE(a1x);
60 RESTORE(astat);
61 RESTORE(rets);
62 RESTORE(pc);
63 RESTORE(retx);
64 RESTORE(fp);
65 RESTORE(i0); RESTORE(i1); RESTORE(i2); RESTORE(i3);
66 RESTORE(m0); RESTORE(m1); RESTORE(m2); RESTORE(m3);
67 RESTORE(l0); RESTORE(l1); RESTORE(l2); RESTORE(l3);
68 RESTORE(b0); RESTORE(b1); RESTORE(b2); RESTORE(b3);
69 RESTORE(lc0); RESTORE(lc1);
70 RESTORE(lt0); RESTORE(lt1);
71 RESTORE(lb0); RESTORE(lb1);
72 RESTORE(seqstat);
73
74 regs->orig_p0 = -1; /* disable syscall checks */
75
76 *pr0 = regs->r0;
77 return err;
78}
79
135c37b8 80asmlinkage int sys_rt_sigreturn(void)
1394f032 81{
135c37b8 82 struct pt_regs *regs = current_pt_regs();
1394f032
BW
83 unsigned long usp = rdusp();
84 struct rt_sigframe *frame = (struct rt_sigframe *)(usp);
85 sigset_t set;
86 int r0;
87
88 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
89 goto badframe;
90 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
91 goto badframe;
92
8e3f9f65 93 set_current_blocked(&set);
1394f032
BW
94
95 if (rt_restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
96 goto badframe;
97
79d43210 98 if (restore_altstack(&frame->uc.uc_stack))
1394f032
BW
99 goto badframe;
100
101 return r0;
102
1f83b8f1 103 badframe:
1394f032
BW
104 force_sig(SIGSEGV, current);
105 return 0;
106}
107
108static inline int rt_setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs)
109{
110 int err = 0;
111
112#define SETUP(x) err |= __put_user(regs->x, &sc->sc_##x)
113
114 SETUP(r0); SETUP(r1); SETUP(r2); SETUP(r3);
115 SETUP(r4); SETUP(r5); SETUP(r6); SETUP(r7);
116 SETUP(p0); SETUP(p1); SETUP(p2); SETUP(p3);
117 SETUP(p4); SETUP(p5);
118 err |= __put_user(rdusp(), &sc->sc_usp);
119 SETUP(a0w); SETUP(a1w);
120 SETUP(a0x); SETUP(a1x);
121 SETUP(astat);
122 SETUP(rets);
123 SETUP(pc);
124 SETUP(retx);
125 SETUP(fp);
126 SETUP(i0); SETUP(i1); SETUP(i2); SETUP(i3);
127 SETUP(m0); SETUP(m1); SETUP(m2); SETUP(m3);
128 SETUP(l0); SETUP(l1); SETUP(l2); SETUP(l3);
129 SETUP(b0); SETUP(b1); SETUP(b2); SETUP(b3);
130 SETUP(lc0); SETUP(lc1);
131 SETUP(lt0); SETUP(lt1);
132 SETUP(lb0); SETUP(lb1);
133 SETUP(seqstat);
134
135 return err;
136}
137
e90670a9 138static inline void *get_sigframe(struct ksignal *ksig,
1394f032
BW
139 size_t frame_size)
140{
e90670a9 141 unsigned long usp = sigsp(rdusp(), ksig);
1394f032 142
1394f032
BW
143 return (void *)((usp - frame_size) & -8UL);
144}
145
146static int
1270cff1 147setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
1394f032
BW
148{
149 struct rt_sigframe *frame;
150 int err = 0;
151
e90670a9 152 frame = get_sigframe(ksig, sizeof(*frame));
1394f032
BW
153
154 err |= __put_user((current_thread_info()->exec_domain
155 && current_thread_info()->exec_domain->signal_invmap
1270cff1 156 && ksig->sig < 32
1394f032 157 ? current_thread_info()->exec_domain->
1270cff1 158 signal_invmap[ksig->sig] : ksig->sig), &frame->sig);
1394f032
BW
159
160 err |= __put_user(&frame->info, &frame->pinfo);
161 err |= __put_user(&frame->uc, &frame->puc);
1270cff1 162 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
1394f032
BW
163
164 /* Create the ucontext. */
165 err |= __put_user(0, &frame->uc.uc_flags);
166 err |= __put_user(0, &frame->uc.uc_link);
79d43210 167 err |= __save_altstack(&frame->uc.uc_stack, rdusp());
1394f032
BW
168 err |= rt_setup_sigcontext(&frame->uc.uc_mcontext, regs);
169 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
170
1394f032 171 if (err)
29bf5dd8 172 return -EFAULT;
1394f032 173
1394f032 174 /* Set up registers for signal handler */
ecd0fa98 175 if (current->personality & FDPIC_FUNCPTRS) {
1394f032 176 struct fdpic_func_descriptor __user *funcptr =
1270cff1 177 (struct fdpic_func_descriptor *) ksig->ka.sa.sa_handler;
29bf5dd8
AV
178 u32 pc, p3;
179 err |= __get_user(pc, &funcptr->text);
180 err |= __get_user(p3, &funcptr->GOT);
181 if (err)
182 return -EFAULT;
183 regs->pc = pc;
184 regs->p3 = p3;
1394f032 185 } else
1270cff1 186 regs->pc = (unsigned long)ksig->ka.sa.sa_handler;
29bf5dd8 187 wrusp((unsigned long)frame);
697a9d65 188 regs->rets = SIGRETURN_STUB;
1394f032
BW
189
190 regs->r0 = frame->sig;
191 regs->r1 = (unsigned long)(&frame->info);
192 regs->r2 = (unsigned long)(&frame->uc);
193
194 return 0;
1394f032
BW
195}
196
197static inline void
198handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
199{
200 switch (regs->r0) {
201 case -ERESTARTNOHAND:
202 if (!has_handler)
203 goto do_restart;
204 regs->r0 = -EINTR;
205 break;
206
207 case -ERESTARTSYS:
208 if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
209 regs->r0 = -EINTR;
210 break;
211 }
212 /* fallthrough */
213 case -ERESTARTNOINTR:
1f83b8f1 214 do_restart:
1394f032
BW
215 regs->p0 = regs->orig_p0;
216 regs->r0 = regs->orig_r0;
217 regs->pc -= 2;
218 break;
ddaebcab
MF
219
220 case -ERESTART_RESTARTBLOCK:
221 regs->p0 = __NR_restart_syscall;
222 regs->pc -= 2;
223 break;
1394f032
BW
224 }
225}
226
227/*
228 * OK, we're invoking a handler
229 */
a610d6e6 230static void
1270cff1 231handle_signal(struct ksignal *ksig, struct pt_regs *regs)
1394f032 232{
1270cff1
RW
233 int ret;
234
1394f032
BW
235 /* are we from a system call? to see pt_regs->orig_p0 */
236 if (regs->orig_p0 >= 0)
237 /* If so, check system call restarting.. */
1270cff1 238 handle_restart(regs, &ksig->ka, 1);
1394f032
BW
239
240 /* set up the stack frame */
1270cff1
RW
241 ret = setup_rt_frame(ksig, sigmask_to_save(), regs);
242
243 signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
1394f032
BW
244}
245
246/*
247 * Note that 'init' is a special process: it doesn't get signals it doesn't
248 * want to handle. Thus you cannot kill init even with a SIGKILL even by
249 * mistake.
250 *
251 * Note that we go through the signals twice: once to check the signals
252 * that the kernel can handle, and then we build all the user-level signal
253 * handling stack-frames in one go after that.
254 */
255asmlinkage void do_signal(struct pt_regs *regs)
256{
1270cff1 257 struct ksignal ksig;
1394f032
BW
258
259 current->thread.esp0 = (unsigned long)regs;
260
1270cff1 261 if (get_signal(&ksig)) {
1394f032 262 /* Whee! Actually deliver the signal. */
1270cff1 263 handle_signal(&ksig, regs);
1394f032
BW
264 return;
265 }
266
1394f032
BW
267 /* Did we come from a system call? */
268 if (regs->orig_p0 >= 0)
269 /* Restart the system call - no handlers present */
270 handle_restart(regs, NULL, 0);
271
272 /* if there's no signal to deliver, we just put the saved sigmask
273 * back */
51a7b448 274 restore_saved_sigmask();
1394f032 275}
d1be2e48
BS
276
277/*
278 * notification of userspace execution resumption
279 */
280asmlinkage void do_notify_resume(struct pt_regs *regs)
281{
6fd84c08 282 if (test_thread_flag(TIF_SIGPENDING))
d1be2e48
BS
283 do_signal(regs);
284
285 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
286 clear_thread_flag(TIF_NOTIFY_RESUME);
287 tracehook_notify_resume(regs);
d1be2e48
BS
288 }
289}
290
This page took 0.500601 seconds and 5 git commands to generate.