]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 1991, 1992 Linus Torvalds |
3 | * | |
4 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson | |
5 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes | |
6 | */ | |
7 | ||
8 | #include <linux/sched.h> | |
9 | #include <linux/mm.h> | |
10 | #include <linux/smp.h> | |
1da177e4 LT |
11 | #include <linux/kernel.h> |
12 | #include <linux/signal.h> | |
13 | #include <linux/errno.h> | |
14 | #include <linux/wait.h> | |
15 | #include <linux/unistd.h> | |
16 | #include <linux/stddef.h> | |
17 | #include <linux/personality.h> | |
18 | #include <linux/suspend.h> | |
19 | #include <linux/ptrace.h> | |
20 | #include <linux/elf.h> | |
9fbbd4dd | 21 | #include <linux/binfmts.h> |
1da177e4 LT |
22 | #include <asm/processor.h> |
23 | #include <asm/ucontext.h> | |
24 | #include <asm/uaccess.h> | |
25 | #include <asm/i387.h> | |
6c3652ef | 26 | #include <asm/vdso.h> |
56cc623c | 27 | #include "sigframe_32.h" |
1da177e4 LT |
28 | |
29 | #define DEBUG_SIG 0 | |
30 | ||
31 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | |
32 | ||
33 | /* | |
34 | * Atomically swap in the new signal mask, and wait for a signal. | |
35 | */ | |
36 | asmlinkage int | |
37 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) | |
38 | { | |
1da177e4 LT |
39 | mask &= _BLOCKABLE; |
40 | spin_lock_irq(¤t->sighand->siglock); | |
283828f3 | 41 | current->saved_sigmask = current->blocked; |
1da177e4 LT |
42 | siginitset(¤t->blocked, mask); |
43 | recalc_sigpending(); | |
44 | spin_unlock_irq(¤t->sighand->siglock); | |
45 | ||
283828f3 DH |
46 | current->state = TASK_INTERRUPTIBLE; |
47 | schedule(); | |
48 | set_thread_flag(TIF_RESTORE_SIGMASK); | |
49 | return -ERESTARTNOHAND; | |
1da177e4 LT |
50 | } |
51 | ||
52 | asmlinkage int | |
53 | sys_sigaction(int sig, const struct old_sigaction __user *act, | |
54 | struct old_sigaction __user *oact) | |
55 | { | |
56 | struct k_sigaction new_ka, old_ka; | |
57 | int ret; | |
58 | ||
59 | if (act) { | |
60 | old_sigset_t mask; | |
61 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | |
62 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | |
63 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | |
64 | return -EFAULT; | |
65 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | |
66 | __get_user(mask, &act->sa_mask); | |
67 | siginitset(&new_ka.sa.sa_mask, mask); | |
68 | } | |
69 | ||
70 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
71 | ||
72 | if (!ret && oact) { | |
73 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | |
74 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | |
75 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | |
76 | return -EFAULT; | |
77 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | |
78 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | |
79 | } | |
80 | ||
81 | return ret; | |
82 | } | |
83 | ||
84 | asmlinkage int | |
85 | sys_sigaltstack(unsigned long ebx) | |
86 | { | |
87 | /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */ | |
88 | struct pt_regs *regs = (struct pt_regs *)&ebx; | |
89 | const stack_t __user *uss = (const stack_t __user *)ebx; | |
90 | stack_t __user *uoss = (stack_t __user *)regs->ecx; | |
91 | ||
92 | return do_sigaltstack(uss, uoss, regs->esp); | |
93 | } | |
94 | ||
95 | ||
96 | /* | |
97 | * Do a signal return; undo the signal stack. | |
98 | */ | |
99 | ||
100 | static int | |
101 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax) | |
102 | { | |
103 | unsigned int err = 0; | |
104 | ||
105 | /* Always make any pending restarted system calls return -EINTR */ | |
106 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | |
107 | ||
108 | #define COPY(x) err |= __get_user(regs->x, &sc->x) | |
109 | ||
110 | #define COPY_SEG(seg) \ | |
111 | { unsigned short tmp; \ | |
112 | err |= __get_user(tmp, &sc->seg); \ | |
113 | regs->x##seg = tmp; } | |
114 | ||
115 | #define COPY_SEG_STRICT(seg) \ | |
116 | { unsigned short tmp; \ | |
117 | err |= __get_user(tmp, &sc->seg); \ | |
118 | regs->x##seg = tmp|3; } | |
119 | ||
120 | #define GET_SEG(seg) \ | |
121 | { unsigned short tmp; \ | |
122 | err |= __get_user(tmp, &sc->seg); \ | |
123 | loadsegment(seg,tmp); } | |
124 | ||
8bed51cd CE |
125 | #define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_RF | \ |
126 | X86_EFLAGS_OF | X86_EFLAGS_DF | \ | |
1da177e4 LT |
127 | X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \ |
128 | X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF) | |
129 | ||
464d1a78 JF |
130 | GET_SEG(gs); |
131 | COPY_SEG(fs); | |
1da177e4 LT |
132 | COPY_SEG(es); |
133 | COPY_SEG(ds); | |
134 | COPY(edi); | |
135 | COPY(esi); | |
136 | COPY(ebp); | |
137 | COPY(esp); | |
138 | COPY(ebx); | |
139 | COPY(edx); | |
140 | COPY(ecx); | |
141 | COPY(eip); | |
142 | COPY_SEG_STRICT(cs); | |
143 | COPY_SEG_STRICT(ss); | |
144 | ||
145 | { | |
146 | unsigned int tmpflags; | |
147 | err |= __get_user(tmpflags, &sc->eflags); | |
148 | regs->eflags = (regs->eflags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); | |
149 | regs->orig_eax = -1; /* disable syscall checks */ | |
150 | } | |
151 | ||
152 | { | |
153 | struct _fpstate __user * buf; | |
154 | err |= __get_user(buf, &sc->fpstate); | |
155 | if (buf) { | |
156 | if (!access_ok(VERIFY_READ, buf, sizeof(*buf))) | |
157 | goto badframe; | |
158 | err |= restore_i387(buf); | |
159 | } else { | |
160 | struct task_struct *me = current; | |
161 | if (used_math()) { | |
162 | clear_fpu(me); | |
163 | clear_used_math(); | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | err |= __get_user(*peax, &sc->eax); | |
169 | return err; | |
170 | ||
171 | badframe: | |
172 | return 1; | |
173 | } | |
174 | ||
175 | asmlinkage int sys_sigreturn(unsigned long __unused) | |
176 | { | |
177 | struct pt_regs *regs = (struct pt_regs *) &__unused; | |
178 | struct sigframe __user *frame = (struct sigframe __user *)(regs->esp - 8); | |
179 | sigset_t set; | |
180 | int eax; | |
181 | ||
182 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | |
183 | goto badframe; | |
184 | if (__get_user(set.sig[0], &frame->sc.oldmask) | |
185 | || (_NSIG_WORDS > 1 | |
186 | && __copy_from_user(&set.sig[1], &frame->extramask, | |
187 | sizeof(frame->extramask)))) | |
188 | goto badframe; | |
189 | ||
190 | sigdelsetmask(&set, ~_BLOCKABLE); | |
191 | spin_lock_irq(¤t->sighand->siglock); | |
192 | current->blocked = set; | |
193 | recalc_sigpending(); | |
194 | spin_unlock_irq(¤t->sighand->siglock); | |
195 | ||
196 | if (restore_sigcontext(regs, &frame->sc, &eax)) | |
197 | goto badframe; | |
198 | return eax; | |
199 | ||
200 | badframe: | |
abd4f750 MAS |
201 | if (show_unhandled_signals && printk_ratelimit()) |
202 | printk("%s%s[%d] bad frame in sigreturn frame:%p eip:%lx" | |
203 | " esp:%lx oeax:%lx\n", | |
19c5870c AD |
204 | task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG, |
205 | current->comm, task_pid_nr(current), frame, regs->eip, | |
abd4f750 MAS |
206 | regs->esp, regs->orig_eax); |
207 | ||
1da177e4 LT |
208 | force_sig(SIGSEGV, current); |
209 | return 0; | |
210 | } | |
211 | ||
212 | asmlinkage int sys_rt_sigreturn(unsigned long __unused) | |
213 | { | |
214 | struct pt_regs *regs = (struct pt_regs *) &__unused; | |
215 | struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->esp - 4); | |
216 | sigset_t set; | |
217 | int eax; | |
218 | ||
219 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | |
220 | goto badframe; | |
221 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) | |
222 | goto badframe; | |
223 | ||
224 | sigdelsetmask(&set, ~_BLOCKABLE); | |
225 | spin_lock_irq(¤t->sighand->siglock); | |
226 | current->blocked = set; | |
227 | recalc_sigpending(); | |
228 | spin_unlock_irq(¤t->sighand->siglock); | |
229 | ||
230 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) | |
231 | goto badframe; | |
232 | ||
233 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->esp) == -EFAULT) | |
234 | goto badframe; | |
235 | ||
236 | return eax; | |
237 | ||
238 | badframe: | |
239 | force_sig(SIGSEGV, current); | |
240 | return 0; | |
241 | } | |
242 | ||
243 | /* | |
244 | * Set up a signal frame. | |
245 | */ | |
246 | ||
247 | static int | |
248 | setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate, | |
249 | struct pt_regs *regs, unsigned long mask) | |
250 | { | |
251 | int tmp, err = 0; | |
252 | ||
464d1a78 JF |
253 | err |= __put_user(regs->xfs, (unsigned int __user *)&sc->fs); |
254 | savesegment(gs, tmp); | |
255 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); | |
1da177e4 LT |
256 | |
257 | err |= __put_user(regs->xes, (unsigned int __user *)&sc->es); | |
258 | err |= __put_user(regs->xds, (unsigned int __user *)&sc->ds); | |
259 | err |= __put_user(regs->edi, &sc->edi); | |
260 | err |= __put_user(regs->esi, &sc->esi); | |
261 | err |= __put_user(regs->ebp, &sc->ebp); | |
262 | err |= __put_user(regs->esp, &sc->esp); | |
263 | err |= __put_user(regs->ebx, &sc->ebx); | |
264 | err |= __put_user(regs->edx, &sc->edx); | |
265 | err |= __put_user(regs->ecx, &sc->ecx); | |
266 | err |= __put_user(regs->eax, &sc->eax); | |
267 | err |= __put_user(current->thread.trap_no, &sc->trapno); | |
268 | err |= __put_user(current->thread.error_code, &sc->err); | |
269 | err |= __put_user(regs->eip, &sc->eip); | |
270 | err |= __put_user(regs->xcs, (unsigned int __user *)&sc->cs); | |
271 | err |= __put_user(regs->eflags, &sc->eflags); | |
272 | err |= __put_user(regs->esp, &sc->esp_at_signal); | |
273 | err |= __put_user(regs->xss, (unsigned int __user *)&sc->ss); | |
274 | ||
275 | tmp = save_i387(fpstate); | |
276 | if (tmp < 0) | |
277 | err = 1; | |
278 | else | |
279 | err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate); | |
280 | ||
281 | /* non-iBCS2 extensions.. */ | |
282 | err |= __put_user(mask, &sc->oldmask); | |
283 | err |= __put_user(current->thread.cr2, &sc->cr2); | |
284 | ||
285 | return err; | |
286 | } | |
287 | ||
288 | /* | |
289 | * Determine which stack to use.. | |
290 | */ | |
291 | static inline void __user * | |
292 | get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) | |
293 | { | |
294 | unsigned long esp; | |
295 | ||
296 | /* Default to using normal stack */ | |
297 | esp = regs->esp; | |
298 | ||
83bd0102 RM |
299 | /* |
300 | * If we are on the alternate signal stack and would overflow it, don't. | |
301 | * Return an always-bogus address instead so we will die with SIGSEGV. | |
302 | */ | |
303 | if (on_sig_stack(esp) && !likely(on_sig_stack(esp - frame_size))) | |
304 | return (void __user *) -1L; | |
305 | ||
1da177e4 LT |
306 | /* This is the X/Open sanctioned signal stack switching. */ |
307 | if (ka->sa.sa_flags & SA_ONSTACK) { | |
308 | if (sas_ss_flags(esp) == 0) | |
309 | esp = current->sas_ss_sp + current->sas_ss_size; | |
310 | } | |
311 | ||
312 | /* This is the legacy signal stack switching. */ | |
313 | else if ((regs->xss & 0xffff) != __USER_DS && | |
314 | !(ka->sa.sa_flags & SA_RESTORER) && | |
315 | ka->sa.sa_restorer) { | |
316 | esp = (unsigned long) ka->sa.sa_restorer; | |
317 | } | |
318 | ||
d347f372 MO |
319 | esp -= frame_size; |
320 | /* Align the stack pointer according to the i386 ABI, | |
321 | * i.e. so that on function entry ((sp + 4) & 15) == 0. */ | |
322 | esp = ((esp + 4) & -16ul) - 4; | |
323 | return (void __user *) esp; | |
1da177e4 LT |
324 | } |
325 | ||
326 | /* These symbols are defined with the addresses in the vsyscall page. | |
327 | See vsyscall-sigreturn.S. */ | |
328 | extern void __user __kernel_sigreturn; | |
329 | extern void __user __kernel_rt_sigreturn; | |
330 | ||
7c1def16 RM |
331 | static int setup_frame(int sig, struct k_sigaction *ka, |
332 | sigset_t *set, struct pt_regs * regs) | |
1da177e4 LT |
333 | { |
334 | void __user *restorer; | |
335 | struct sigframe __user *frame; | |
336 | int err = 0; | |
337 | int usig; | |
338 | ||
339 | frame = get_sigframe(ka, regs, sizeof(*frame)); | |
340 | ||
341 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | |
342 | goto give_sigsegv; | |
343 | ||
344 | usig = current_thread_info()->exec_domain | |
345 | && current_thread_info()->exec_domain->signal_invmap | |
346 | && sig < 32 | |
347 | ? current_thread_info()->exec_domain->signal_invmap[sig] | |
348 | : sig; | |
349 | ||
350 | err = __put_user(usig, &frame->sig); | |
351 | if (err) | |
352 | goto give_sigsegv; | |
353 | ||
354 | err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]); | |
355 | if (err) | |
356 | goto give_sigsegv; | |
357 | ||
358 | if (_NSIG_WORDS > 1) { | |
359 | err = __copy_to_user(&frame->extramask, &set->sig[1], | |
360 | sizeof(frame->extramask)); | |
361 | if (err) | |
362 | goto give_sigsegv; | |
363 | } | |
364 | ||
9fbbd4dd | 365 | if (current->binfmt->hasvdso) |
6c3652ef | 366 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn); |
9fbbd4dd AK |
367 | else |
368 | restorer = (void *)&frame->retcode; | |
1da177e4 LT |
369 | if (ka->sa.sa_flags & SA_RESTORER) |
370 | restorer = ka->sa.sa_restorer; | |
371 | ||
372 | /* Set up to return from userspace. */ | |
373 | err |= __put_user(restorer, &frame->pretcode); | |
374 | ||
375 | /* | |
376 | * This is popl %eax ; movl $,%eax ; int $0x80 | |
377 | * | |
378 | * WE DO NOT USE IT ANY MORE! It's only left here for historical | |
379 | * reasons and because gdb uses it as a signature to notice | |
380 | * signal handler stack frames. | |
381 | */ | |
382 | err |= __put_user(0xb858, (short __user *)(frame->retcode+0)); | |
383 | err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2)); | |
384 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); | |
385 | ||
386 | if (err) | |
387 | goto give_sigsegv; | |
388 | ||
389 | /* Set up registers for signal handler */ | |
390 | regs->esp = (unsigned long) frame; | |
391 | regs->eip = (unsigned long) ka->sa.sa_handler; | |
392 | regs->eax = (unsigned long) sig; | |
393 | regs->edx = (unsigned long) 0; | |
394 | regs->ecx = (unsigned long) 0; | |
395 | ||
1da177e4 LT |
396 | regs->xds = __USER_DS; |
397 | regs->xes = __USER_DS; | |
398 | regs->xss = __USER_DS; | |
399 | regs->xcs = __USER_CS; | |
400 | ||
401 | /* | |
402 | * Clear TF when entering the signal handler, but | |
403 | * notify any tracer that was single-stepping it. | |
404 | * The tracer may want to single-step inside the | |
405 | * handler too. | |
406 | */ | |
407 | regs->eflags &= ~TF_MASK; | |
408 | if (test_thread_flag(TIF_SINGLESTEP)) | |
409 | ptrace_notify(SIGTRAP); | |
410 | ||
411 | #if DEBUG_SIG | |
412 | printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", | |
413 | current->comm, current->pid, frame, regs->eip, frame->pretcode); | |
414 | #endif | |
415 | ||
283828f3 | 416 | return 0; |
1da177e4 LT |
417 | |
418 | give_sigsegv: | |
419 | force_sigsegv(sig, current); | |
283828f3 | 420 | return -EFAULT; |
1da177e4 LT |
421 | } |
422 | ||
7c1def16 | 423 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
1da177e4 LT |
424 | sigset_t *set, struct pt_regs * regs) |
425 | { | |
426 | void __user *restorer; | |
427 | struct rt_sigframe __user *frame; | |
428 | int err = 0; | |
429 | int usig; | |
430 | ||
431 | frame = get_sigframe(ka, regs, sizeof(*frame)); | |
432 | ||
433 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) | |
434 | goto give_sigsegv; | |
435 | ||
436 | usig = current_thread_info()->exec_domain | |
437 | && current_thread_info()->exec_domain->signal_invmap | |
438 | && sig < 32 | |
439 | ? current_thread_info()->exec_domain->signal_invmap[sig] | |
440 | : sig; | |
441 | ||
442 | err |= __put_user(usig, &frame->sig); | |
443 | err |= __put_user(&frame->info, &frame->pinfo); | |
444 | err |= __put_user(&frame->uc, &frame->puc); | |
445 | err |= copy_siginfo_to_user(&frame->info, info); | |
446 | if (err) | |
447 | goto give_sigsegv; | |
448 | ||
449 | /* Create the ucontext. */ | |
450 | err |= __put_user(0, &frame->uc.uc_flags); | |
451 | err |= __put_user(0, &frame->uc.uc_link); | |
452 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | |
453 | err |= __put_user(sas_ss_flags(regs->esp), | |
454 | &frame->uc.uc_stack.ss_flags); | |
455 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); | |
456 | err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate, | |
457 | regs, set->sig[0]); | |
458 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); | |
459 | if (err) | |
460 | goto give_sigsegv; | |
461 | ||
462 | /* Set up to return from userspace. */ | |
6c3652ef | 463 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); |
1da177e4 LT |
464 | if (ka->sa.sa_flags & SA_RESTORER) |
465 | restorer = ka->sa.sa_restorer; | |
466 | err |= __put_user(restorer, &frame->pretcode); | |
467 | ||
468 | /* | |
469 | * This is movl $,%eax ; int $0x80 | |
470 | * | |
471 | * WE DO NOT USE IT ANY MORE! It's only left here for historical | |
472 | * reasons and because gdb uses it as a signature to notice | |
473 | * signal handler stack frames. | |
474 | */ | |
475 | err |= __put_user(0xb8, (char __user *)(frame->retcode+0)); | |
476 | err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1)); | |
477 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); | |
478 | ||
479 | if (err) | |
480 | goto give_sigsegv; | |
481 | ||
482 | /* Set up registers for signal handler */ | |
483 | regs->esp = (unsigned long) frame; | |
484 | regs->eip = (unsigned long) ka->sa.sa_handler; | |
485 | regs->eax = (unsigned long) usig; | |
486 | regs->edx = (unsigned long) &frame->info; | |
487 | regs->ecx = (unsigned long) &frame->uc; | |
488 | ||
1da177e4 LT |
489 | regs->xds = __USER_DS; |
490 | regs->xes = __USER_DS; | |
491 | regs->xss = __USER_DS; | |
492 | regs->xcs = __USER_CS; | |
493 | ||
494 | /* | |
495 | * Clear TF when entering the signal handler, but | |
496 | * notify any tracer that was single-stepping it. | |
497 | * The tracer may want to single-step inside the | |
498 | * handler too. | |
499 | */ | |
500 | regs->eflags &= ~TF_MASK; | |
501 | if (test_thread_flag(TIF_SINGLESTEP)) | |
502 | ptrace_notify(SIGTRAP); | |
503 | ||
504 | #if DEBUG_SIG | |
505 | printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", | |
506 | current->comm, current->pid, frame, regs->eip, frame->pretcode); | |
507 | #endif | |
508 | ||
283828f3 | 509 | return 0; |
1da177e4 LT |
510 | |
511 | give_sigsegv: | |
512 | force_sigsegv(sig, current); | |
283828f3 | 513 | return -EFAULT; |
1da177e4 LT |
514 | } |
515 | ||
516 | /* | |
517 | * OK, we're invoking a handler | |
518 | */ | |
519 | ||
7c1def16 | 520 | static int |
1da177e4 LT |
521 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, |
522 | sigset_t *oldset, struct pt_regs * regs) | |
523 | { | |
7c1def16 RM |
524 | int ret; |
525 | ||
1da177e4 LT |
526 | /* Are we from a system call? */ |
527 | if (regs->orig_eax >= 0) { | |
528 | /* If so, check system call restarting.. */ | |
529 | switch (regs->eax) { | |
530 | case -ERESTART_RESTARTBLOCK: | |
531 | case -ERESTARTNOHAND: | |
532 | regs->eax = -EINTR; | |
533 | break; | |
534 | ||
535 | case -ERESTARTSYS: | |
536 | if (!(ka->sa.sa_flags & SA_RESTART)) { | |
537 | regs->eax = -EINTR; | |
538 | break; | |
539 | } | |
540 | /* fallthrough */ | |
541 | case -ERESTARTNOINTR: | |
542 | regs->eax = regs->orig_eax; | |
543 | regs->eip -= 2; | |
544 | } | |
545 | } | |
546 | ||
547 | /* | |
548 | * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so | |
549 | * that register information in the sigcontext is correct. | |
550 | */ | |
551 | if (unlikely(regs->eflags & TF_MASK) | |
552 | && likely(current->ptrace & PT_DTRACE)) { | |
553 | current->ptrace &= ~PT_DTRACE; | |
554 | regs->eflags &= ~TF_MASK; | |
555 | } | |
556 | ||
557 | /* Set up the stack frame */ | |
558 | if (ka->sa.sa_flags & SA_SIGINFO) | |
7c1def16 | 559 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
1da177e4 | 560 | else |
7c1def16 | 561 | ret = setup_frame(sig, ka, oldset, regs); |
1da177e4 | 562 | |
283828f3 | 563 | if (ret == 0) { |
1da177e4 LT |
564 | spin_lock_irq(¤t->sighand->siglock); |
565 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | |
69be8f18 SR |
566 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
567 | sigaddset(¤t->blocked,sig); | |
1da177e4 LT |
568 | recalc_sigpending(); |
569 | spin_unlock_irq(¤t->sighand->siglock); | |
570 | } | |
7c1def16 RM |
571 | |
572 | return ret; | |
1da177e4 LT |
573 | } |
574 | ||
575 | /* | |
576 | * Note that 'init' is a special process: it doesn't get signals it doesn't | |
577 | * want to handle. Thus you cannot kill init even with a SIGKILL even by | |
578 | * mistake. | |
579 | */ | |
283828f3 | 580 | static void fastcall do_signal(struct pt_regs *regs) |
1da177e4 LT |
581 | { |
582 | siginfo_t info; | |
583 | int signr; | |
584 | struct k_sigaction ka; | |
283828f3 | 585 | sigset_t *oldset; |
1da177e4 LT |
586 | |
587 | /* | |
588 | * We want the common case to go fast, which | |
589 | * is why we may in certain cases get here from | |
590 | * kernel mode. Just return without doing anything | |
0998e422 ZA |
591 | * if so. vm86 regs switched out by assembly code |
592 | * before reaching here, so testing against kernel | |
593 | * CS suffices. | |
1da177e4 | 594 | */ |
717b594a | 595 | if (!user_mode(regs)) |
283828f3 | 596 | return; |
1da177e4 | 597 | |
283828f3 DH |
598 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
599 | oldset = ¤t->saved_sigmask; | |
600 | else | |
1da177e4 LT |
601 | oldset = ¤t->blocked; |
602 | ||
603 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | |
604 | if (signr > 0) { | |
27b46d76 | 605 | /* Re-enable any watchpoints before delivering the |
1da177e4 LT |
606 | * signal to user space. The processor register will |
607 | * have been cleared if the watchpoint triggered | |
608 | * inside the kernel. | |
609 | */ | |
283828f3 | 610 | if (unlikely(current->thread.debugreg[7])) |
1cc6f12e | 611 | set_debugreg(current->thread.debugreg[7], 7); |
1da177e4 LT |
612 | |
613 | /* Whee! Actually deliver the signal. */ | |
283828f3 DH |
614 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { |
615 | /* a signal was successfully delivered; the saved | |
616 | * sigmask will have been stored in the signal frame, | |
617 | * and will be restored by sigreturn, so we can simply | |
618 | * clear the TIF_RESTORE_SIGMASK flag */ | |
619 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) | |
620 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
621 | } | |
622 | ||
623 | return; | |
1da177e4 LT |
624 | } |
625 | ||
1da177e4 LT |
626 | /* Did we come from a system call? */ |
627 | if (regs->orig_eax >= 0) { | |
628 | /* Restart the system call - no handlers present */ | |
283828f3 DH |
629 | switch (regs->eax) { |
630 | case -ERESTARTNOHAND: | |
631 | case -ERESTARTSYS: | |
632 | case -ERESTARTNOINTR: | |
1da177e4 LT |
633 | regs->eax = regs->orig_eax; |
634 | regs->eip -= 2; | |
283828f3 DH |
635 | break; |
636 | ||
637 | case -ERESTART_RESTARTBLOCK: | |
1da177e4 LT |
638 | regs->eax = __NR_restart_syscall; |
639 | regs->eip -= 2; | |
283828f3 | 640 | break; |
1da177e4 LT |
641 | } |
642 | } | |
283828f3 DH |
643 | |
644 | /* if there's no signal to deliver, we just put the saved sigmask | |
645 | * back */ | |
646 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { | |
647 | clear_thread_flag(TIF_RESTORE_SIGMASK); | |
648 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | |
649 | } | |
1da177e4 LT |
650 | } |
651 | ||
652 | /* | |
653 | * notification of userspace execution resumption | |
283828f3 | 654 | * - triggered by the TIF_WORK_MASK flags |
1da177e4 LT |
655 | */ |
656 | __attribute__((regparm(3))) | |
283828f3 | 657 | void do_notify_resume(struct pt_regs *regs, void *_unused, |
1da177e4 LT |
658 | __u32 thread_info_flags) |
659 | { | |
660 | /* Pending single-step? */ | |
661 | if (thread_info_flags & _TIF_SINGLESTEP) { | |
662 | regs->eflags |= TF_MASK; | |
663 | clear_thread_flag(TIF_SINGLESTEP); | |
664 | } | |
283828f3 | 665 | |
1da177e4 | 666 | /* deal with pending signal delivery */ |
283828f3 DH |
667 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) |
668 | do_signal(regs); | |
8f4d37ec PZ |
669 | |
670 | if (thread_info_flags & _TIF_HRTICK_RESCHED) | |
671 | hrtick_resched(); | |
1da177e4 LT |
672 | |
673 | clear_thread_flag(TIF_IRET); | |
674 | } |