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
);
300 /* From now, fpsimd_thread_switch() won't clear TIF_FOREIGN_FPSTATE */
302 set_thread_flag(TIF_FOREIGN_FPSTATE
);
304 /* From now, fpsimd_thread_switch() won't touch thread.sve_state */
307 err
= __copy_from_user(current
->thread
.sve_state
,
308 (char __user
const *)user
->sve
+
310 SVE_SIG_REGS_SIZE(vq
));
314 set_thread_flag(TIF_SVE
);
317 /* copy the FP and status/control registers */
318 /* restore_sigframe() already checked that user->fpsimd != NULL. */
319 err
= __copy_from_user(fpsimd
.vregs
, user
->fpsimd
->vregs
,
320 sizeof(fpsimd
.vregs
));
321 __get_user_error(fpsimd
.fpsr
, &user
->fpsimd
->fpsr
, err
);
322 __get_user_error(fpsimd
.fpcr
, &user
->fpsimd
->fpcr
, err
);
324 /* load the hardware registers from the fpsimd_state structure */
326 fpsimd_update_current_state(&fpsimd
);
328 return err
? -EFAULT
: 0;
331 #else /* ! CONFIG_ARM64_SVE */
333 /* Turn any non-optimised out attempts to use these into a link error: */
334 extern int preserve_sve_context(void __user
*ctx
);
335 extern int restore_sve_fpsimd_context(struct user_ctxs
*user
);
337 #endif /* ! CONFIG_ARM64_SVE */
340 static int parse_user_sigframe(struct user_ctxs
*user
,
341 struct rt_sigframe __user
*sf
)
343 struct sigcontext __user
*const sc
= &sf
->uc
.uc_mcontext
;
344 struct _aarch64_ctx __user
*head
;
345 char __user
*base
= (char __user
*)&sc
->__reserved
;
347 size_t limit
= sizeof(sc
->__reserved
);
348 bool have_extra_context
= false;
349 char const __user
*const sfp
= (char const __user
*)sf
;
354 if (!IS_ALIGNED((unsigned long)base
, 16))
360 char const __user
*userp
;
361 struct extra_context
const __user
*extra
;
364 struct _aarch64_ctx
const __user
*end
;
365 u32 end_magic
, end_size
;
367 if (limit
- offset
< sizeof(*head
))
370 if (!IS_ALIGNED(offset
, 16))
373 head
= (struct _aarch64_ctx __user
*)(base
+ offset
);
374 __get_user_error(magic
, &head
->magic
, err
);
375 __get_user_error(size
, &head
->size
, err
);
379 if (limit
- offset
< size
)
393 if (size
< sizeof(*user
->fpsimd
))
396 user
->fpsimd
= (struct fpsimd_context __user
*)head
;
404 if (!system_supports_sve())
410 if (size
< sizeof(*user
->sve
))
413 user
->sve
= (struct sve_context __user
*)head
;
417 if (have_extra_context
)
420 if (size
< sizeof(*extra
))
423 userp
= (char const __user
*)head
;
425 extra
= (struct extra_context
const __user
*)userp
;
428 __get_user_error(extra_datap
, &extra
->datap
, err
);
429 __get_user_error(extra_size
, &extra
->size
, err
);
433 /* Check for the dummy terminator in __reserved[]: */
435 if (limit
- offset
- size
< TERMINATOR_SIZE
)
438 end
= (struct _aarch64_ctx
const __user
*)userp
;
439 userp
+= TERMINATOR_SIZE
;
441 __get_user_error(end_magic
, &end
->magic
, err
);
442 __get_user_error(end_size
, &end
->size
, err
);
446 if (end_magic
|| end_size
)
449 /* Prevent looping/repeated parsing of extra_context */
450 have_extra_context
= true;
452 base
= (__force
void __user
*)extra_datap
;
453 if (!IS_ALIGNED((unsigned long)base
, 16))
456 if (!IS_ALIGNED(extra_size
, 16))
462 /* Reject "unreasonably large" frames: */
463 if (extra_size
> sfp
+ SIGFRAME_MAXSZ
- userp
)
467 * Ignore trailing terminator in __reserved[]
468 * and start parsing extra data:
473 if (!access_ok(VERIFY_READ
, base
, limit
))
482 if (size
< sizeof(*head
))
485 if (limit
- offset
< size
)
498 static int restore_sigframe(struct pt_regs
*regs
,
499 struct rt_sigframe __user
*sf
)
503 struct user_ctxs user
;
505 err
= __copy_from_user(&set
, &sf
->uc
.uc_sigmask
, sizeof(set
));
507 set_current_blocked(&set
);
509 for (i
= 0; i
< 31; i
++)
510 __get_user_error(regs
->regs
[i
], &sf
->uc
.uc_mcontext
.regs
[i
],
512 __get_user_error(regs
->sp
, &sf
->uc
.uc_mcontext
.sp
, err
);
513 __get_user_error(regs
->pc
, &sf
->uc
.uc_mcontext
.pc
, err
);
514 __get_user_error(regs
->pstate
, &sf
->uc
.uc_mcontext
.pstate
, err
);
517 * Avoid sys_rt_sigreturn() restarting.
519 forget_syscall(regs
);
521 err
|= !valid_user_regs(®s
->user_regs
, current
);
523 err
= parse_user_sigframe(&user
, sf
);
530 if (!system_supports_sve())
533 err
= restore_sve_fpsimd_context(&user
);
535 err
= restore_fpsimd_context(user
.fpsimd
);
542 asmlinkage
long sys_rt_sigreturn(struct pt_regs
*regs
)
544 struct rt_sigframe __user
*frame
;
546 /* Always make any pending restarted system calls return -EINTR */
547 current
->restart_block
.fn
= do_no_restart_syscall
;
550 * Since we stacked the signal on a 128-bit boundary, then 'sp' should
551 * be word aligned here.
556 frame
= (struct rt_sigframe __user
*)regs
->sp
;
558 if (!access_ok(VERIFY_READ
, frame
, sizeof (*frame
)))
561 if (restore_sigframe(regs
, frame
))
564 if (restore_altstack(&frame
->uc
.uc_stack
))
567 return regs
->regs
[0];
570 arm64_notify_segfault(regs
->sp
);
575 * Determine the layout of optional records in the signal frame
577 * add_all: if true, lays out the biggest possible signal frame for
578 * this task; otherwise, generates a layout for the current state
581 static int setup_sigframe_layout(struct rt_sigframe_user_layout
*user
,
586 err
= sigframe_alloc(user
, &user
->fpsimd_offset
,
587 sizeof(struct fpsimd_context
));
591 /* fault information, if valid */
592 if (add_all
|| current
->thread
.fault_code
) {
593 err
= sigframe_alloc(user
, &user
->esr_offset
,
594 sizeof(struct esr_context
));
599 if (system_supports_sve()) {
602 if (add_all
|| test_thread_flag(TIF_SVE
)) {
606 vl
= current
->thread
.sve_vl
;
608 vq
= sve_vq_from_vl(vl
);
611 err
= sigframe_alloc(user
, &user
->sve_offset
,
612 SVE_SIG_CONTEXT_SIZE(vq
));
617 return sigframe_alloc_end(user
);
620 static int setup_sigframe(struct rt_sigframe_user_layout
*user
,
621 struct pt_regs
*regs
, sigset_t
*set
)
624 struct rt_sigframe __user
*sf
= user
->sigframe
;
626 /* set up the stack frame for unwinding */
627 __put_user_error(regs
->regs
[29], &user
->next_frame
->fp
, err
);
628 __put_user_error(regs
->regs
[30], &user
->next_frame
->lr
, err
);
630 for (i
= 0; i
< 31; i
++)
631 __put_user_error(regs
->regs
[i
], &sf
->uc
.uc_mcontext
.regs
[i
],
633 __put_user_error(regs
->sp
, &sf
->uc
.uc_mcontext
.sp
, err
);
634 __put_user_error(regs
->pc
, &sf
->uc
.uc_mcontext
.pc
, err
);
635 __put_user_error(regs
->pstate
, &sf
->uc
.uc_mcontext
.pstate
, err
);
637 __put_user_error(current
->thread
.fault_address
, &sf
->uc
.uc_mcontext
.fault_address
, err
);
639 err
|= __copy_to_user(&sf
->uc
.uc_sigmask
, set
, sizeof(*set
));
642 struct fpsimd_context __user
*fpsimd_ctx
=
643 apply_user_offset(user
, user
->fpsimd_offset
);
644 err
|= preserve_fpsimd_context(fpsimd_ctx
);
647 /* fault information, if valid */
648 if (err
== 0 && user
->esr_offset
) {
649 struct esr_context __user
*esr_ctx
=
650 apply_user_offset(user
, user
->esr_offset
);
652 __put_user_error(ESR_MAGIC
, &esr_ctx
->head
.magic
, err
);
653 __put_user_error(sizeof(*esr_ctx
), &esr_ctx
->head
.size
, err
);
654 __put_user_error(current
->thread
.fault_code
, &esr_ctx
->esr
, err
);
657 /* Scalable Vector Extension state, if present */
658 if (system_supports_sve() && err
== 0 && user
->sve_offset
) {
659 struct sve_context __user
*sve_ctx
=
660 apply_user_offset(user
, user
->sve_offset
);
661 err
|= preserve_sve_context(sve_ctx
);
664 if (err
== 0 && user
->extra_offset
) {
665 char __user
*sfp
= (char __user
*)user
->sigframe
;
667 apply_user_offset(user
, user
->extra_offset
);
669 struct extra_context __user
*extra
;
670 struct _aarch64_ctx __user
*end
;
674 extra
= (struct extra_context __user
*)userp
;
675 userp
+= EXTRA_CONTEXT_SIZE
;
677 end
= (struct _aarch64_ctx __user
*)userp
;
678 userp
+= TERMINATOR_SIZE
;
681 * extra_datap is just written to the signal frame.
682 * The value gets cast back to a void __user *
685 extra_datap
= (__force u64
)userp
;
686 extra_size
= sfp
+ round_up(user
->size
, 16) - userp
;
688 __put_user_error(EXTRA_MAGIC
, &extra
->head
.magic
, err
);
689 __put_user_error(EXTRA_CONTEXT_SIZE
, &extra
->head
.size
, err
);
690 __put_user_error(extra_datap
, &extra
->datap
, err
);
691 __put_user_error(extra_size
, &extra
->size
, err
);
693 /* Add the terminator */
694 __put_user_error(0, &end
->magic
, err
);
695 __put_user_error(0, &end
->size
, err
);
698 /* set the "end" magic */
700 struct _aarch64_ctx __user
*end
=
701 apply_user_offset(user
, user
->end_offset
);
703 __put_user_error(0, &end
->magic
, err
);
704 __put_user_error(0, &end
->size
, err
);
710 static int get_sigframe(struct rt_sigframe_user_layout
*user
,
711 struct ksignal
*ksig
, struct pt_regs
*regs
)
713 unsigned long sp
, sp_top
;
716 init_user_layout(user
);
717 err
= setup_sigframe_layout(user
, false);
721 sp
= sp_top
= sigsp(regs
->sp
, ksig
);
723 sp
= round_down(sp
- sizeof(struct frame_record
), 16);
724 user
->next_frame
= (struct frame_record __user
*)sp
;
726 sp
= round_down(sp
, 16) - sigframe_size(user
);
727 user
->sigframe
= (struct rt_sigframe __user
*)sp
;
730 * Check that we can actually write to the signal frame.
732 if (!access_ok(VERIFY_WRITE
, user
->sigframe
, sp_top
- sp
))
738 static void setup_return(struct pt_regs
*regs
, struct k_sigaction
*ka
,
739 struct rt_sigframe_user_layout
*user
, int usig
)
741 __sigrestore_t sigtramp
;
743 regs
->regs
[0] = usig
;
744 regs
->sp
= (unsigned long)user
->sigframe
;
745 regs
->regs
[29] = (unsigned long)&user
->next_frame
->fp
;
746 regs
->pc
= (unsigned long)ka
->sa
.sa_handler
;
748 if (ka
->sa
.sa_flags
& SA_RESTORER
)
749 sigtramp
= ka
->sa
.sa_restorer
;
751 sigtramp
= VDSO_SYMBOL(current
->mm
->context
.vdso
, sigtramp
);
753 regs
->regs
[30] = (unsigned long)sigtramp
;
756 static int setup_rt_frame(int usig
, struct ksignal
*ksig
, sigset_t
*set
,
757 struct pt_regs
*regs
)
759 struct rt_sigframe_user_layout user
;
760 struct rt_sigframe __user
*frame
;
763 fpsimd_signal_preserve_current_state();
765 if (get_sigframe(&user
, ksig
, regs
))
768 frame
= user
.sigframe
;
770 __put_user_error(0, &frame
->uc
.uc_flags
, err
);
771 __put_user_error(NULL
, &frame
->uc
.uc_link
, err
);
773 err
|= __save_altstack(&frame
->uc
.uc_stack
, regs
->sp
);
774 err
|= setup_sigframe(&user
, regs
, set
);
776 setup_return(regs
, &ksig
->ka
, &user
, usig
);
777 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
) {
778 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
779 regs
->regs
[1] = (unsigned long)&frame
->info
;
780 regs
->regs
[2] = (unsigned long)&frame
->uc
;
787 static void setup_restart_syscall(struct pt_regs
*regs
)
789 if (is_compat_task())
790 compat_setup_restart_syscall(regs
);
792 regs
->regs
[8] = __NR_restart_syscall
;
796 * OK, we're invoking a handler
798 static void handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
800 struct task_struct
*tsk
= current
;
801 sigset_t
*oldset
= sigmask_to_save();
802 int usig
= ksig
->sig
;
806 * Set up the stack frame
808 if (is_compat_task()) {
809 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
810 ret
= compat_setup_rt_frame(usig
, ksig
, oldset
, regs
);
812 ret
= compat_setup_frame(usig
, ksig
, oldset
, regs
);
814 ret
= setup_rt_frame(usig
, ksig
, oldset
, regs
);
818 * Check that the resulting registers are actually sane.
820 ret
|= !valid_user_regs(®s
->user_regs
, current
);
823 * Fast forward the stepping logic so we step into the signal
827 user_fastforward_single_step(tsk
);
829 signal_setup_done(ret
, ksig
, 0);
833 * Note that 'init' is a special process: it doesn't get signals it doesn't
834 * want to handle. Thus you cannot kill init even with a SIGKILL even by
837 * Note that we go through the signals twice: once to check the signals that
838 * the kernel can handle, and then we build all the user-level signal handling
839 * stack-frames in one go after that.
841 static void do_signal(struct pt_regs
*regs
)
843 unsigned long continue_addr
= 0, restart_addr
= 0;
846 bool syscall
= in_syscall(regs
);
849 * If we were from a system call, check for system call restarting...
852 continue_addr
= regs
->pc
;
853 restart_addr
= continue_addr
- (compat_thumb_mode(regs
) ? 2 : 4);
854 retval
= regs
->regs
[0];
857 * Avoid additional syscall restarting via ret_to_user.
859 forget_syscall(regs
);
862 * Prepare for system call restart. We do this here so that a
863 * debugger will see the already changed PC.
866 case -ERESTARTNOHAND
:
868 case -ERESTARTNOINTR
:
869 case -ERESTART_RESTARTBLOCK
:
870 regs
->regs
[0] = regs
->orig_x0
;
871 regs
->pc
= restart_addr
;
877 * Get the signal to deliver. When running under ptrace, at this point
878 * the debugger may change all of our registers.
880 if (get_signal(&ksig
)) {
882 * Depending on the signal settings, we may need to revert the
883 * decision to restart the system call, but skip this if a
884 * debugger has chosen to restart at a different PC.
886 if (regs
->pc
== restart_addr
&&
887 (retval
== -ERESTARTNOHAND
||
888 retval
== -ERESTART_RESTARTBLOCK
||
889 (retval
== -ERESTARTSYS
&&
890 !(ksig
.ka
.sa
.sa_flags
& SA_RESTART
)))) {
891 regs
->regs
[0] = -EINTR
;
892 regs
->pc
= continue_addr
;
895 handle_signal(&ksig
, regs
);
900 * Handle restarting a different system call. As above, if a debugger
901 * has chosen to restart at a different PC, ignore the restart.
903 if (syscall
&& regs
->pc
== restart_addr
) {
904 if (retval
== -ERESTART_RESTARTBLOCK
)
905 setup_restart_syscall(regs
);
906 user_rewind_single_step(current
);
909 restore_saved_sigmask();
912 asmlinkage
void do_notify_resume(struct pt_regs
*regs
,
913 unsigned int thread_flags
)
916 * The assembly code enters us with IRQs off, but it hasn't
917 * informed the tracing code of that for efficiency reasons.
918 * Update the trace code with the current status.
920 trace_hardirqs_off();
923 /* Check valid user FS if needed */
924 addr_limit_user_check();
926 if (thread_flags
& _TIF_NEED_RESCHED
) {
927 /* Unmask Debug and SError for the next task */
928 local_daif_restore(DAIF_PROCCTX_NOIRQ
);
932 local_daif_restore(DAIF_PROCCTX
);
934 if (thread_flags
& _TIF_UPROBE
)
935 uprobe_notify_resume(regs
);
937 if (thread_flags
& _TIF_SIGPENDING
)
940 if (thread_flags
& _TIF_NOTIFY_RESUME
) {
941 clear_thread_flag(TIF_NOTIFY_RESUME
);
942 tracehook_notify_resume(regs
);
945 if (thread_flags
& _TIF_FOREIGN_FPSTATE
)
946 fpsimd_restore_current_state();
950 thread_flags
= READ_ONCE(current_thread_info()->flags
);
951 } while (thread_flags
& _TIF_WORK_MASK
);
954 unsigned long __ro_after_init signal_minsigstksz
;
957 * Determine the stack space required for guaranteed signal devliery.
958 * This function is used to populate AT_MINSIGSTKSZ at process startup.
959 * cpufeatures setup is assumed to be complete.
961 void __init
minsigstksz_setup(void)
963 struct rt_sigframe_user_layout user
;
965 init_user_layout(&user
);
968 * If this fails, SIGFRAME_MAXSZ needs to be enlarged. It won't
969 * be big enough, but it's our best guess:
971 if (WARN_ON(setup_sigframe_layout(&user
, true)))
974 signal_minsigstksz
= sigframe_size(&user
) +
975 round_up(sizeof(struct frame_record
), 16) +
976 16; /* max alignment padding */