]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/m32r/kernel/signal.c | |
3 | * | |
4 | * Copyright (c) 2003 Hitoshi Yamamoto | |
5 | * | |
6 | * Taken from i386 version. | |
7 | * Copyright (C) 1991, 1992 Linus Torvalds | |
8 | * | |
9 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | |
10 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes | |
11 | */ | |
12 | ||
1da177e4 LT |
13 | #include <linux/sched.h> |
14 | #include <linux/mm.h> | |
15 | #include <linux/smp.h> | |
1da177e4 LT |
16 | #include <linux/kernel.h> |
17 | #include <linux/signal.h> | |
18 | #include <linux/errno.h> | |
19 | #include <linux/wait.h> | |
20 | #include <linux/unistd.h> | |
21 | #include <linux/stddef.h> | |
22 | #include <linux/personality.h> | |
7dfb7103 | 23 | #include <linux/freezer.h> |
733e5e4b | 24 | #include <linux/tracehook.h> |
1da177e4 LT |
25 | #include <asm/cacheflush.h> |
26 | #include <asm/ucontext.h> | |
27 | #include <asm/uaccess.h> | |
28 | ||
29 | #define DEBUG_SIG 0 | |
30 | ||
1da177e4 LT |
31 | asmlinkage int |
32 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | |
33 | unsigned long r2, unsigned long r3, unsigned long r4, | |
6ced13cd | 34 | unsigned long r5, unsigned long r6, struct pt_regs *regs) |
1da177e4 | 35 | { |
6ced13cd | 36 | return do_sigaltstack(uss, uoss, regs->spu); |
1da177e4 LT |
37 | } |
38 | ||
39 | ||
40 | /* | |
41 | * Do a signal return; undo the signal stack. | |
42 | */ | |
43 | ||
44 | struct rt_sigframe | |
45 | { | |
46 | int sig; | |
870e75a2 AV |
47 | struct siginfo __user *pinfo; |
48 | void __user *puc; | |
1da177e4 LT |
49 | struct siginfo info; |
50 | struct ucontext uc; | |
51 | // struct _fpstate fpstate; | |
52 | }; | |
53 | ||
54 | static int | |
55 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, | |
56 | int *r0_p) | |
57 | { | |
58 | unsigned int err = 0; | |
59 | ||
60 | /* Always make any pending restarted system calls return -EINTR */ | |
61 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | |
62 | ||
63 | #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x) | |
64 | COPY(r4); | |
65 | COPY(r5); | |
66 | COPY(r6); | |
67 | COPY(pt_regs); | |
68 | /* COPY(r0); Skip r0 */ | |
69 | COPY(r1); | |
70 | COPY(r2); | |
71 | COPY(r3); | |
72 | COPY(r7); | |
73 | COPY(r8); | |
74 | COPY(r9); | |
75 | COPY(r10); | |
76 | COPY(r11); | |
77 | COPY(r12); | |
1da177e4 LT |
78 | COPY(acc0h); |
79 | COPY(acc0l); | |
9674dcf7 HT |
80 | COPY(acc1h); /* ISA_DSP_LEVEL2 only */ |
81 | COPY(acc1l); /* ISA_DSP_LEVEL2 only */ | |
1da177e4 LT |
82 | COPY(psw); |
83 | COPY(bpc); | |
84 | COPY(bbpsw); | |
85 | COPY(bbpc); | |
86 | COPY(spu); | |
87 | COPY(fp); | |
88 | COPY(lr); | |
89 | COPY(spi); | |
90 | #undef COPY | |
91 | ||
92 | regs->syscall_nr = -1; /* disable syscall checks */ | |
93 | err |= __get_user(*r0_p, &sc->sc_r0); | |
94 | ||
95 | return err; | |
96 | } | |
97 | ||
98 | asmlinkage int | |
99 | sys_rt_sigreturn(unsigned long r0, unsigned long r1, | |
100 | unsigned long r2, unsigned long r3, unsigned long r4, | |
6ced13cd | 101 | unsigned long r5, unsigned long r6, struct pt_regs *regs) |
1da177e4 | 102 | { |
6ced13cd | 103 | struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->spu; |
1da177e4 | 104 | sigset_t set; |
1da177e4 LT |
105 | int result; |
106 | ||
107 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | |
108 | goto badframe; | |
109 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | |
110 | goto badframe; | |
111 | ||
112 | sigdelsetmask(&set, ~_BLOCKABLE); | |
113 | spin_lock_irq(¤t->sighand->siglock); | |
114 | current->blocked = set; | |
115 | recalc_sigpending(); | |
116 | spin_unlock_irq(¤t->sighand->siglock); | |
117 | ||
6ced13cd | 118 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result)) |
1da177e4 LT |
119 | goto badframe; |
120 | ||
6ced13cd | 121 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->spu) == -EFAULT) |
1da177e4 | 122 | goto badframe; |
1da177e4 LT |
123 | |
124 | return result; | |
125 | ||
126 | badframe: | |
127 | force_sig(SIGSEGV, current); | |
128 | return 0; | |
129 | } | |
130 | ||
131 | /* | |
132 | * Set up a signal frame. | |
133 | */ | |
134 | ||
135 | static int | |
136 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, | |
137 | unsigned long mask) | |
138 | { | |
139 | int err = 0; | |
140 | ||
141 | #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x) | |
142 | COPY(r4); | |
143 | COPY(r5); | |
144 | COPY(r6); | |
145 | COPY(pt_regs); | |
146 | COPY(r0); | |
147 | COPY(r1); | |
148 | COPY(r2); | |
149 | COPY(r3); | |
150 | COPY(r7); | |
151 | COPY(r8); | |
152 | COPY(r9); | |
153 | COPY(r10); | |
154 | COPY(r11); | |
155 | COPY(r12); | |
1da177e4 LT |
156 | COPY(acc0h); |
157 | COPY(acc0l); | |
9674dcf7 HT |
158 | COPY(acc1h); /* ISA_DSP_LEVEL2 only */ |
159 | COPY(acc1l); /* ISA_DSP_LEVEL2 only */ | |
1da177e4 LT |
160 | COPY(psw); |
161 | COPY(bpc); | |
162 | COPY(bbpsw); | |
163 | COPY(bbpc); | |
164 | COPY(spu); | |
165 | COPY(fp); | |
166 | COPY(lr); | |
167 | COPY(spi); | |
168 | #undef COPY | |
169 | ||
170 | err |= __put_user(mask, &sc->oldmask); | |
171 | ||
172 | return err; | |
173 | } | |
174 | ||
175 | /* | |
176 | * Determine which stack to use.. | |
177 | */ | |
178 | static inline void __user * | |
179 | get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) | |
180 | { | |
181 | /* This is the X/Open sanctioned signal stack switching. */ | |
182 | if (ka->sa.sa_flags & SA_ONSTACK) { | |
183 | if (sas_ss_flags(sp) == 0) | |
184 | sp = current->sas_ss_sp + current->sas_ss_size; | |
185 | } | |
186 | ||
187 | return (void __user *)((sp - frame_size) & -8ul); | |
188 | } | |
189 | ||
a05c4e1d | 190 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
1da177e4 LT |
191 | sigset_t *set, struct pt_regs *regs) |
192 | { | |
193 | struct rt_sigframe __user *frame; | |
194 | int err = 0; | |
195 | int signal; | |
196 | ||
197 | frame = get_sigframe(ka, regs->spu, sizeof(*frame)); | |
198 | ||
199 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | |
200 | goto give_sigsegv; | |
201 | ||
202 | signal = current_thread_info()->exec_domain | |
203 | && current_thread_info()->exec_domain->signal_invmap | |
204 | && sig < 32 | |
205 | ? current_thread_info()->exec_domain->signal_invmap[sig] | |
206 | : sig; | |
207 | ||
208 | err |= __put_user(signal, &frame->sig); | |
209 | if (err) | |
210 | goto give_sigsegv; | |
211 | ||
212 | err |= __put_user(&frame->info, &frame->pinfo); | |
213 | err |= __put_user(&frame->uc, &frame->puc); | |
214 | err |= copy_siginfo_to_user(&frame->info, info); | |
215 | if (err) | |
216 | goto give_sigsegv; | |
217 | ||
218 | /* Create the ucontext. */ | |
219 | err |= __put_user(0, &frame->uc.uc_flags); | |
220 | err |= __put_user(0, &frame->uc.uc_link); | |
221 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | |
222 | err |= __put_user(sas_ss_flags(regs->spu), | |
223 | &frame->uc.uc_stack.ss_flags); | |
224 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); | |
225 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]); | |
226 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | |
227 | if (err) | |
228 | goto give_sigsegv; | |
229 | ||
230 | /* Set up to return from userspace. */ | |
231 | regs->lr = (unsigned long)ka->sa.sa_restorer; | |
232 | ||
233 | /* Set up registers for signal handler */ | |
234 | regs->spu = (unsigned long)frame; | |
235 | regs->r0 = signal; /* Arg for signal handler */ | |
236 | regs->r1 = (unsigned long)&frame->info; | |
237 | regs->r2 = (unsigned long)&frame->uc; | |
238 | regs->bpc = (unsigned long)ka->sa.sa_handler; | |
239 | ||
240 | set_fs(USER_DS); | |
241 | ||
242 | #if DEBUG_SIG | |
243 | printk("SIG deliver (%s:%d): sp=%p pc=%p\n", | |
244 | current->comm, current->pid, frame, regs->pc); | |
245 | #endif | |
246 | ||
a05c4e1d | 247 | return 0; |
1da177e4 LT |
248 | |
249 | give_sigsegv: | |
250 | force_sigsegv(sig, current); | |
a05c4e1d | 251 | return -EFAULT; |
1da177e4 LT |
252 | } |
253 | ||
254 | /* | |
255 | * OK, we're invoking a handler | |
256 | */ | |
257 | ||
a05c4e1d | 258 | static int |
1da177e4 LT |
259 | handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, |
260 | sigset_t *oldset, struct pt_regs *regs) | |
261 | { | |
262 | unsigned short inst; | |
263 | ||
264 | /* Are we from a system call? */ | |
265 | if (regs->syscall_nr >= 0) { | |
266 | /* If so, check system call restarting.. */ | |
267 | switch (regs->r0) { | |
268 | case -ERESTART_RESTARTBLOCK: | |
269 | case -ERESTARTNOHAND: | |
270 | regs->r0 = -EINTR; | |
271 | break; | |
272 | ||
273 | case -ERESTARTSYS: | |
274 | if (!(ka->sa.sa_flags & SA_RESTART)) { | |
275 | regs->r0 = -EINTR; | |
276 | break; | |
277 | } | |
278 | /* fallthrough */ | |
279 | case -ERESTARTNOINTR: | |
280 | regs->r0 = regs->orig_r0; | |
281 | inst = *(unsigned short *)(regs->bpc - 2); | |
282 | if ((inst & 0xfff0) == 0x10f0) /* trap ? */ | |
283 | regs->bpc -= 2; | |
284 | else | |
285 | regs->bpc -= 4; | |
a7481024 | 286 | regs->syscall_nr = -1; |
1da177e4 LT |
287 | } |
288 | } | |
289 | ||
290 | /* Set up the stack frame */ | |
a05c4e1d AV |
291 | if (setup_rt_frame(sig, ka, info, oldset, regs)) |
292 | return -EFAULT; | |
1da177e4 | 293 | |
69be8f18 SR |
294 | spin_lock_irq(¤t->sighand->siglock); |
295 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | |
296 | if (!(ka->sa.sa_flags & SA_NODEFER)) | |
1da177e4 | 297 | sigaddset(¤t->blocked,sig); |
69be8f18 SR |
298 | recalc_sigpending(); |
299 | spin_unlock_irq(¤t->sighand->siglock); | |
a05c4e1d | 300 | return 0; |
1da177e4 LT |
301 | } |
302 | ||
303 | /* | |
304 | * Note that 'init' is a special process: it doesn't get signals it doesn't | |
305 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | |
306 | * mistake. | |
307 | */ | |
a05c4e1d | 308 | static void do_signal(struct pt_regs *regs) |
1da177e4 LT |
309 | { |
310 | siginfo_t info; | |
311 | int signr; | |
312 | struct k_sigaction ka; | |
313 | unsigned short inst; | |
a7f8388e | 314 | sigset_t *oldset; |
1da177e4 LT |
315 | |
316 | /* | |
317 | * We want the common case to go fast, which | |
318 | * is why we may in certain cases get here from | |
319 | * kernel mode. Just return without doing anything | |
320 | * if so. | |
321 | */ | |
322 | if (!user_mode(regs)) | |
a05c4e1d | 323 | return; |
1da177e4 | 324 | |
3e1d1d28 | 325 | if (try_to_freeze()) |
1da177e4 | 326 | goto no_signal; |
1da177e4 | 327 | |
a7f8388e AV |
328 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
329 | oldset = ¤t->saved_sigmask; | |
330 | else | |
1da177e4 LT |
331 | oldset = ¤t->blocked; |
332 | ||
333 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | |
334 | if (signr > 0) { | |
5aa8b6c1 | 335 | /* Re-enable any watchpoints before delivering the |
1da177e4 LT |
336 | * signal to user space. The processor register will |
337 | * have been cleared if the watchpoint triggered | |
338 | * inside the kernel. | |
339 | */ | |
340 | ||
341 | /* Whee! Actually deliver the signal. */ | |
a05c4e1d AV |
342 | if (handle_signal(signr, &ka, &info, oldset, regs) == 0) |
343 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
344 | ||
345 | return; | |
1da177e4 LT |
346 | } |
347 | ||
348 | no_signal: | |
349 | /* Did we come from a system call? */ | |
350 | if (regs->syscall_nr >= 0) { | |
351 | /* Restart the system call - no handlers present */ | |
352 | if (regs->r0 == -ERESTARTNOHAND || | |
353 | regs->r0 == -ERESTARTSYS || | |
354 | regs->r0 == -ERESTARTNOINTR) { | |
355 | regs->r0 = regs->orig_r0; | |
356 | inst = *(unsigned short *)(regs->bpc - 2); | |
357 | if ((inst & 0xfff0) == 0x10f0) /* trap ? */ | |
358 | regs->bpc -= 2; | |
359 | else | |
360 | regs->bpc -= 4; | |
a7481024 AV |
361 | regs->syscall_nr = -1; |
362 | } else if (regs->r0 == -ERESTART_RESTARTBLOCK){ | |
1da177e4 LT |
363 | regs->r0 = regs->orig_r0; |
364 | regs->r7 = __NR_restart_syscall; | |
365 | inst = *(unsigned short *)(regs->bpc - 2); | |
366 | if ((inst & 0xfff0) == 0x10f0) /* trap ? */ | |
367 | regs->bpc -= 2; | |
368 | else | |
369 | regs->bpc -= 4; | |
a7481024 | 370 | regs->syscall_nr = -1; |
1da177e4 LT |
371 | } |
372 | } | |
a7f8388e AV |
373 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { |
374 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
375 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | |
376 | } | |
1da177e4 LT |
377 | } |
378 | ||
379 | /* | |
380 | * notification of userspace execution resumption | |
381 | * - triggered by current->work.notify_resume | |
382 | */ | |
a7f8388e | 383 | void do_notify_resume(struct pt_regs *regs, __u32 thread_info_flags) |
1da177e4 LT |
384 | { |
385 | /* Pending single-step? */ | |
386 | if (thread_info_flags & _TIF_SINGLESTEP) | |
387 | clear_thread_flag(TIF_SINGLESTEP); | |
388 | ||
389 | /* deal with pending signal delivery */ | |
390 | if (thread_info_flags & _TIF_SIGPENDING) | |
a7f8388e | 391 | do_signal(regs); |
1da177e4 | 392 | |
d0420c83 DH |
393 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
394 | clear_thread_flag(TIF_NOTIFY_RESUME); | |
395 | tracehook_notify_resume(regs); | |
ee18d64c DH |
396 | if (current->replacement_session_keyring) |
397 | key_replace_session_keyring(); | |
d0420c83 DH |
398 | } |
399 | ||
1da177e4 LT |
400 | clear_thread_flag(TIF_IRET); |
401 | } |