1 /* signal.c: FRV specific bits of signal handling
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/signal.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/sched.h>
15 #include <linux/smp.h>
16 #include <linux/kernel.h>
17 #include <linux/signal.h>
18 #include <linux/errno.h>
19 #include <linux/wait.h>
20 #include <linux/ptrace.h>
21 #include <linux/unistd.h>
22 #include <linux/personality.h>
23 #include <linux/tracehook.h>
24 #include <asm/ucontext.h>
25 #include <asm/uaccess.h>
26 #include <asm/cacheflush.h>
30 struct fdpic_func_descriptor
{
36 * Do a signal return; undo the signal stack.
41 __sigrestore_t pretcode
;
44 unsigned long extramask
[_NSIG_WORDS
-1];
50 __sigrestore_t pretcode
;
52 struct siginfo __user
*pinfo
;
59 static int restore_sigcontext(struct sigcontext __user
*sc
, int *_gr8
)
61 struct user_context
*user
= current
->thread
.user
;
62 unsigned long tbr
, psr
;
64 /* Always make any pending restarted system calls return -EINTR */
65 current
->restart_block
.fn
= do_no_restart_syscall
;
69 if (copy_from_user(user
, &sc
->sc_context
, sizeof(sc
->sc_context
)))
74 restore_user_regs(user
);
76 user
->i
.syscallno
= -1; /* disable syscall checks */
78 *_gr8
= user
->i
.gr
[8];
85 asmlinkage
int sys_sigreturn(void)
87 struct sigframe __user
*frame
= (struct sigframe __user
*) __frame
->sp
;
91 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
93 if (__get_user(set
.sig
[0], &frame
->sc
.sc_oldmask
))
96 if (_NSIG_WORDS
> 1 &&
97 __copy_from_user(&set
.sig
[1], &frame
->extramask
, sizeof(frame
->extramask
)))
100 set_current_blocked(&set
);
102 if (restore_sigcontext(&frame
->sc
, &gr8
))
107 force_sig(SIGSEGV
, current
);
111 asmlinkage
int sys_rt_sigreturn(void)
113 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*) __frame
->sp
;
117 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
119 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
122 set_current_blocked(&set
);
124 if (restore_sigcontext(&frame
->uc
.uc_mcontext
, &gr8
))
127 if (restore_altstack(&frame
->uc
.uc_stack
))
133 force_sig(SIGSEGV
, current
);
138 * Set up a signal frame
140 static int setup_sigcontext(struct sigcontext __user
*sc
, unsigned long mask
)
142 save_user_regs(current
->thread
.user
);
144 if (copy_to_user(&sc
->sc_context
, current
->thread
.user
, sizeof(sc
->sc_context
)) != 0)
147 /* non-iBCS2 extensions.. */
148 if (__put_user(mask
, &sc
->sc_oldmask
) < 0)
157 /*****************************************************************************/
159 * Determine which stack to use..
161 static inline void __user
*get_sigframe(struct ksignal
*ksig
,
164 unsigned long sp
= sigsp(__frame
->sp
, ksig
);
166 return (void __user
*) ((sp
- frame_size
) & ~7UL);
168 } /* end get_sigframe() */
170 /*****************************************************************************/
174 static int setup_frame(struct ksignal
*ksig
, sigset_t
*set
)
176 struct sigframe __user
*frame
;
179 frame
= get_sigframe(ksig
, sizeof(*frame
));
181 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
184 if (__put_user(sig
, &frame
->sig
) < 0)
187 if (setup_sigcontext(&frame
->sc
, set
->sig
[0]))
190 if (_NSIG_WORDS
> 1) {
191 if (__copy_to_user(frame
->extramask
, &set
->sig
[1],
192 sizeof(frame
->extramask
)))
196 /* Set up to return from userspace. If provided, use a stub
197 * already in userspace. */
198 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
) {
199 if (__put_user(ksig
->ka
.sa
.sa_restorer
, &frame
->pretcode
) < 0)
203 /* Set up the following code on the stack:
204 * setlos #__NR_sigreturn,gr7
207 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
208 __put_user(0x8efc0000|__NR_sigreturn
, &frame
->retcode
[0]) ||
209 __put_user(0xc0700000, &frame
->retcode
[1]))
212 flush_icache_range((unsigned long) frame
->retcode
,
213 (unsigned long) (frame
->retcode
+ 2));
216 /* Set up registers for the signal handler */
217 if (current
->personality
& FDPIC_FUNCPTRS
) {
218 struct fdpic_func_descriptor __user
*funcptr
=
219 (struct fdpic_func_descriptor __user
*) ksig
->ka
.sa
.sa_handler
;
220 struct fdpic_func_descriptor desc
;
221 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
223 __frame
->pc
= desc
.text
;
224 __frame
->gr15
= desc
.GOT
;
226 __frame
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
230 __frame
->sp
= (unsigned long) frame
;
231 __frame
->lr
= (unsigned long) &frame
->retcode
;
235 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
236 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
241 } /* end setup_frame() */
243 /*****************************************************************************/
247 static int setup_rt_frame(struct ksignal
*ksig
, sigset_t
*set
)
249 struct rt_sigframe __user
*frame
;
252 frame
= get_sigframe(ksig
, sizeof(*frame
));
254 if (!access_ok(VERIFY_WRITE
, frame
, sizeof(*frame
)))
257 if (__put_user(sig
, &frame
->sig
) ||
258 __put_user(&frame
->info
, &frame
->pinfo
) ||
259 __put_user(&frame
->uc
, &frame
->puc
))
262 if (copy_siginfo_to_user(&frame
->info
, &ksig
->info
))
265 /* Create the ucontext. */
266 if (__put_user(0, &frame
->uc
.uc_flags
) ||
267 __put_user(NULL
, &frame
->uc
.uc_link
) ||
268 __save_altstack(&frame
->uc
.uc_stack
, __frame
->sp
))
271 if (setup_sigcontext(&frame
->uc
.uc_mcontext
, set
->sig
[0]))
274 if (__copy_to_user(&frame
->uc
.uc_sigmask
, set
, sizeof(*set
)))
277 /* Set up to return from userspace. If provided, use a stub
278 * already in userspace. */
279 if (ksig
->ka
.sa
.sa_flags
& SA_RESTORER
) {
280 if (__put_user(ksig
->ka
.sa
.sa_restorer
, &frame
->pretcode
))
284 /* Set up the following code on the stack:
285 * setlos #__NR_sigreturn,gr7
288 if (__put_user((__sigrestore_t
)frame
->retcode
, &frame
->pretcode
) ||
289 __put_user(0x8efc0000|__NR_rt_sigreturn
, &frame
->retcode
[0]) ||
290 __put_user(0xc0700000, &frame
->retcode
[1]))
293 flush_icache_range((unsigned long) frame
->retcode
,
294 (unsigned long) (frame
->retcode
+ 2));
297 /* Set up registers for signal handler */
298 if (current
->personality
& FDPIC_FUNCPTRS
) {
299 struct fdpic_func_descriptor __user
*funcptr
=
300 (struct fdpic_func_descriptor __user
*) ksig
->ka
.sa
.sa_handler
;
301 struct fdpic_func_descriptor desc
;
302 if (copy_from_user(&desc
, funcptr
, sizeof(desc
)))
304 __frame
->pc
= desc
.text
;
305 __frame
->gr15
= desc
.GOT
;
307 __frame
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
311 __frame
->sp
= (unsigned long) frame
;
312 __frame
->lr
= (unsigned long) &frame
->retcode
;
314 __frame
->gr9
= (unsigned long) &frame
->info
;
317 printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
318 sig
, current
->comm
, current
->pid
, frame
, __frame
->pc
,
323 } /* end setup_rt_frame() */
325 /*****************************************************************************/
327 * OK, we're invoking a handler
329 static void handle_signal(struct ksignal
*ksig
)
331 sigset_t
*oldset
= sigmask_to_save();
334 /* Are we from a system call? */
335 if (__frame
->syscallno
!= -1) {
336 /* If so, check system call restarting.. */
337 switch (__frame
->gr8
) {
338 case -ERESTART_RESTARTBLOCK
:
339 case -ERESTARTNOHAND
:
340 __frame
->gr8
= -EINTR
;
344 if (!(ksig
->ka
.sa
.sa_flags
& SA_RESTART
)) {
345 __frame
->gr8
= -EINTR
;
350 case -ERESTARTNOINTR
:
351 __frame
->gr8
= __frame
->orig_gr8
;
354 __frame
->syscallno
= -1;
357 /* Set up the stack frame */
358 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
359 ret
= setup_rt_frame(ksig
, oldset
);
361 ret
= setup_frame(ksig
, oldset
);
363 signal_setup_done(ret
, ksig
, test_thread_flag(TIF_SINGLESTEP
));
364 } /* end handle_signal() */
366 /*****************************************************************************/
368 * Note that 'init' is a special process: it doesn't get signals it doesn't
369 * want to handle. Thus you cannot kill init even with a SIGKILL even by
372 static void do_signal(void)
376 if (get_signal(&ksig
)) {
377 handle_signal(&ksig
);
381 /* Did we come from a system call? */
382 if (__frame
->syscallno
!= -1) {
383 /* Restart the system call - no handlers present */
384 switch (__frame
->gr8
) {
385 case -ERESTARTNOHAND
:
387 case -ERESTARTNOINTR
:
388 __frame
->gr8
= __frame
->orig_gr8
;
392 case -ERESTART_RESTARTBLOCK
:
393 __frame
->gr7
= __NR_restart_syscall
;
397 __frame
->syscallno
= -1;
400 /* if there's no signal to deliver, we just put the saved sigmask
402 restore_saved_sigmask();
403 } /* end do_signal() */
405 /*****************************************************************************/
407 * notification of userspace execution resumption
408 * - triggered by the TIF_WORK_MASK flags
410 asmlinkage
void do_notify_resume(__u32 thread_info_flags
)
412 /* pending single-step? */
413 if (thread_info_flags
& _TIF_SINGLESTEP
)
414 clear_thread_flag(TIF_SINGLESTEP
);
416 /* deal with pending signal delivery */
417 if (thread_info_flags
& _TIF_SIGPENDING
)
420 /* deal with notification on about to resume userspace execution */
421 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
422 clear_thread_flag(TIF_NOTIFY_RESUME
);
423 tracehook_notify_resume(__frame
);
426 } /* end do_notify_resume() */