1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/m32r/kernel/signal.c
5 * Copyright (c) 2003 Hitoshi Yamamoto
7 * Taken from i386 version.
8 * Copyright (C) 1991, 1992 Linus Torvalds
10 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
11 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
14 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/kernel.h>
18 #include <linux/signal.h>
19 #include <linux/errno.h>
20 #include <linux/wait.h>
21 #include <linux/unistd.h>
22 #include <linux/stddef.h>
23 #include <linux/personality.h>
24 #include <linux/tracehook.h>
25 #include <asm/cacheflush.h>
26 #include <asm/ucontext.h>
27 #include <linux/uaccess.h>
32 * Do a signal return; undo the signal stack.
38 struct siginfo __user
*pinfo
;
42 // struct _fpstate fpstate;
46 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*sc
,
51 /* Always make any pending restarted system calls return -EINTR */
52 current
->restart_block
.fn
= do_no_restart_syscall
;
54 #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
59 /* COPY(r0); Skip r0 */
71 COPY(acc1h
); /* ISA_DSP_LEVEL2 only */
72 COPY(acc1l
); /* ISA_DSP_LEVEL2 only */
83 regs
->syscall_nr
= -1; /* disable syscall checks */
84 err
|= __get_user(*r0_p
, &sc
->sc_r0
);
90 sys_rt_sigreturn(unsigned long r0
, unsigned long r1
,
91 unsigned long r2
, unsigned long r3
, unsigned long r4
,
92 unsigned long r5
, unsigned long r6
, struct pt_regs
*regs
)
94 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*)regs
->spu
;
98 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
100 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
103 set_current_blocked(&set
);
105 if (restore_sigcontext(regs
, &frame
->uc
.uc_mcontext
, &result
))
108 if (restore_altstack(&frame
->uc
.uc_stack
))
114 force_sig(SIGSEGV
, current
);
119 * Set up a signal frame.
123 setup_sigcontext(struct sigcontext __user
*sc
, struct pt_regs
*regs
,
128 #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
145 COPY(acc1h
); /* ISA_DSP_LEVEL2 only */
146 COPY(acc1l
); /* ISA_DSP_LEVEL2 only */
157 err
|= __put_user(mask
, &sc
->oldmask
);
163 * Determine which stack to use..
165 static inline void __user
*
166 get_sigframe(struct ksignal
*ksig
, unsigned long sp
, size_t frame_size
)
168 return (void __user
*)((sigsp(sp
, ksig
) - frame_size
) & -8ul);
171 static int setup_rt_frame(struct ksignal
*ksig
, sigset_t
*set
,
172 struct pt_regs
*regs
)
174 struct rt_sigframe __user
*frame
;
178 frame
= get_sigframe(ksig
, regs
->spu
, sizeof(*frame
));
180 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
183 err
|= __put_user(sig
, &frame
->sig
);
187 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
188 err
|= __put_user(&frame
->uc
, &frame
->puc
);
189 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
193 /* Create the ucontext. */
194 err
|= __put_user(0, &frame
->uc
.uc_flags
);
195 err
|= __put_user(0, &frame
->uc
.uc_link
);
196 err
|= __save_altstack(&frame
->uc
.uc_stack
, regs
->spu
);
197 err
|= setup_sigcontext(&frame
->uc
.uc_mcontext
, regs
, set
->sig
[0]);
198 err
|= __copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
202 /* Set up to return from userspace. */
203 regs
->lr
= (unsigned long)ksig
->ka
.sa
.sa_restorer
;
205 /* Set up registers for signal handler */
206 regs
->spu
= (unsigned long)frame
;
207 regs
->r0
= sig
; /* Arg for signal handler */
208 regs
->r1
= (unsigned long)&frame
->info
;
209 regs
->r2
= (unsigned long)&frame
->uc
;
210 regs
->bpc
= (unsigned long)ksig
->ka
.sa
.sa_handler
;
213 printk("SIG deliver (%s:%d): sp=%p pc=%p\n",
214 current
->comm
, current
->pid
, frame
, regs
->pc
);
220 static int prev_insn(struct pt_regs
*regs
)
223 if (get_user(inst
, (u16 __user
*)(regs
->bpc
- 2)))
225 if ((inst
& 0xfff0) == 0x10f0) /* trap ? */
229 regs
->syscall_nr
= -1;
234 * OK, we're invoking a handler
238 handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
242 /* Are we from a system call? */
243 if (regs
->syscall_nr
>= 0) {
244 /* If so, check system call restarting.. */
246 case -ERESTART_RESTARTBLOCK
:
247 case -ERESTARTNOHAND
:
252 if (!(ksig
->ka
.sa
.sa_flags
& SA_RESTART
)) {
257 case -ERESTARTNOINTR
:
258 regs
->r0
= regs
->orig_r0
;
259 if (prev_insn(regs
) < 0)
264 /* Set up the stack frame */
265 ret
= setup_rt_frame(ksig
, sigmask_to_save(), regs
);
267 signal_setup_done(ret
, ksig
, 0);
271 * Note that 'init' is a special process: it doesn't get signals it doesn't
272 * want to handle. Thus you cannot kill init even with a SIGKILL even by
275 static void do_signal(struct pt_regs
*regs
)
280 * We want the common case to go fast, which
281 * is why we may in certain cases get here from
282 * kernel mode. Just return without doing anything
285 if (!user_mode(regs
))
288 if (get_signal(&ksig
)) {
289 /* Re-enable any watchpoints before delivering the
290 * signal to user space. The processor register will
291 * have been cleared if the watchpoint triggered
295 /* Whee! Actually deliver the signal. */
296 handle_signal(&ksig
, regs
);
301 /* Did we come from a system call? */
302 if (regs
->syscall_nr
>= 0) {
303 /* Restart the system call - no handlers present */
304 if (regs
->r0
== -ERESTARTNOHAND
||
305 regs
->r0
== -ERESTARTSYS
||
306 regs
->r0
== -ERESTARTNOINTR
) {
307 regs
->r0
= regs
->orig_r0
;
309 } else if (regs
->r0
== -ERESTART_RESTARTBLOCK
){
310 regs
->r0
= regs
->orig_r0
;
311 regs
->r7
= __NR_restart_syscall
;
315 restore_saved_sigmask();
319 * notification of userspace execution resumption
320 * - triggered by current->work.notify_resume
322 void do_notify_resume(struct pt_regs
*regs
, __u32 thread_info_flags
)
324 /* Pending single-step? */
325 if (thread_info_flags
& _TIF_SINGLESTEP
)
326 clear_thread_flag(TIF_SINGLESTEP
);
328 /* deal with pending signal delivery */
329 if (thread_info_flags
& _TIF_SIGPENDING
)
332 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
333 clear_thread_flag(TIF_NOTIFY_RESUME
);
334 tracehook_notify_resume(regs
);