2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
5 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
6 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
7 * 2000-2002 x86-64 support by Andi Kleen
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/sched.h>
14 #include <linux/smp.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/wait.h>
18 #include <linux/tracehook.h>
19 #include <linux/unistd.h>
20 #include <linux/stddef.h>
21 #include <linux/personality.h>
22 #include <linux/uaccess.h>
23 #include <linux/user-return-notifier.h>
24 #include <linux/uprobes.h>
25 #include <linux/context_tracking.h>
27 #include <asm/processor.h>
28 #include <asm/ucontext.h>
29 #include <asm/fpu/internal.h>
30 #include <asm/fpu/signal.h>
33 #include <asm/sighandling.h>
37 #include <asm/proto.h>
38 #include <asm/ia32_unistd.h>
39 #endif /* CONFIG_X86_64 */
41 #include <asm/syscall.h>
42 #include <asm/syscalls.h>
44 #include <asm/sigframe.h>
46 #define COPY(x) do { \
47 get_user_ex(regs->x, &sc->x); \
50 #define GET_SEG(seg) ({ \
52 get_user_ex(tmp, &sc->seg); \
56 #define COPY_SEG(seg) do { \
57 regs->seg = GET_SEG(seg); \
60 #define COPY_SEG_CPL3(seg) do { \
61 regs->seg = GET_SEG(seg) | 3; \
66 * If regs->ss will cause an IRET fault, change it. Otherwise leave it
67 * alone. Using this generally makes no sense unless
68 * user_64bit_mode(regs) would return true.
70 static void force_valid_ss(struct pt_regs
*regs
)
73 asm volatile ("lar %[old_ss], %[ar]\n\t"
74 "jz 1f\n\t" /* If invalid: */
75 "xorl %[ar], %[ar]\n\t" /* set ar = 0 */
78 : [old_ss
] "rm" ((u16
)regs
->ss
));
81 * For a valid 64-bit user context, we need DPL 3, type
82 * read-write data or read-write exp-down data, and S and P
83 * set. We can't use VERW because VERW doesn't check the
86 ar
&= AR_DPL_MASK
| AR_S
| AR_P
| AR_TYPE_MASK
;
87 if (ar
!= (AR_DPL3
| AR_S
| AR_P
| AR_TYPE_RWDATA
) &&
88 ar
!= (AR_DPL3
| AR_S
| AR_P
| AR_TYPE_RWDATA_EXPDOWN
))
93 static int restore_sigcontext(struct pt_regs
*regs
,
94 struct sigcontext __user
*sc
,
95 unsigned long uc_flags
)
97 unsigned long buf_val
;
99 unsigned int tmpflags
;
100 unsigned int err
= 0;
102 /* Always make any pending restarted system calls return -EINTR */
103 current
->restart_block
.fn
= do_no_restart_syscall
;
108 set_user_gs(regs
, GET_SEG(gs
));
112 #endif /* CONFIG_X86_32 */
114 COPY(di
); COPY(si
); COPY(bp
); COPY(sp
); COPY(bx
);
115 COPY(dx
); COPY(cx
); COPY(ip
); COPY(ax
);
126 #endif /* CONFIG_X86_64 */
133 * Fix up SS if needed for the benefit of old DOSEMU and
136 if (unlikely(!(uc_flags
& UC_STRICT_RESTORE_SS
) &&
137 user_64bit_mode(regs
)))
138 force_valid_ss(regs
);
141 get_user_ex(tmpflags
, &sc
->flags
);
142 regs
->flags
= (regs
->flags
& ~FIX_EFLAGS
) | (tmpflags
& FIX_EFLAGS
);
143 regs
->orig_ax
= -1; /* disable syscall checks */
145 get_user_ex(buf_val
, &sc
->fpstate
);
146 buf
= (void __user
*)buf_val
;
147 } get_user_catch(err
);
149 err
|= fpu__restore_sig(buf
, config_enabled(CONFIG_X86_32
));
156 int setup_sigcontext(struct sigcontext __user
*sc
, void __user
*fpstate
,
157 struct pt_regs
*regs
, unsigned long mask
)
164 put_user_ex(get_user_gs(regs
), (unsigned int __user
*)&sc
->gs
);
165 put_user_ex(regs
->fs
, (unsigned int __user
*)&sc
->fs
);
166 put_user_ex(regs
->es
, (unsigned int __user
*)&sc
->es
);
167 put_user_ex(regs
->ds
, (unsigned int __user
*)&sc
->ds
);
168 #endif /* CONFIG_X86_32 */
170 put_user_ex(regs
->di
, &sc
->di
);
171 put_user_ex(regs
->si
, &sc
->si
);
172 put_user_ex(regs
->bp
, &sc
->bp
);
173 put_user_ex(regs
->sp
, &sc
->sp
);
174 put_user_ex(regs
->bx
, &sc
->bx
);
175 put_user_ex(regs
->dx
, &sc
->dx
);
176 put_user_ex(regs
->cx
, &sc
->cx
);
177 put_user_ex(regs
->ax
, &sc
->ax
);
179 put_user_ex(regs
->r8
, &sc
->r8
);
180 put_user_ex(regs
->r9
, &sc
->r9
);
181 put_user_ex(regs
->r10
, &sc
->r10
);
182 put_user_ex(regs
->r11
, &sc
->r11
);
183 put_user_ex(regs
->r12
, &sc
->r12
);
184 put_user_ex(regs
->r13
, &sc
->r13
);
185 put_user_ex(regs
->r14
, &sc
->r14
);
186 put_user_ex(regs
->r15
, &sc
->r15
);
187 #endif /* CONFIG_X86_64 */
189 put_user_ex(current
->thread
.trap_nr
, &sc
->trapno
);
190 put_user_ex(current
->thread
.error_code
, &sc
->err
);
191 put_user_ex(regs
->ip
, &sc
->ip
);
193 put_user_ex(regs
->cs
, (unsigned int __user
*)&sc
->cs
);
194 put_user_ex(regs
->flags
, &sc
->flags
);
195 put_user_ex(regs
->sp
, &sc
->sp_at_signal
);
196 put_user_ex(regs
->ss
, (unsigned int __user
*)&sc
->ss
);
197 #else /* !CONFIG_X86_32 */
198 put_user_ex(regs
->flags
, &sc
->flags
);
199 put_user_ex(regs
->cs
, &sc
->cs
);
200 put_user_ex(0, &sc
->gs
);
201 put_user_ex(0, &sc
->fs
);
202 put_user_ex(regs
->ss
, &sc
->ss
);
203 #endif /* CONFIG_X86_32 */
205 put_user_ex(fpstate
, &sc
->fpstate
);
207 /* non-iBCS2 extensions.. */
208 put_user_ex(mask
, &sc
->oldmask
);
209 put_user_ex(current
->thread
.cr2
, &sc
->cr2
);
210 } put_user_catch(err
);
216 * Set up a signal frame.
220 * Determine which stack to use..
222 static unsigned long align_sigframe(unsigned long sp
)
226 * Align the stack pointer according to the i386 ABI,
227 * i.e. so that on function entry ((sp + 4) & 15) == 0.
229 sp
= ((sp
+ 4) & -16ul) - 4;
230 #else /* !CONFIG_X86_32 */
231 sp
= round_down(sp
, 16) - 8;
237 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
,
238 void __user
**fpstate
)
240 /* Default to using normal stack */
241 unsigned long math_size
= 0;
242 unsigned long sp
= regs
->sp
;
243 unsigned long buf_fx
= 0;
244 int onsigstack
= on_sig_stack(sp
);
245 struct fpu
*fpu
= ¤t
->thread
.fpu
;
248 if (config_enabled(CONFIG_X86_64
))
252 /* This is the X/Open sanctioned signal stack switching. */
253 if (ka
->sa
.sa_flags
& SA_ONSTACK
) {
254 if (current
->sas_ss_size
)
255 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
256 } else if (config_enabled(CONFIG_X86_32
) &&
257 (regs
->ss
& 0xffff) != __USER_DS
&&
258 !(ka
->sa
.sa_flags
& SA_RESTORER
) &&
259 ka
->sa
.sa_restorer
) {
260 /* This is the legacy signal stack switching. */
261 sp
= (unsigned long) ka
->sa
.sa_restorer
;
265 if (fpu
->fpstate_active
) {
266 sp
= fpu__alloc_mathframe(sp
, config_enabled(CONFIG_X86_32
),
267 &buf_fx
, &math_size
);
268 *fpstate
= (void __user
*)sp
;
271 sp
= align_sigframe(sp
- frame_size
);
274 * If we are on the alternate signal stack and would overflow it, don't.
275 * Return an always-bogus address instead so we will die with SIGSEGV.
277 if (onsigstack
&& !likely(on_sig_stack(sp
)))
278 return (void __user
*)-1L;
280 /* save i387 and extended state */
281 if (fpu
->fpstate_active
&&
282 copy_fpstate_to_sigframe(*fpstate
, (void __user
*)buf_fx
, math_size
) < 0)
283 return (void __user
*)-1L;
285 return (void __user
*)sp
;
289 static const struct {
293 } __attribute__((packed
)) retcode
= {
294 0xb858, /* popl %eax; movl $..., %eax */
296 0x80cd, /* int $0x80 */
299 static const struct {
304 } __attribute__((packed
)) rt_retcode
= {
305 0xb8, /* movl $..., %eax */
307 0x80cd, /* int $0x80 */
312 __setup_frame(int sig
, struct ksignal
*ksig
, sigset_t
*set
,
313 struct pt_regs
*regs
)
315 struct sigframe __user
*frame
;
316 void __user
*restorer
;
318 void __user
*fpstate
= NULL
;
320 frame
= get_sigframe(&ksig
->ka
, regs
, sizeof(*frame
), &fpstate
);
322 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
325 if (__put_user(sig
, &frame
->sig
))
328 if (setup_sigcontext(&frame
->sc
, fpstate
, regs
, set
->sig
[0]))
331 if (_NSIG_WORDS
> 1) {
332 if (__copy_to_user(&frame
->extramask
, &set
->sig
[1],
333 sizeof(frame
->extramask
)))
337 if (current
->mm
->context
.vdso
)
338 restorer
= current
->mm
->context
.vdso
+
339 vdso_image_32
.sym___kernel_sigreturn
;
341 restorer
= &frame
->retcode
;
342 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
)
343 restorer
= ksig
->ka
.sa
.sa_restorer
;
345 /* Set up to return from userspace. */
346 err
|= __put_user(restorer
, &frame
->pretcode
);
349 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
351 * WE DO NOT USE IT ANY MORE! It's only left here for historical
352 * reasons and because gdb uses it as a signature to notice
353 * signal handler stack frames.
355 err
|= __put_user(*((u64
*)&retcode
), (u64
*)frame
->retcode
);
360 /* Set up registers for signal handler */
361 regs
->sp
= (unsigned long)frame
;
362 regs
->ip
= (unsigned long)ksig
->ka
.sa
.sa_handler
;
363 regs
->ax
= (unsigned long)sig
;
367 regs
->ds
= __USER_DS
;
368 regs
->es
= __USER_DS
;
369 regs
->ss
= __USER_DS
;
370 regs
->cs
= __USER_CS
;
375 static int __setup_rt_frame(int sig
, struct ksignal
*ksig
,
376 sigset_t
*set
, struct pt_regs
*regs
)
378 struct rt_sigframe __user
*frame
;
379 void __user
*restorer
;
381 void __user
*fpstate
= NULL
;
383 frame
= get_sigframe(&ksig
->ka
, regs
, sizeof(*frame
), &fpstate
);
385 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
389 put_user_ex(sig
, &frame
->sig
);
390 put_user_ex(&frame
->info
, &frame
->pinfo
);
391 put_user_ex(&frame
->uc
, &frame
->puc
);
393 /* Create the ucontext. */
395 put_user_ex(UC_FP_XSTATE
, &frame
->uc
.uc_flags
);
397 put_user_ex(0, &frame
->uc
.uc_flags
);
398 put_user_ex(0, &frame
->uc
.uc_link
);
399 save_altstack_ex(&frame
->uc
.uc_stack
, regs
->sp
);
401 /* Set up to return from userspace. */
402 restorer
= current
->mm
->context
.vdso
+
403 vdso_image_32
.sym___kernel_rt_sigreturn
;
404 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
)
405 restorer
= ksig
->ka
.sa
.sa_restorer
;
406 put_user_ex(restorer
, &frame
->pretcode
);
409 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
411 * WE DO NOT USE IT ANY MORE! It's only left here for historical
412 * reasons and because gdb uses it as a signature to notice
413 * signal handler stack frames.
415 put_user_ex(*((u64
*)&rt_retcode
), (u64
*)frame
->retcode
);
416 } put_user_catch(err
);
418 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
419 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, fpstate
,
421 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
426 /* Set up registers for signal handler */
427 regs
->sp
= (unsigned long)frame
;
428 regs
->ip
= (unsigned long)ksig
->ka
.sa
.sa_handler
;
429 regs
->ax
= (unsigned long)sig
;
430 regs
->dx
= (unsigned long)&frame
->info
;
431 regs
->cx
= (unsigned long)&frame
->uc
;
433 regs
->ds
= __USER_DS
;
434 regs
->es
= __USER_DS
;
435 regs
->ss
= __USER_DS
;
436 regs
->cs
= __USER_CS
;
440 #else /* !CONFIG_X86_32 */
441 static unsigned long frame_uc_flags(struct pt_regs
*regs
)
446 flags
= UC_FP_XSTATE
| UC_SIGCONTEXT_SS
;
448 flags
= UC_SIGCONTEXT_SS
;
450 if (likely(user_64bit_mode(regs
)))
451 flags
|= UC_STRICT_RESTORE_SS
;
456 static int __setup_rt_frame(int sig
, struct ksignal
*ksig
,
457 sigset_t
*set
, struct pt_regs
*regs
)
459 struct rt_sigframe __user
*frame
;
460 void __user
*fp
= NULL
;
463 frame
= get_sigframe(&ksig
->ka
, regs
, sizeof(struct rt_sigframe
), &fp
);
465 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
468 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
) {
469 if (copy_siginfo_to_user(&frame
->info
, &ksig
->info
))
474 /* Create the ucontext. */
475 put_user_ex(frame_uc_flags(regs
), &frame
->uc
.uc_flags
);
476 put_user_ex(0, &frame
->uc
.uc_link
);
477 save_altstack_ex(&frame
->uc
.uc_stack
, regs
->sp
);
479 /* Set up to return from userspace. If provided, use a stub
480 already in userspace. */
481 /* x86-64 should always use SA_RESTORER. */
482 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
) {
483 put_user_ex(ksig
->ka
.sa
.sa_restorer
, &frame
->pretcode
);
485 /* could use a vstub here */
488 } put_user_catch(err
);
490 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, fp
, regs
, set
->sig
[0]);
491 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
496 /* Set up registers for signal handler */
498 /* In case the signal handler was declared without prototypes */
501 /* This also works for non SA_SIGINFO handlers because they expect the
502 next argument after the signal number on the stack. */
503 regs
->si
= (unsigned long)&frame
->info
;
504 regs
->dx
= (unsigned long)&frame
->uc
;
505 regs
->ip
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
507 regs
->sp
= (unsigned long)frame
;
510 * Set up the CS and SS registers to run signal handlers in
511 * 64-bit mode, even if the handler happens to be interrupting
512 * 32-bit or 16-bit code.
514 * SS is subtle. In 64-bit mode, we don't need any particular
515 * SS descriptor, but we do need SS to be valid. It's possible
516 * that the old SS is entirely bogus -- this can happen if the
517 * signal we're trying to deliver is #GP or #SS caused by a bad
518 * SS value. We also have a compatbility issue here: DOSEMU
519 * relies on the contents of the SS register indicating the
520 * SS value at the time of the signal, even though that code in
521 * DOSEMU predates sigreturn's ability to restore SS. (DOSEMU
522 * avoids relying on sigreturn to restore SS; instead it uses
523 * a trampoline.) So we do our best: if the old SS was valid,
524 * we keep it. Otherwise we replace it.
526 regs
->cs
= __USER_CS
;
528 if (unlikely(regs
->ss
!= __USER_DS
))
529 force_valid_ss(regs
);
533 #endif /* CONFIG_X86_32 */
535 static int x32_setup_rt_frame(struct ksignal
*ksig
,
536 compat_sigset_t
*set
,
537 struct pt_regs
*regs
)
539 #ifdef CONFIG_X86_X32_ABI
540 struct rt_sigframe_x32 __user
*frame
;
541 void __user
*restorer
;
543 void __user
*fpstate
= NULL
;
545 frame
= get_sigframe(&ksig
->ka
, regs
, sizeof(*frame
), &fpstate
);
547 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
550 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
) {
551 if (copy_siginfo_to_user32(&frame
->info
, &ksig
->info
))
556 /* Create the ucontext. */
557 put_user_ex(frame_uc_flags(regs
), &frame
->uc
.uc_flags
);
558 put_user_ex(0, &frame
->uc
.uc_link
);
559 compat_save_altstack_ex(&frame
->uc
.uc_stack
, regs
->sp
);
560 put_user_ex(0, &frame
->uc
.uc__pad0
);
562 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
) {
563 restorer
= ksig
->ka
.sa
.sa_restorer
;
565 /* could use a vstub here */
569 put_user_ex(restorer
, &frame
->pretcode
);
570 } put_user_catch(err
);
572 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, fpstate
,
574 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
579 /* Set up registers for signal handler */
580 regs
->sp
= (unsigned long) frame
;
581 regs
->ip
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
583 /* We use the x32 calling convention here... */
584 regs
->di
= ksig
->sig
;
585 regs
->si
= (unsigned long) &frame
->info
;
586 regs
->dx
= (unsigned long) &frame
->uc
;
588 loadsegment(ds
, __USER_DS
);
589 loadsegment(es
, __USER_DS
);
591 regs
->cs
= __USER_CS
;
592 regs
->ss
= __USER_DS
;
593 #endif /* CONFIG_X86_X32_ABI */
599 * Do a signal return; undo the signal stack.
602 asmlinkage
unsigned long sys_sigreturn(void)
604 struct pt_regs
*regs
= current_pt_regs();
605 struct sigframe __user
*frame
;
608 frame
= (struct sigframe __user
*)(regs
->sp
- 8);
610 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
612 if (__get_user(set
.sig
[0], &frame
->sc
.oldmask
) || (_NSIG_WORDS
> 1
613 && __copy_from_user(&set
.sig
[1], &frame
->extramask
,
614 sizeof(frame
->extramask
))))
617 set_current_blocked(&set
);
620 * x86_32 has no uc_flags bits relevant to restore_sigcontext.
621 * Save a few cycles by skipping the __get_user.
623 if (restore_sigcontext(regs
, &frame
->sc
, 0))
628 signal_fault(regs
, frame
, "sigreturn");
632 #endif /* CONFIG_X86_32 */
634 asmlinkage
long sys_rt_sigreturn(void)
636 struct pt_regs
*regs
= current_pt_regs();
637 struct rt_sigframe __user
*frame
;
639 unsigned long uc_flags
;
641 frame
= (struct rt_sigframe __user
*)(regs
->sp
- sizeof(long));
642 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
644 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
646 if (__get_user(uc_flags
, &frame
->uc
.uc_flags
))
649 set_current_blocked(&set
);
651 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, uc_flags
))
654 if (restore_altstack(&frame
->uc
.uc_stack
))
660 signal_fault(regs
, frame
, "rt_sigreturn");
664 static inline int is_ia32_compat_frame(void)
666 return config_enabled(CONFIG_IA32_EMULATION
) &&
667 test_thread_flag(TIF_IA32
);
670 static inline int is_ia32_frame(void)
672 return config_enabled(CONFIG_X86_32
) || is_ia32_compat_frame();
675 static inline int is_x32_frame(void)
677 return config_enabled(CONFIG_X86_X32_ABI
) && test_thread_flag(TIF_X32
);
681 setup_rt_frame(struct ksignal
*ksig
, struct pt_regs
*regs
)
683 int usig
= ksig
->sig
;
684 sigset_t
*set
= sigmask_to_save();
685 compat_sigset_t
*cset
= (compat_sigset_t
*) set
;
687 /* Set up the stack frame */
688 if (is_ia32_frame()) {
689 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
690 return ia32_setup_rt_frame(usig
, ksig
, cset
, regs
);
692 return ia32_setup_frame(usig
, ksig
, cset
, regs
);
693 } else if (is_x32_frame()) {
694 return x32_setup_rt_frame(ksig
, cset
, regs
);
696 return __setup_rt_frame(ksig
->sig
, ksig
, set
, regs
);
701 handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
703 bool stepping
, failed
;
704 struct fpu
*fpu
= ¤t
->thread
.fpu
;
706 if (v8086_mode(regs
))
707 save_v86_state((struct kernel_vm86_regs
*) regs
, VM86_SIGNAL
);
709 /* Are we from a system call? */
710 if (syscall_get_nr(current
, regs
) >= 0) {
711 /* If so, check system call restarting.. */
712 switch (syscall_get_error(current
, regs
)) {
713 case -ERESTART_RESTARTBLOCK
:
714 case -ERESTARTNOHAND
:
719 if (!(ksig
->ka
.sa
.sa_flags
& SA_RESTART
)) {
724 case -ERESTARTNOINTR
:
725 regs
->ax
= regs
->orig_ax
;
732 * If TF is set due to a debugger (TIF_FORCED_TF), clear TF now
733 * so that register information in the sigcontext is correct and
734 * then notify the tracer before entering the signal handler.
736 stepping
= test_thread_flag(TIF_SINGLESTEP
);
738 user_disable_single_step(current
);
740 failed
= (setup_rt_frame(ksig
, regs
) < 0);
743 * Clear the direction flag as per the ABI for function entry.
745 * Clear RF when entering the signal handler, because
746 * it might disable possible debug exception from the
749 * Clear TF for the case when it wasn't set by debugger to
750 * avoid the recursive send_sigtrap() in SIGTRAP handler.
752 regs
->flags
&= ~(X86_EFLAGS_DF
|X86_EFLAGS_RF
|X86_EFLAGS_TF
);
754 * Ensure the signal handler starts with the new fpu state.
756 if (fpu
->fpstate_active
)
759 signal_setup_done(failed
, ksig
, stepping
);
762 static inline unsigned long get_nr_restart_syscall(const struct pt_regs
*regs
)
766 return __NR_ia32_restart_syscall
;
768 #ifdef CONFIG_X86_X32_ABI
769 return __NR_restart_syscall
| (regs
->orig_ax
& __X32_SYSCALL_BIT
);
771 return __NR_restart_syscall
;
776 * Note that 'init' is a special process: it doesn't get signals it doesn't
777 * want to handle. Thus you cannot kill init even with a SIGKILL even by
780 void do_signal(struct pt_regs
*regs
)
784 if (get_signal(&ksig
)) {
785 /* Whee! Actually deliver the signal. */
786 handle_signal(&ksig
, regs
);
790 /* Did we come from a system call? */
791 if (syscall_get_nr(current
, regs
) >= 0) {
792 /* Restart the system call - no handlers present */
793 switch (syscall_get_error(current
, regs
)) {
794 case -ERESTARTNOHAND
:
796 case -ERESTARTNOINTR
:
797 regs
->ax
= regs
->orig_ax
;
801 case -ERESTART_RESTARTBLOCK
:
802 regs
->ax
= get_nr_restart_syscall(regs
);
809 * If there's no signal to deliver, we just put the saved sigmask
812 restore_saved_sigmask();
815 void signal_fault(struct pt_regs
*regs
, void __user
*frame
, char *where
)
817 struct task_struct
*me
= current
;
819 if (show_unhandled_signals
&& printk_ratelimit()) {
821 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
822 task_pid_nr(current
) > 1 ? KERN_INFO
: KERN_EMERG
,
823 me
->comm
, me
->pid
, where
, frame
,
824 regs
->ip
, regs
->sp
, regs
->orig_ax
);
825 print_vma_addr(" in ", regs
->ip
);
829 force_sig(SIGSEGV
, me
);
832 #ifdef CONFIG_X86_X32_ABI
833 asmlinkage
long sys32_x32_rt_sigreturn(void)
835 struct pt_regs
*regs
= current_pt_regs();
836 struct rt_sigframe_x32 __user
*frame
;
838 unsigned long uc_flags
;
840 frame
= (struct rt_sigframe_x32 __user
*)(regs
->sp
- 8);
842 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
844 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
846 if (__get_user(uc_flags
, &frame
->uc
.uc_flags
))
849 set_current_blocked(&set
);
851 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, uc_flags
))
854 if (compat_restore_altstack(&frame
->uc
.uc_stack
))
860 signal_fault(regs
, frame
, "x32 rt_sigreturn");