1 // SPDX-License-Identifier: GPL-2.0-only
3 * Based on arch/arm/kernel/signal.c
5 * Copyright (C) 1995-2009 Russell King
6 * Copyright (C) 2012 ARM Ltd.
9 #include <linux/cache.h>
10 #include <linux/compat.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/personality.h>
15 #include <linux/freezer.h>
16 #include <linux/stddef.h>
17 #include <linux/uaccess.h>
18 #include <linux/sizes.h>
19 #include <linux/string.h>
20 #include <linux/tracehook.h>
21 #include <linux/ratelimit.h>
22 #include <linux/syscalls.h>
24 #include <asm/daifflags.h>
25 #include <asm/debug-monitors.h>
27 #include <asm/cacheflush.h>
28 #include <asm/ucontext.h>
29 #include <asm/unistd.h>
30 #include <asm/fpsimd.h>
31 #include <asm/ptrace.h>
32 #include <asm/syscall.h>
33 #include <asm/signal32.h>
34 #include <asm/traps.h>
38 * Do a signal return; undo the signal stack. These are aligned to 128-bit.
50 struct rt_sigframe_user_layout {
51 struct rt_sigframe __user *sigframe;
52 struct frame_record __user *next_frame;
54 unsigned long size; /* size of allocated sigframe data */
55 unsigned long limit; /* largest allowed size */
57 unsigned long fpsimd_offset;
58 unsigned long esr_offset;
59 unsigned long sve_offset;
60 unsigned long extra_offset;
61 unsigned long end_offset;
64 #define BASE_SIGFRAME_SIZE round_up(sizeof(struct rt_sigframe), 16)
65 #define TERMINATOR_SIZE round_up(sizeof(struct _aarch64_ctx), 16)
66 #define EXTRA_CONTEXT_SIZE round_up(sizeof(struct extra_context), 16)
68 static void init_user_layout(struct rt_sigframe_user_layout *user)
70 const size_t reserved_size =
71 sizeof(user->sigframe->uc.uc_mcontext.__reserved);
73 memset(user, 0, sizeof(*user));
74 user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved);
76 user->limit = user->size + reserved_size;
78 user->limit -= TERMINATOR_SIZE;
79 user->limit -= EXTRA_CONTEXT_SIZE;
80 /* Reserve space for extension and terminator ^ */
83 static size_t sigframe_size(struct rt_sigframe_user_layout const *user)
85 return round_up(max(user->size, sizeof(struct rt_sigframe)), 16);
89 * Sanity limit on the approximate maximum size of signal frame we'll
90 * try to generate. Stack alignment padding and the frame record are
91 * not taken into account. This limit is not a guarantee and is
94 #define SIGFRAME_MAXSZ SZ_64K
96 static int __sigframe_alloc(struct rt_sigframe_user_layout *user,
97 unsigned long *offset, size_t size, bool extend)
99 size_t padded_size = round_up(size, 16);
101 if (padded_size > user->limit - user->size &&
102 !user->extra_offset &&
106 user->limit += EXTRA_CONTEXT_SIZE;
107 ret = __sigframe_alloc(user, &user->extra_offset,
108 sizeof(struct extra_context), false);
110 user->limit -= EXTRA_CONTEXT_SIZE;
114 /* Reserve space for the __reserved[] terminator */
115 user->size += TERMINATOR_SIZE;
118 * Allow expansion up to SIGFRAME_MAXSZ, ensuring space for
121 user->limit = SIGFRAME_MAXSZ - TERMINATOR_SIZE;
124 /* Still not enough space? Bad luck! */
125 if (padded_size > user->limit - user->size)
128 *offset = user->size;
129 user->size += padded_size;
135 * Allocate space for an optional record of <size> bytes in the user
136 * signal frame. The offset from the signal frame base address to the
137 * allocated block is assigned to *offset.
139 static int sigframe_alloc(struct rt_sigframe_user_layout *user,
140 unsigned long *offset, size_t size)
142 return __sigframe_alloc(user, offset, size, true);
145 /* Allocate the null terminator record and prevent further allocations */
146 static int sigframe_alloc_end(struct rt_sigframe_user_layout *user)
150 /* Un-reserve the space reserved for the terminator: */
151 user->limit += TERMINATOR_SIZE;
153 ret = sigframe_alloc(user, &user->end_offset,
154 sizeof(struct _aarch64_ctx));
158 /* Prevent further allocation: */
159 user->limit = user->size;
163 static void __user *apply_user_offset(
164 struct rt_sigframe_user_layout const *user, unsigned long offset)
166 char __user *base = (char __user *)user->sigframe;
168 return base + offset;
171 static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
173 struct user_fpsimd_state const *fpsimd =
174 ¤t->thread.uw.fpsimd_state;
177 /* copy the FP and status/control registers */
178 err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs));
179 __put_user_error(fpsimd->fpsr, &ctx->fpsr, err);
180 __put_user_error(fpsimd->fpcr, &ctx->fpcr, err);
182 /* copy the magic/size information */
183 __put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err);
184 __put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err);
186 return err ? -EFAULT : 0;
189 static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
191 struct user_fpsimd_state fpsimd;
195 /* check the magic/size information */
196 __get_user_error(magic, &ctx->head.magic, err);
197 __get_user_error(size, &ctx->head.size, err);
200 if (magic != FPSIMD_MAGIC || size != sizeof(struct fpsimd_context))
203 /* copy the FP and status/control registers */
204 err = __copy_from_user(fpsimd.vregs, ctx->vregs,
205 sizeof(fpsimd.vregs));
206 __get_user_error(fpsimd.fpsr, &ctx->fpsr, err);
207 __get_user_error(fpsimd.fpcr, &ctx->fpcr, err);
209 clear_thread_flag(TIF_SVE);
211 /* load the hardware registers from the fpsimd_state structure */
213 fpsimd_update_current_state(&fpsimd);
215 return err ? -EFAULT : 0;
220 struct fpsimd_context __user *fpsimd;
221 struct sve_context __user *sve;
224 #ifdef CONFIG_ARM64_SVE
226 static int preserve_sve_context(struct sve_context __user *ctx)
229 u16 reserved[ARRAY_SIZE(ctx->__reserved)];
230 unsigned int vl = current->thread.sve_vl;
233 if (test_thread_flag(TIF_SVE))
234 vq = sve_vq_from_vl(vl);
236 memset(reserved, 0, sizeof(reserved));
238 __put_user_error(SVE_MAGIC, &ctx->head.magic, err);
239 __put_user_error(round_up(SVE_SIG_CONTEXT_SIZE(vq), 16),
240 &ctx->head.size, err);
241 __put_user_error(vl, &ctx->vl, err);
242 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved));
243 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved));
247 * This assumes that the SVE state has already been saved to
248 * the task struct by calling the function
249 * fpsimd_signal_preserve_current_state().
251 err |= __copy_to_user((char __user *)ctx + SVE_SIG_REGS_OFFSET,
252 current->thread.sve_state,
253 SVE_SIG_REGS_SIZE(vq));
256 return err ? -EFAULT : 0;
259 static int restore_sve_fpsimd_context(struct user_ctxs *user)
263 struct user_fpsimd_state fpsimd;
264 struct sve_context sve;
266 if (__copy_from_user(&sve, user->sve, sizeof(sve)))
269 if (sve.vl != current->thread.sve_vl)
272 if (sve.head.size <= sizeof(*user->sve)) {
273 clear_thread_flag(TIF_SVE);
277 vq = sve_vq_from_vl(sve.vl);
279 if (sve.head.size < SVE_SIG_CONTEXT_SIZE(vq))
283 * Careful: we are about __copy_from_user() directly into
284 * thread.sve_state with preemption enabled, so protection is
285 * needed to prevent a racing context switch from writing stale
286 * registers back over the new data.
289 fpsimd_flush_task_state(current);
290 /* From now, fpsimd_thread_switch() won't touch thread.sve_state */
293 if (!current->thread.sve_state) {
294 clear_thread_flag(TIF_SVE);
298 err = __copy_from_user(current->thread.sve_state,
299 (char __user const *)user->sve +
301 SVE_SIG_REGS_SIZE(vq));
305 set_thread_flag(TIF_SVE);
308 /* copy the FP and status/control registers */
309 /* restore_sigframe() already checked that user->fpsimd != NULL. */
310 err = __copy_from_user(fpsimd.vregs, user->fpsimd->vregs,
311 sizeof(fpsimd.vregs));
312 __get_user_error(fpsimd.fpsr, &user->fpsimd->fpsr, err);
313 __get_user_error(fpsimd.fpcr, &user->fpsimd->fpcr, err);
315 /* load the hardware registers from the fpsimd_state structure */
317 fpsimd_update_current_state(&fpsimd);
319 return err ? -EFAULT : 0;
322 #else /* ! CONFIG_ARM64_SVE */
324 /* Turn any non-optimised out attempts to use these into a link error: */
325 extern int preserve_sve_context(void __user *ctx);
326 extern int restore_sve_fpsimd_context(struct user_ctxs *user);
328 #endif /* ! CONFIG_ARM64_SVE */
331 static int parse_user_sigframe(struct user_ctxs *user,
332 struct rt_sigframe __user *sf)
334 struct sigcontext __user *const sc = &sf->uc.uc_mcontext;
335 struct _aarch64_ctx __user *head;
336 char __user *base = (char __user *)&sc->__reserved;
338 size_t limit = sizeof(sc->__reserved);
339 bool have_extra_context = false;
340 char const __user *const sfp = (char const __user *)sf;
345 if (!IS_ALIGNED((unsigned long)base, 16))
351 char const __user *userp;
352 struct extra_context const __user *extra;
355 struct _aarch64_ctx const __user *end;
356 u32 end_magic, end_size;
358 if (limit - offset < sizeof(*head))
361 if (!IS_ALIGNED(offset, 16))
364 head = (struct _aarch64_ctx __user *)(base + offset);
365 __get_user_error(magic, &head->magic, err);
366 __get_user_error(size, &head->size, err);
370 if (limit - offset < size)
381 if (!system_supports_fpsimd())
386 if (size < sizeof(*user->fpsimd))
389 user->fpsimd = (struct fpsimd_context __user *)head;
397 if (!system_supports_sve())
403 if (size < sizeof(*user->sve))
406 user->sve = (struct sve_context __user *)head;
410 if (have_extra_context)
413 if (size < sizeof(*extra))
416 userp = (char const __user *)head;
418 extra = (struct extra_context const __user *)userp;
421 __get_user_error(extra_datap, &extra->datap, err);
422 __get_user_error(extra_size, &extra->size, err);
426 /* Check for the dummy terminator in __reserved[]: */
428 if (limit - offset - size < TERMINATOR_SIZE)
431 end = (struct _aarch64_ctx const __user *)userp;
432 userp += TERMINATOR_SIZE;
434 __get_user_error(end_magic, &end->magic, err);
435 __get_user_error(end_size, &end->size, err);
439 if (end_magic || end_size)
442 /* Prevent looping/repeated parsing of extra_context */
443 have_extra_context = true;
445 base = (__force void __user *)extra_datap;
446 if (!IS_ALIGNED((unsigned long)base, 16))
449 if (!IS_ALIGNED(extra_size, 16))
455 /* Reject "unreasonably large" frames: */
456 if (extra_size > sfp + SIGFRAME_MAXSZ - userp)
460 * Ignore trailing terminator in __reserved[]
461 * and start parsing extra data:
466 if (!access_ok(base, limit))
475 if (size < sizeof(*head))
478 if (limit - offset < size)
491 static int restore_sigframe(struct pt_regs *regs,
492 struct rt_sigframe __user *sf)
496 struct user_ctxs user;
498 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
500 set_current_blocked(&set);
502 for (i = 0; i < 31; i++)
503 __get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i],
505 __get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err);
506 __get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err);
507 __get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err);
510 * Avoid sys_rt_sigreturn() restarting.
512 forget_syscall(regs);
514 err |= !valid_user_regs(®s->user_regs, current);
516 err = parse_user_sigframe(&user, sf);
518 if (err == 0 && system_supports_fpsimd()) {
523 if (!system_supports_sve())
526 err = restore_sve_fpsimd_context(&user);
528 err = restore_fpsimd_context(user.fpsimd);
535 SYSCALL_DEFINE0(rt_sigreturn)
537 struct pt_regs *regs = current_pt_regs();
538 struct rt_sigframe __user *frame;
540 /* Always make any pending restarted system calls return -EINTR */
541 current->restart_block.fn = do_no_restart_syscall;
544 * Since we stacked the signal on a 128-bit boundary, then 'sp' should
545 * be word aligned here.
550 frame = (struct rt_sigframe __user *)regs->sp;
552 if (!access_ok(frame, sizeof (*frame)))
555 if (restore_sigframe(regs, frame))
558 if (restore_altstack(&frame->uc.uc_stack))
561 return regs->regs[0];
564 arm64_notify_segfault(regs->sp);
569 * Determine the layout of optional records in the signal frame
571 * add_all: if true, lays out the biggest possible signal frame for
572 * this task; otherwise, generates a layout for the current state
575 static int setup_sigframe_layout(struct rt_sigframe_user_layout *user,
580 if (system_supports_fpsimd()) {
581 err = sigframe_alloc(user, &user->fpsimd_offset,
582 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));
637 if (err == 0 && system_supports_fpsimd()) {
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;
745 * Signal delivery is a (wacky) indirect function call in
746 * userspace, so simulate the same setting of BTYPE as a BLR
747 * <register containing the signal handler entry point>.
748 * Signal delivery to a location in a PROT_BTI guarded page
749 * that is not a function entry point will now trigger a
750 * SIGILL in userspace.
752 * If the signal handler entry point is not in a PROT_BTI
753 * guarded page, this is harmless.
755 if (system_supports_bti()) {
756 regs->pstate &= ~PSR_BTYPE_MASK;
757 regs->pstate |= PSR_BTYPE_C;
760 /* TCO (Tag Check Override) always cleared for signal handlers */
761 regs->pstate &= ~PSR_TCO_BIT;
763 if (ka->sa.sa_flags & SA_RESTORER)
764 sigtramp = ka->sa.sa_restorer;
766 sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
768 regs->regs[30] = (unsigned long)sigtramp;
771 static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
772 struct pt_regs *regs)
774 struct rt_sigframe_user_layout user;
775 struct rt_sigframe __user *frame;
778 fpsimd_signal_preserve_current_state();
780 if (get_sigframe(&user, ksig, regs))
783 frame = user.sigframe;
785 __put_user_error(0, &frame->uc.uc_flags, err);
786 __put_user_error(NULL, &frame->uc.uc_link, err);
788 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
789 err |= setup_sigframe(&user, regs, set);
791 setup_return(regs, &ksig->ka, &user, usig);
792 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
793 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
794 regs->regs[1] = (unsigned long)&frame->info;
795 regs->regs[2] = (unsigned long)&frame->uc;
802 static void setup_restart_syscall(struct pt_regs *regs)
804 if (is_compat_task())
805 compat_setup_restart_syscall(regs);
807 regs->regs[8] = __NR_restart_syscall;
811 * OK, we're invoking a handler
813 static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
815 sigset_t *oldset = sigmask_to_save();
816 int usig = ksig->sig;
819 rseq_signal_deliver(ksig, regs);
822 * Set up the stack frame
824 if (is_compat_task()) {
825 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
826 ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
828 ret = compat_setup_frame(usig, ksig, oldset, regs);
830 ret = setup_rt_frame(usig, ksig, oldset, regs);
834 * Check that the resulting registers are actually sane.
836 ret |= !valid_user_regs(®s->user_regs, current);
838 /* Step into the signal handler if we are stepping */
839 signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
843 * Note that 'init' is a special process: it doesn't get signals it doesn't
844 * want to handle. Thus you cannot kill init even with a SIGKILL even by
847 * Note that we go through the signals twice: once to check the signals that
848 * the kernel can handle, and then we build all the user-level signal handling
849 * stack-frames in one go after that.
851 static void do_signal(struct pt_regs *regs)
853 unsigned long continue_addr = 0, restart_addr = 0;
856 bool syscall = in_syscall(regs);
859 * If we were from a system call, check for system call restarting...
862 continue_addr = regs->pc;
863 restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4);
864 retval = regs->regs[0];
867 * Avoid additional syscall restarting via ret_to_user.
869 forget_syscall(regs);
872 * Prepare for system call restart. We do this here so that a
873 * debugger will see the already changed PC.
876 case -ERESTARTNOHAND:
878 case -ERESTARTNOINTR:
879 case -ERESTART_RESTARTBLOCK:
880 regs->regs[0] = regs->orig_x0;
881 regs->pc = restart_addr;
887 * Get the signal to deliver. When running under ptrace, at this point
888 * the debugger may change all of our registers.
890 if (get_signal(&ksig)) {
892 * Depending on the signal settings, we may need to revert the
893 * decision to restart the system call, but skip this if a
894 * debugger has chosen to restart at a different PC.
896 if (regs->pc == restart_addr &&
897 (retval == -ERESTARTNOHAND ||
898 retval == -ERESTART_RESTARTBLOCK ||
899 (retval == -ERESTARTSYS &&
900 !(ksig.ka.sa.sa_flags & SA_RESTART)))) {
901 syscall_set_return_value(current, regs, -EINTR, 0);
902 regs->pc = continue_addr;
905 handle_signal(&ksig, regs);
910 * Handle restarting a different system call. As above, if a debugger
911 * has chosen to restart at a different PC, ignore the restart.
913 if (syscall && regs->pc == restart_addr) {
914 if (retval == -ERESTART_RESTARTBLOCK)
915 setup_restart_syscall(regs);
916 user_rewind_single_step(current);
919 restore_saved_sigmask();
922 void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
925 if (thread_flags & _TIF_NEED_RESCHED) {
926 /* Unmask Debug and SError for the next task */
927 local_daif_restore(DAIF_PROCCTX_NOIRQ);
931 local_daif_restore(DAIF_PROCCTX);
933 if (thread_flags & _TIF_UPROBE)
934 uprobe_notify_resume(regs);
936 if (thread_flags & _TIF_MTE_ASYNC_FAULT) {
937 clear_thread_flag(TIF_MTE_ASYNC_FAULT);
938 send_sig_fault(SIGSEGV, SEGV_MTEAERR,
939 (void __user *)NULL, current);
942 if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
945 if (thread_flags & _TIF_NOTIFY_RESUME)
946 tracehook_notify_resume(regs);
948 if (thread_flags & _TIF_FOREIGN_FPSTATE)
949 fpsimd_restore_current_state();
953 thread_flags = READ_ONCE(current_thread_info()->flags);
954 } while (thread_flags & _TIF_WORK_MASK);
957 unsigned long __ro_after_init signal_minsigstksz;
960 * Determine the stack space required for guaranteed signal devliery.
961 * This function is used to populate AT_MINSIGSTKSZ at process startup.
962 * cpufeatures setup is assumed to be complete.
964 void __init minsigstksz_setup(void)
966 struct rt_sigframe_user_layout user;
968 init_user_layout(&user);
971 * If this fails, SIGFRAME_MAXSZ needs to be enlarged. It won't
972 * be big enough, but it's our best guess:
974 if (WARN_ON(setup_sigframe_layout(&user, true)))
977 signal_minsigstksz = sigframe_size(&user) +
978 round_up(sizeof(struct frame_record), 16) +
979 16; /* max alignment padding */
983 * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as
984 * changes likely come with new fields that should be added below.
986 static_assert(NSIGILL == 11);
987 static_assert(NSIGFPE == 15);
988 static_assert(NSIGSEGV == 9);
989 static_assert(NSIGBUS == 5);
990 static_assert(NSIGTRAP == 6);
991 static_assert(NSIGCHLD == 6);
992 static_assert(NSIGSYS == 2);
993 static_assert(sizeof(siginfo_t) == 128);
994 static_assert(__alignof__(siginfo_t) == 8);
995 static_assert(offsetof(siginfo_t, si_signo) == 0x00);
996 static_assert(offsetof(siginfo_t, si_errno) == 0x04);
997 static_assert(offsetof(siginfo_t, si_code) == 0x08);
998 static_assert(offsetof(siginfo_t, si_pid) == 0x10);
999 static_assert(offsetof(siginfo_t, si_uid) == 0x14);
1000 static_assert(offsetof(siginfo_t, si_tid) == 0x10);
1001 static_assert(offsetof(siginfo_t, si_overrun) == 0x14);
1002 static_assert(offsetof(siginfo_t, si_status) == 0x18);
1003 static_assert(offsetof(siginfo_t, si_utime) == 0x20);
1004 static_assert(offsetof(siginfo_t, si_stime) == 0x28);
1005 static_assert(offsetof(siginfo_t, si_value) == 0x18);
1006 static_assert(offsetof(siginfo_t, si_int) == 0x18);
1007 static_assert(offsetof(siginfo_t, si_ptr) == 0x18);
1008 static_assert(offsetof(siginfo_t, si_addr) == 0x10);
1009 static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);
1010 static_assert(offsetof(siginfo_t, si_lower) == 0x20);
1011 static_assert(offsetof(siginfo_t, si_upper) == 0x28);
1012 static_assert(offsetof(siginfo_t, si_pkey) == 0x20);
1013 static_assert(offsetof(siginfo_t, si_perf_data) == 0x18);
1014 static_assert(offsetof(siginfo_t, si_perf_type) == 0x20);
1015 static_assert(offsetof(siginfo_t, si_perf_flags) == 0x24);
1016 static_assert(offsetof(siginfo_t, si_band) == 0x10);
1017 static_assert(offsetof(siginfo_t, si_fd) == 0x18);
1018 static_assert(offsetof(siginfo_t, si_call_addr) == 0x10);
1019 static_assert(offsetof(siginfo_t, si_syscall) == 0x18);
1020 static_assert(offsetof(siginfo_t, si_arch) == 0x1c);