2 * Based on arch/arm/kernel/signal.c
4 * Copyright (C) 1995-2009 Russell King
5 * Copyright (C) 2012 ARM Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/cache.h>
21 #include <linux/compat.h>
22 #include <linux/errno.h>
23 #include <linux/kernel.h>
24 #include <linux/signal.h>
25 #include <linux/personality.h>
26 #include <linux/freezer.h>
27 #include <linux/stddef.h>
28 #include <linux/uaccess.h>
29 #include <linux/sizes.h>
30 #include <linux/string.h>
31 #include <linux/tracehook.h>
32 #include <linux/ratelimit.h>
33 #include <linux/syscalls.h>
35 #include <asm/daifflags.h>
36 #include <asm/debug-monitors.h>
38 #include <asm/cacheflush.h>
39 #include <asm/ucontext.h>
40 #include <asm/unistd.h>
41 #include <asm/fpsimd.h>
42 #include <asm/ptrace.h>
43 #include <asm/signal32.h>
44 #include <asm/traps.h>
48 * Do a signal return; undo the signal stack. These are aligned to 128-bit.
60 struct rt_sigframe_user_layout
{
61 struct rt_sigframe __user
*sigframe
;
62 struct frame_record __user
*next_frame
;
64 unsigned long size
; /* size of allocated sigframe data */
65 unsigned long limit
; /* largest allowed size */
67 unsigned long fpsimd_offset
;
68 unsigned long esr_offset
;
69 unsigned long sve_offset
;
70 unsigned long extra_offset
;
71 unsigned long end_offset
;
74 #define BASE_SIGFRAME_SIZE round_up(sizeof(struct rt_sigframe), 16)
75 #define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
76 #define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
78 static void init_user_layout(struct rt_sigframe_user_layout
*user
)
80 const size_t reserved_size
=
81 sizeof(user
->sigframe
->uc
.uc_mcontext
.__reserved
);
83 memset(user
, 0, sizeof(*user
));
84 user
->size
= offsetof(struct rt_sigframe
, uc
.uc_mcontext
.__reserved
);
86 user
->limit
= user
->size
+ reserved_size
;
88 user
->limit
-= TERMINATOR_SIZE
;
89 user
->limit
-= EXTRA_CONTEXT_SIZE
;
90 /* Reserve space for extension and terminator ^ */
93 static size_t sigframe_size(struct rt_sigframe_user_layout
const *user
)
95 return round_up(max(user
->size
, sizeof(struct rt_sigframe
)), 16);
99 * Sanity limit on the approximate maximum size of signal frame we'll
100 * try to generate. Stack alignment padding and the frame record are
101 * not taken into account. This limit is not a guarantee and is
104 #define SIGFRAME_MAXSZ SZ_64K
106 static int __sigframe_alloc(struct rt_sigframe_user_layout
*user
,
107 unsigned long *offset
, size_t size
, bool extend
)
109 size_t padded_size
= round_up(size
, 16);
111 if (padded_size
> user
->limit
- user
->size
&&
112 !user
->extra_offset
&&
116 user
->limit
+= EXTRA_CONTEXT_SIZE
;
117 ret
= __sigframe_alloc(user
, &user
->extra_offset
,
118 sizeof(struct extra_context
), false);
120 user
->limit
-= EXTRA_CONTEXT_SIZE
;
124 /* Reserve space for the __reserved[] terminator */
125 user
->size
+= TERMINATOR_SIZE
;
128 * Allow expansion up to SIGFRAME_MAXSZ, ensuring space for
131 user
->limit
= SIGFRAME_MAXSZ
- TERMINATOR_SIZE
;
134 /* Still not enough space? Bad luck! */
135 if (padded_size
> user
->limit
- user
->size
)
138 *offset
= user
->size
;
139 user
->size
+= padded_size
;
145 * Allocate space for an optional record of <size> bytes in the user
146 * signal frame. The offset from the signal frame base address to the
147 * allocated block is assigned to *offset.
149 static int sigframe_alloc(struct rt_sigframe_user_layout
*user
,
150 unsigned long *offset
, size_t size
)
152 return __sigframe_alloc(user
, offset
, size
, true);
155 /* Allocate the null terminator record and prevent further allocations */
156 static int sigframe_alloc_end(struct rt_sigframe_user_layout
*user
)
160 /* Un-reserve the space reserved for the terminator: */
161 user
->limit
+= TERMINATOR_SIZE
;
163 ret
= sigframe_alloc(user
, &user
->end_offset
,
164 sizeof(struct _aarch64_ctx
));
168 /* Prevent further allocation: */
169 user
->limit
= user
->size
;
173 static void __user
*apply_user_offset(
174 struct rt_sigframe_user_layout
const *user
, unsigned long offset
)
176 char __user
*base
= (char __user
*)user
->sigframe
;
178 return base
+ offset
;
181 static int preserve_fpsimd_context(struct fpsimd_context __user
*ctx
)
183 struct user_fpsimd_state
const *fpsimd
=
184 ¤t
->thread
.uw
.fpsimd_state
;
187 /* copy the FP and status/control registers */
188 err
= __copy_to_user(ctx
->vregs
, fpsimd
->vregs
, sizeof(fpsimd
->vregs
));
189 __put_user_error(fpsimd
->fpsr
, &ctx
->fpsr
, err
);
190 __put_user_error(fpsimd
->fpcr
, &ctx
->fpcr
, err
);
192 /* copy the magic/size information */
193 __put_user_error(FPSIMD_MAGIC
, &ctx
->head
.magic
, err
);
194 __put_user_error(sizeof(struct fpsimd_context
), &ctx
->head
.size
, err
);
196 return err
? -EFAULT
: 0;
199 static int restore_fpsimd_context(struct fpsimd_context __user
*ctx
)
201 struct user_fpsimd_state fpsimd
;
205 /* check the magic/size information */
206 __get_user_error(magic
, &ctx
->head
.magic
, err
);
207 __get_user_error(size
, &ctx
->head
.size
, err
);
210 if (magic
!= FPSIMD_MAGIC
|| size
!= sizeof(struct fpsimd_context
))
213 /* copy the FP and status/control registers */
214 err
= __copy_from_user(fpsimd
.vregs
, ctx
->vregs
,
215 sizeof(fpsimd
.vregs
));
216 __get_user_error(fpsimd
.fpsr
, &ctx
->fpsr
, err
);
217 __get_user_error(fpsimd
.fpcr
, &ctx
->fpcr
, err
);
219 clear_thread_flag(TIF_SVE
);
221 /* load the hardware registers from the fpsimd_state structure */
223 fpsimd_update_current_state(&fpsimd
);
225 return err
? -EFAULT
: 0;
230 struct fpsimd_context __user
*fpsimd
;
231 struct sve_context __user
*sve
;
234 #ifdef CONFIG_ARM64_SVE
236 static int preserve_sve_context(struct sve_context __user
*ctx
)
239 u16 reserved
[ARRAY_SIZE(ctx
->__reserved
)];
240 unsigned int vl
= current
->thread
.sve_vl
;
243 if (test_thread_flag(TIF_SVE
))
244 vq
= sve_vq_from_vl(vl
);
246 memset(reserved
, 0, sizeof(reserved
));
248 __put_user_error(SVE_MAGIC
, &ctx
->head
.magic
, err
);
249 __put_user_error(round_up(SVE_SIG_CONTEXT_SIZE(vq
), 16),
250 &ctx
->head
.size
, err
);
251 __put_user_error(vl
, &ctx
->vl
, err
);
252 BUILD_BUG_ON(sizeof(ctx
->__reserved
) != sizeof(reserved
));
253 err
|= __copy_to_user(&ctx
->__reserved
, reserved
, sizeof(reserved
));
257 * This assumes that the SVE state has already been saved to
258 * the task struct by calling preserve_fpsimd_context().
260 err
|= __copy_to_user((char __user
*)ctx
+ SVE_SIG_REGS_OFFSET
,
261 current
->thread
.sve_state
,
262 SVE_SIG_REGS_SIZE(vq
));
265 return err
? -EFAULT
: 0;
268 static int restore_sve_fpsimd_context(struct user_ctxs
*user
)
272 struct user_fpsimd_state fpsimd
;
273 struct sve_context sve
;
275 if (__copy_from_user(&sve
, user
->sve
, sizeof(sve
)))
278 if (sve
.vl
!= current
->thread
.sve_vl
)
281 if (sve
.head
.size
<= sizeof(*user
->sve
)) {
282 clear_thread_flag(TIF_SVE
);
286 vq
= sve_vq_from_vl(sve
.vl
);
288 if (sve
.head
.size
< SVE_SIG_CONTEXT_SIZE(vq
))
292 * Careful: we are about __copy_from_user() directly into
293 * thread.sve_state with preemption enabled, so protection is
294 * needed to prevent a racing context switch from writing stale
295 * registers back over the new data.
298 fpsimd_flush_task_state(current
);
299 /* From now, fpsimd_thread_switch() won't touch thread.sve_state */
302 err
= __copy_from_user(current
->thread
.sve_state
,
303 (char __user
const *)user
->sve
+
305 SVE_SIG_REGS_SIZE(vq
));
309 set_thread_flag(TIF_SVE
);
312 /* copy the FP and status/control registers */
313 /* restore_sigframe() already checked that user->fpsimd != NULL. */
314 err
= __copy_from_user(fpsimd
.vregs
, user
->fpsimd
->vregs
,
315 sizeof(fpsimd
.vregs
));
316 __get_user_error(fpsimd
.fpsr
, &user
->fpsimd
->fpsr
, err
);
317 __get_user_error(fpsimd
.fpcr
, &user
->fpsimd
->fpcr
, err
);
319 /* load the hardware registers from the fpsimd_state structure */
321 fpsimd_update_current_state(&fpsimd
);
323 return err
? -EFAULT
: 0;
326 #else /* ! CONFIG_ARM64_SVE */
328 /* Turn any non-optimised out attempts to use these into a link error: */
329 extern int preserve_sve_context(void __user
*ctx
);
330 extern int restore_sve_fpsimd_context(struct user_ctxs
*user
);
332 #endif /* ! CONFIG_ARM64_SVE */
335 static int parse_user_sigframe(struct user_ctxs
*user
,
336 struct rt_sigframe __user
*sf
)
338 struct sigcontext __user
*const sc
= &sf
->uc
.uc_mcontext
;
339 struct _aarch64_ctx __user
*head
;
340 char __user
*base
= (char __user
*)&sc
->__reserved
;
342 size_t limit
= sizeof(sc
->__reserved
);
343 bool have_extra_context
= false;
344 char const __user
*const sfp
= (char const __user
*)sf
;
349 if (!IS_ALIGNED((unsigned long)base
, 16))
355 char const __user
*userp
;
356 struct extra_context
const __user
*extra
;
359 struct _aarch64_ctx
const __user
*end
;
360 u32 end_magic
, end_size
;
362 if (limit
- offset
< sizeof(*head
))
365 if (!IS_ALIGNED(offset
, 16))
368 head
= (struct _aarch64_ctx __user
*)(base
+ offset
);
369 __get_user_error(magic
, &head
->magic
, err
);
370 __get_user_error(size
, &head
->size
, err
);
374 if (limit
- offset
< size
)
388 if (size
< sizeof(*user
->fpsimd
))
391 user
->fpsimd
= (struct fpsimd_context __user
*)head
;
399 if (!system_supports_sve())
405 if (size
< sizeof(*user
->sve
))
408 user
->sve
= (struct sve_context __user
*)head
;
412 if (have_extra_context
)
415 if (size
< sizeof(*extra
))
418 userp
= (char const __user
*)head
;
420 extra
= (struct extra_context
const __user
*)userp
;
423 __get_user_error(extra_datap
, &extra
->datap
, err
);
424 __get_user_error(extra_size
, &extra
->size
, err
);
428 /* Check for the dummy terminator in __reserved[]: */
430 if (limit
- offset
- size
< TERMINATOR_SIZE
)
433 end
= (struct _aarch64_ctx
const __user
*)userp
;
434 userp
+= TERMINATOR_SIZE
;
436 __get_user_error(end_magic
, &end
->magic
, err
);
437 __get_user_error(end_size
, &end
->size
, err
);
441 if (end_magic
|| end_size
)
444 /* Prevent looping/repeated parsing of extra_context */
445 have_extra_context
= true;
447 base
= (__force
void __user
*)extra_datap
;
448 if (!IS_ALIGNED((unsigned long)base
, 16))
451 if (!IS_ALIGNED(extra_size
, 16))
457 /* Reject "unreasonably large" frames: */
458 if (extra_size
> sfp
+ SIGFRAME_MAXSZ
- userp
)
462 * Ignore trailing terminator in __reserved[]
463 * and start parsing extra data:
468 if (!access_ok(base
, limit
))
477 if (size
< sizeof(*head
))
480 if (limit
- offset
< size
)
493 static int restore_sigframe(struct pt_regs
*regs
,
494 struct rt_sigframe __user
*sf
)
498 struct user_ctxs user
;
500 err
= __copy_from_user(&set
, &sf
->uc
.uc_sigmask
, sizeof(set
));
502 set_current_blocked(&set
);
504 for (i
= 0; i
< 31; i
++)
505 __get_user_error(regs
->regs
[i
], &sf
->uc
.uc_mcontext
.regs
[i
],
507 __get_user_error(regs
->sp
, &sf
->uc
.uc_mcontext
.sp
, err
);
508 __get_user_error(regs
->pc
, &sf
->uc
.uc_mcontext
.pc
, err
);
509 __get_user_error(regs
->pstate
, &sf
->uc
.uc_mcontext
.pstate
, err
);
512 * Avoid sys_rt_sigreturn() restarting.
514 forget_syscall(regs
);
516 err
|= !valid_user_regs(®s
->user_regs
, current
);
518 err
= parse_user_sigframe(&user
, sf
);
525 if (!system_supports_sve())
528 err
= restore_sve_fpsimd_context(&user
);
530 err
= restore_fpsimd_context(user
.fpsimd
);
537 SYSCALL_DEFINE0(rt_sigreturn
)
539 struct pt_regs
*regs
= current_pt_regs();
540 struct rt_sigframe __user
*frame
;
542 /* Always make any pending restarted system calls return -EINTR */
543 current
->restart_block
.fn
= do_no_restart_syscall
;
546 * Since we stacked the signal on a 128-bit boundary, then 'sp' should
547 * be word aligned here.
552 frame
= (struct rt_sigframe __user
*)regs
->sp
;
554 if (!access_ok(frame
, sizeof (*frame
)))
557 if (restore_sigframe(regs
, frame
))
560 if (restore_altstack(&frame
->uc
.uc_stack
))
563 return regs
->regs
[0];
566 arm64_notify_segfault(regs
->sp
);
571 * Determine the layout of optional records in the signal frame
573 * add_all: if true, lays out the biggest possible signal frame for
574 * this task; otherwise, generates a layout for the current state
577 static int setup_sigframe_layout(struct rt_sigframe_user_layout
*user
,
582 err
= sigframe_alloc(user
, &user
->fpsimd_offset
,
583 sizeof(struct fpsimd_context
));
587 /* fault information, if valid */
588 if (add_all
|| current
->thread
.fault_code
) {
589 err
= sigframe_alloc(user
, &user
->esr_offset
,
590 sizeof(struct esr_context
));
595 if (system_supports_sve()) {
598 if (add_all
|| test_thread_flag(TIF_SVE
)) {
602 vl
= current
->thread
.sve_vl
;
604 vq
= sve_vq_from_vl(vl
);
607 err
= sigframe_alloc(user
, &user
->sve_offset
,
608 SVE_SIG_CONTEXT_SIZE(vq
));
613 return sigframe_alloc_end(user
);
616 static int setup_sigframe(struct rt_sigframe_user_layout
*user
,
617 struct pt_regs
*regs
, sigset_t
*set
)
620 struct rt_sigframe __user
*sf
= user
->sigframe
;
622 /* set up the stack frame for unwinding */
623 __put_user_error(regs
->regs
[29], &user
->next_frame
->fp
, err
);
624 __put_user_error(regs
->regs
[30], &user
->next_frame
->lr
, err
);
626 for (i
= 0; i
< 31; i
++)
627 __put_user_error(regs
->regs
[i
], &sf
->uc
.uc_mcontext
.regs
[i
],
629 __put_user_error(regs
->sp
, &sf
->uc
.uc_mcontext
.sp
, err
);
630 __put_user_error(regs
->pc
, &sf
->uc
.uc_mcontext
.pc
, err
);
631 __put_user_error(regs
->pstate
, &sf
->uc
.uc_mcontext
.pstate
, err
);
633 __put_user_error(current
->thread
.fault_address
, &sf
->uc
.uc_mcontext
.fault_address
, err
);
635 err
|= __copy_to_user(&sf
->uc
.uc_sigmask
, set
, sizeof(*set
));
638 struct fpsimd_context __user
*fpsimd_ctx
=
639 apply_user_offset(user
, user
->fpsimd_offset
);
640 err
|= preserve_fpsimd_context(fpsimd_ctx
);
643 /* fault information, if valid */
644 if (err
== 0 && user
->esr_offset
) {
645 struct esr_context __user
*esr_ctx
=
646 apply_user_offset(user
, user
->esr_offset
);
648 __put_user_error(ESR_MAGIC
, &esr_ctx
->head
.magic
, err
);
649 __put_user_error(sizeof(*esr_ctx
), &esr_ctx
->head
.size
, err
);
650 __put_user_error(current
->thread
.fault_code
, &esr_ctx
->esr
, err
);
653 /* Scalable Vector Extension state, if present */
654 if (system_supports_sve() && err
== 0 && user
->sve_offset
) {
655 struct sve_context __user
*sve_ctx
=
656 apply_user_offset(user
, user
->sve_offset
);
657 err
|= preserve_sve_context(sve_ctx
);
660 if (err
== 0 && user
->extra_offset
) {
661 char __user
*sfp
= (char __user
*)user
->sigframe
;
663 apply_user_offset(user
, user
->extra_offset
);
665 struct extra_context __user
*extra
;
666 struct _aarch64_ctx __user
*end
;
670 extra
= (struct extra_context __user
*)userp
;
671 userp
+= EXTRA_CONTEXT_SIZE
;
673 end
= (struct _aarch64_ctx __user
*)userp
;
674 userp
+= TERMINATOR_SIZE
;
677 * extra_datap is just written to the signal frame.
678 * The value gets cast back to a void __user *
681 extra_datap
= (__force u64
)userp
;
682 extra_size
= sfp
+ round_up(user
->size
, 16) - userp
;
684 __put_user_error(EXTRA_MAGIC
, &extra
->head
.magic
, err
);
685 __put_user_error(EXTRA_CONTEXT_SIZE
, &extra
->head
.size
, err
);
686 __put_user_error(extra_datap
, &extra
->datap
, err
);
687 __put_user_error(extra_size
, &extra
->size
, err
);
689 /* Add the terminator */
690 __put_user_error(0, &end
->magic
, err
);
691 __put_user_error(0, &end
->size
, err
);
694 /* set the "end" magic */
696 struct _aarch64_ctx __user
*end
=
697 apply_user_offset(user
, user
->end_offset
);
699 __put_user_error(0, &end
->magic
, err
);
700 __put_user_error(0, &end
->size
, err
);
706 static int get_sigframe(struct rt_sigframe_user_layout
*user
,
707 struct ksignal
*ksig
, struct pt_regs
*regs
)
709 unsigned long sp
, sp_top
;
712 init_user_layout(user
);
713 err
= setup_sigframe_layout(user
, false);
717 sp
= sp_top
= sigsp(regs
->sp
, ksig
);
719 sp
= round_down(sp
- sizeof(struct frame_record
), 16);
720 user
->next_frame
= (struct frame_record __user
*)sp
;
722 sp
= round_down(sp
, 16) - sigframe_size(user
);
723 user
->sigframe
= (struct rt_sigframe __user
*)sp
;
726 * Check that we can actually write to the signal frame.
728 if (!access_ok(user
->sigframe
, sp_top
- sp
))
734 static void setup_return(struct pt_regs
*regs
, struct k_sigaction
*ka
,
735 struct rt_sigframe_user_layout
*user
, int usig
)
737 __sigrestore_t sigtramp
;
739 regs
->regs
[0] = usig
;
740 regs
->sp
= (unsigned long)user
->sigframe
;
741 regs
->regs
[29] = (unsigned long)&user
->next_frame
->fp
;
742 regs
->pc
= (unsigned long)ka
->sa
.sa_handler
;
744 if (ka
->sa
.sa_flags
& SA_RESTORER
)
745 sigtramp
= ka
->sa
.sa_restorer
;
747 sigtramp
= VDSO_SYMBOL(current
->mm
->context
.vdso
, sigtramp
);
749 regs
->regs
[30] = (unsigned long)sigtramp
;
752 static int setup_rt_frame(int usig
, struct ksignal
*ksig
, sigset_t
*set
,
753 struct pt_regs
*regs
)
755 struct rt_sigframe_user_layout user
;
756 struct rt_sigframe __user
*frame
;
759 fpsimd_signal_preserve_current_state();
761 if (get_sigframe(&user
, ksig
, regs
))
764 frame
= user
.sigframe
;
766 __put_user_error(0, &frame
->uc
.uc_flags
, err
);
767 __put_user_error(NULL
, &frame
->uc
.uc_link
, err
);
769 err
|= __save_altstack(&frame
->uc
.uc_stack
, regs
->sp
);
770 err
|= setup_sigframe(&user
, regs
, set
);
772 setup_return(regs
, &ksig
->ka
, &user
, usig
);
773 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
) {
774 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
775 regs
->regs
[1] = (unsigned long)&frame
->info
;
776 regs
->regs
[2] = (unsigned long)&frame
->uc
;
783 static void setup_restart_syscall(struct pt_regs
*regs
)
785 if (is_compat_task())
786 compat_setup_restart_syscall(regs
);
788 regs
->regs
[8] = __NR_restart_syscall
;
792 * OK, we're invoking a handler
794 static void handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
796 struct task_struct
*tsk
= current
;
797 sigset_t
*oldset
= sigmask_to_save();
798 int usig
= ksig
->sig
;
801 rseq_signal_deliver(ksig
, regs
);
804 * Set up the stack frame
806 if (is_compat_task()) {
807 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
808 ret
= compat_setup_rt_frame(usig
, ksig
, oldset
, regs
);
810 ret
= compat_setup_frame(usig
, ksig
, oldset
, regs
);
812 ret
= setup_rt_frame(usig
, ksig
, oldset
, regs
);
816 * Check that the resulting registers are actually sane.
818 ret
|= !valid_user_regs(®s
->user_regs
, current
);
821 * Fast forward the stepping logic so we step into the signal
825 user_fastforward_single_step(tsk
);
827 signal_setup_done(ret
, ksig
, 0);
831 * Note that 'init' is a special process: it doesn't get signals it doesn't
832 * want to handle. Thus you cannot kill init even with a SIGKILL even by
835 * Note that we go through the signals twice: once to check the signals that
836 * the kernel can handle, and then we build all the user-level signal handling
837 * stack-frames in one go after that.
839 static void do_signal(struct pt_regs
*regs
)
841 unsigned long continue_addr
= 0, restart_addr
= 0;
844 bool syscall
= in_syscall(regs
);
847 * If we were from a system call, check for system call restarting...
850 continue_addr
= regs
->pc
;
851 restart_addr
= continue_addr
- (compat_thumb_mode(regs
) ? 2 : 4);
852 retval
= regs
->regs
[0];
855 * Avoid additional syscall restarting via ret_to_user.
857 forget_syscall(regs
);
860 * Prepare for system call restart. We do this here so that a
861 * debugger will see the already changed PC.
864 case -ERESTARTNOHAND
:
866 case -ERESTARTNOINTR
:
867 case -ERESTART_RESTARTBLOCK
:
868 regs
->regs
[0] = regs
->orig_x0
;
869 regs
->pc
= restart_addr
;
875 * Get the signal to deliver. When running under ptrace, at this point
876 * the debugger may change all of our registers.
878 if (get_signal(&ksig
)) {
880 * Depending on the signal settings, we may need to revert the
881 * decision to restart the system call, but skip this if a
882 * debugger has chosen to restart at a different PC.
884 if (regs
->pc
== restart_addr
&&
885 (retval
== -ERESTARTNOHAND
||
886 retval
== -ERESTART_RESTARTBLOCK
||
887 (retval
== -ERESTARTSYS
&&
888 !(ksig
.ka
.sa
.sa_flags
& SA_RESTART
)))) {
889 regs
->regs
[0] = -EINTR
;
890 regs
->pc
= continue_addr
;
893 handle_signal(&ksig
, regs
);
898 * Handle restarting a different system call. As above, if a debugger
899 * has chosen to restart at a different PC, ignore the restart.
901 if (syscall
&& regs
->pc
== restart_addr
) {
902 if (retval
== -ERESTART_RESTARTBLOCK
)
903 setup_restart_syscall(regs
);
904 user_rewind_single_step(current
);
907 restore_saved_sigmask();
910 asmlinkage
void do_notify_resume(struct pt_regs
*regs
,
911 unsigned long thread_flags
)
914 * The assembly code enters us with IRQs off, but it hasn't
915 * informed the tracing code of that for efficiency reasons.
916 * Update the trace code with the current status.
918 trace_hardirqs_off();
921 /* Check valid user FS if needed */
922 addr_limit_user_check();
924 if (thread_flags
& _TIF_NEED_RESCHED
) {
925 /* Unmask Debug and SError for the next task */
926 local_daif_restore(DAIF_PROCCTX_NOIRQ
);
930 local_daif_restore(DAIF_PROCCTX
);
932 if (thread_flags
& _TIF_UPROBE
)
933 uprobe_notify_resume(regs
);
935 if (thread_flags
& _TIF_SIGPENDING
)
938 if (thread_flags
& _TIF_NOTIFY_RESUME
) {
939 clear_thread_flag(TIF_NOTIFY_RESUME
);
940 tracehook_notify_resume(regs
);
941 rseq_handle_notify_resume(NULL
, regs
);
944 if (thread_flags
& _TIF_FOREIGN_FPSTATE
)
945 fpsimd_restore_current_state();
949 thread_flags
= READ_ONCE(current_thread_info()->flags
);
950 } while (thread_flags
& _TIF_WORK_MASK
);
953 unsigned long __ro_after_init signal_minsigstksz
;
956 * Determine the stack space required for guaranteed signal devliery.
957 * This function is used to populate AT_MINSIGSTKSZ at process startup.
958 * cpufeatures setup is assumed to be complete.
960 void __init
minsigstksz_setup(void)
962 struct rt_sigframe_user_layout user
;
964 init_user_layout(&user
);
967 * If this fails, SIGFRAME_MAXSZ needs to be enlarged. It won't
968 * be big enough, but it's our best guess:
970 if (WARN_ON(setup_sigframe_layout(&user
, true)))
973 signal_minsigstksz
= sigframe_size(&user
) +
974 round_up(sizeof(struct frame_record
), 16) +
975 16; /* max alignment padding */