1 /* $Id: signal.c,v 1.110 2002/02/08 03:57:14 davem Exp $
2 * linux/arch/sparc/kernel/signal.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/signal.h>
13 #include <linux/errno.h>
14 #include <linux/wait.h>
15 #include <linux/ptrace.h>
16 #include <linux/unistd.h>
18 #include <linux/tty.h>
19 #include <linux/smp.h>
20 #include <linux/smp_lock.h>
21 #include <linux/binfmts.h> /* do_coredum */
22 #include <linux/bitops.h>
24 #include <asm/uaccess.h>
25 #include <asm/ptrace.h>
27 #include <asm/pgalloc.h>
28 #include <asm/pgtable.h>
29 #include <asm/cacheflush.h> /* flush_sig_insns */
31 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33 extern void fpsave(unsigned long *fpregs
, unsigned long *fsr
,
34 void *fpqueue
, unsigned long *fpqdepth
);
35 extern void fpload(unsigned long *fpregs
, unsigned long *fsr
);
37 /* Signal frames: the original one (compatible with SunOS):
39 * Set up a signal frame... Make the stack look the way SunOS
40 * expects it to look which is basically:
42 * ---------------------------------- <-- %sp at signal time
45 * Ptr to sigcontext area above
47 * The signal number itself
49 * ---------------------------------- <-- New %sp
51 struct signal_sframe
{
52 struct reg_window sig_window
;
55 struct sigcontext __user
*sig_scptr
;
57 struct sigcontext sig_context
;
58 unsigned int extramask
[_NSIG_WORDS
- 1];
62 * And the new one, intended to be used for Linux applications only
63 * (we have enough in there to work with clone).
64 * All the interesting bits are in the info field.
67 struct new_signal_frame
{
68 struct sparc_stackf ss
;
70 __siginfo_fpu_t __user
*fpu_save
;
71 unsigned long insns
[2] __attribute__ ((aligned (8)));
72 unsigned int extramask
[_NSIG_WORDS
- 1];
73 unsigned int extra_size
; /* Should be 0 */
74 __siginfo_fpu_t fpu_state
;
77 struct rt_signal_frame
{
78 struct sparc_stackf ss
;
82 __siginfo_fpu_t __user
*fpu_save
;
83 unsigned int insns
[2];
85 unsigned int extra_size
; /* Should be 0 */
86 __siginfo_fpu_t fpu_state
;
90 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7)))
91 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7)))
92 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))
94 static int _sigpause_common(old_sigset_t set
)
97 spin_lock_irq(¤t
->sighand
->siglock
);
98 current
->saved_sigmask
= current
->blocked
;
99 siginitset(¤t
->blocked
, set
);
101 spin_unlock_irq(¤t
->sighand
->siglock
);
103 current
->state
= TASK_INTERRUPTIBLE
;
105 set_thread_flag(TIF_RESTORE_SIGMASK
);
107 return -ERESTARTNOHAND
;
110 asmlinkage
int sys_sigpause(unsigned int set
)
112 return _sigpause_common(set
);
115 asmlinkage
int sys_sigsuspend(old_sigset_t set
)
117 return _sigpause_common(set
);
121 restore_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
125 if (test_tsk_thread_flag(current
, TIF_USEDFPU
))
126 regs
->psr
&= ~PSR_EF
;
128 if (current
== last_task_used_math
) {
129 last_task_used_math
= NULL
;
130 regs
->psr
&= ~PSR_EF
;
134 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
136 if (!access_ok(VERIFY_READ
, fpu
, sizeof(*fpu
)))
139 err
= __copy_from_user(¤t
->thread
.float_regs
[0], &fpu
->si_float_regs
[0],
140 (sizeof(unsigned long) * 32));
141 err
|= __get_user(current
->thread
.fsr
, &fpu
->si_fsr
);
142 err
|= __get_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
143 if (current
->thread
.fpqdepth
!= 0)
144 err
|= __copy_from_user(¤t
->thread
.fpqueue
[0],
146 ((sizeof(unsigned long) +
147 (sizeof(unsigned long *)))*16));
151 static inline void do_new_sigreturn (struct pt_regs
*regs
)
153 struct new_signal_frame __user
*sf
;
154 unsigned long up_psr
, pc
, npc
;
156 __siginfo_fpu_t __user
*fpu_save
;
159 sf
= (struct new_signal_frame __user
*) regs
->u_regs
[UREG_FP
];
161 /* 1. Make sure we are not getting garbage from the user */
162 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)))
165 if (((unsigned long) sf
) & 3)
168 err
= __get_user(pc
, &sf
->info
.si_regs
.pc
);
169 err
|= __get_user(npc
, &sf
->info
.si_regs
.npc
);
174 /* 2. Restore the state */
176 err
|= __copy_from_user(regs
, &sf
->info
.si_regs
, sizeof(struct pt_regs
));
178 /* User can only change condition codes and FPU enabling in %psr. */
179 regs
->psr
= (up_psr
& ~(PSR_ICC
| PSR_EF
))
180 | (regs
->psr
& (PSR_ICC
| PSR_EF
));
182 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
185 err
|= restore_fpu_state(regs
, fpu_save
);
187 /* This is pretty much atomic, no amount locking would prevent
188 * the races which exist anyways.
190 err
|= __get_user(set
.sig
[0], &sf
->info
.si_mask
);
191 err
|= __copy_from_user(&set
.sig
[1], &sf
->extramask
,
192 (_NSIG_WORDS
-1) * sizeof(unsigned int));
197 sigdelsetmask(&set
, ~_BLOCKABLE
);
198 spin_lock_irq(¤t
->sighand
->siglock
);
199 current
->blocked
= set
;
201 spin_unlock_irq(¤t
->sighand
->siglock
);
205 force_sig(SIGSEGV
, current
);
208 asmlinkage
void do_sigreturn(struct pt_regs
*regs
)
210 struct sigcontext __user
*scptr
;
211 unsigned long pc
, npc
, psr
;
215 /* Always make any pending restarted system calls return -EINTR */
216 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
218 synchronize_user_stack();
220 if (current
->thread
.new_signal
) {
221 do_new_sigreturn(regs
);
225 scptr
= (struct sigcontext __user
*) regs
->u_regs
[UREG_I0
];
227 /* Check sanity of the user arg. */
228 if (!access_ok(VERIFY_READ
, scptr
, sizeof(struct sigcontext
)) ||
229 (((unsigned long) scptr
) & 3))
232 err
= __get_user(pc
, &scptr
->sigc_pc
);
233 err
|= __get_user(npc
, &scptr
->sigc_npc
);
238 /* This is pretty much atomic, no amount locking would prevent
239 * the races which exist anyways.
241 err
|= __get_user(set
.sig
[0], &scptr
->sigc_mask
);
242 /* Note that scptr + 1 points to extramask */
243 err
|= __copy_from_user(&set
.sig
[1], scptr
+ 1,
244 (_NSIG_WORDS
- 1) * sizeof(unsigned int));
249 sigdelsetmask(&set
, ~_BLOCKABLE
);
250 spin_lock_irq(¤t
->sighand
->siglock
);
251 current
->blocked
= set
;
253 spin_unlock_irq(¤t
->sighand
->siglock
);
258 err
= __get_user(regs
->u_regs
[UREG_FP
], &scptr
->sigc_sp
);
259 err
|= __get_user(regs
->u_regs
[UREG_I0
], &scptr
->sigc_o0
);
260 err
|= __get_user(regs
->u_regs
[UREG_G1
], &scptr
->sigc_g1
);
262 /* User can only change condition codes in %psr. */
263 err
|= __get_user(psr
, &scptr
->sigc_psr
);
267 regs
->psr
&= ~(PSR_ICC
);
268 regs
->psr
|= (psr
& PSR_ICC
);
272 force_sig(SIGSEGV
, current
);
275 asmlinkage
void do_rt_sigreturn(struct pt_regs
*regs
)
277 struct rt_signal_frame __user
*sf
;
278 unsigned int psr
, pc
, npc
;
279 __siginfo_fpu_t __user
*fpu_save
;
285 synchronize_user_stack();
286 sf
= (struct rt_signal_frame __user
*) regs
->u_regs
[UREG_FP
];
287 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)) ||
288 (((unsigned long) sf
) & 0x03))
291 err
= __get_user(pc
, &sf
->regs
.pc
);
292 err
|= __get_user(npc
, &sf
->regs
.npc
);
293 err
|= ((pc
| npc
) & 0x03);
295 err
|= __get_user(regs
->y
, &sf
->regs
.y
);
296 err
|= __get_user(psr
, &sf
->regs
.psr
);
298 err
|= __copy_from_user(®s
->u_regs
[UREG_G1
],
299 &sf
->regs
.u_regs
[UREG_G1
], 15 * sizeof(u32
));
301 regs
->psr
= (regs
->psr
& ~PSR_ICC
) | (psr
& PSR_ICC
);
303 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
306 err
|= restore_fpu_state(regs
, fpu_save
);
307 err
|= __copy_from_user(&set
, &sf
->mask
, sizeof(sigset_t
));
309 err
|= __copy_from_user(&st
, &sf
->stack
, sizeof(stack_t
));
317 /* It is more difficult to avoid calling this function than to
318 * call it and ignore errors.
322 do_sigaltstack((const stack_t __user
*) &st
, NULL
, (unsigned long)sf
);
325 sigdelsetmask(&set
, ~_BLOCKABLE
);
326 spin_lock_irq(¤t
->sighand
->siglock
);
327 current
->blocked
= set
;
329 spin_unlock_irq(¤t
->sighand
->siglock
);
332 force_sig(SIGSEGV
, current
);
335 /* Checks if the fp is valid */
336 static inline int invalid_frame_pointer(void __user
*fp
, int fplen
)
338 if ((((unsigned long) fp
) & 7) ||
339 !__access_ok((unsigned long)fp
, fplen
) ||
340 ((sparc_cpu_model
== sun4
|| sparc_cpu_model
== sun4c
) &&
341 ((unsigned long) fp
< 0xe0000000 && (unsigned long) fp
>= 0x20000000)))
347 static inline void __user
*get_sigframe(struct sigaction
*sa
, struct pt_regs
*regs
, unsigned long framesize
)
351 sp
= regs
->u_regs
[UREG_FP
];
353 /* This is the X/Open sanctioned signal stack switching. */
354 if (sa
->sa_flags
& SA_ONSTACK
) {
355 if (!on_sig_stack(sp
) && !((current
->sas_ss_sp
+ current
->sas_ss_size
) & 7))
356 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
358 return (void __user
*)(sp
- framesize
);
362 setup_frame(struct sigaction
*sa
, struct pt_regs
*regs
, int signr
, sigset_t
*oldset
, siginfo_t
*info
)
364 struct signal_sframe __user
*sframep
;
365 struct sigcontext __user
*sc
;
367 unsigned long pc
= regs
->pc
;
368 unsigned long npc
= regs
->npc
;
369 struct thread_info
*tp
= current_thread_info();
370 void __user
*sig_address
;
373 synchronize_user_stack();
374 sframep
= (struct signal_sframe __user
*)
375 get_sigframe(sa
, regs
, SF_ALIGNEDSZ
);
376 if (invalid_frame_pointer(sframep
, sizeof(*sframep
))){
377 /* Don't change signal code and address, so that
378 * post mortem debuggers can have a look.
380 goto sigill_and_return
;
383 sc
= &sframep
->sig_context
;
385 /* We've already made sure frame pointer isn't in kernel space... */
386 err
= __put_user((sas_ss_flags(regs
->u_regs
[UREG_FP
]) == SS_ONSTACK
),
388 err
|= __put_user(oldset
->sig
[0], &sc
->sigc_mask
);
389 err
|= __copy_to_user(sframep
->extramask
, &oldset
->sig
[1],
390 (_NSIG_WORDS
- 1) * sizeof(unsigned int));
391 err
|= __put_user(regs
->u_regs
[UREG_FP
], &sc
->sigc_sp
);
392 err
|= __put_user(pc
, &sc
->sigc_pc
);
393 err
|= __put_user(npc
, &sc
->sigc_npc
);
394 err
|= __put_user(regs
->psr
, &sc
->sigc_psr
);
395 err
|= __put_user(regs
->u_regs
[UREG_G1
], &sc
->sigc_g1
);
396 err
|= __put_user(regs
->u_regs
[UREG_I0
], &sc
->sigc_o0
);
397 err
|= __put_user(tp
->w_saved
, &sc
->sigc_oswins
);
399 for (window
= 0; window
< tp
->w_saved
; window
++) {
400 put_user((char *)tp
->rwbuf_stkptrs
[window
],
401 &sc
->sigc_spbuf
[window
]);
402 err
|= __copy_to_user(&sc
->sigc_wbuf
[window
],
403 &tp
->reg_window
[window
],
404 sizeof(struct reg_window
));
407 err
|= __copy_to_user(sframep
, (char *) regs
->u_regs
[UREG_FP
],
408 sizeof(struct reg_window
));
410 tp
->w_saved
= 0; /* So process is allowed to execute. */
412 err
|= __put_user(signr
, &sframep
->sig_num
);
415 if (SI_FROMKERNEL (info
) && (info
->si_code
& __SI_MASK
) == __SI_FAULT
) {
416 sig_address
= info
->si_addr
;
419 switch (info
->si_code
) {
420 case SEGV_MAPERR
: sig_code
= SUBSIG_NOMAPPING
; break;
421 default: sig_code
= SUBSIG_PROTECTION
; break;
425 switch (info
->si_code
) {
426 case ILL_ILLOPC
: sig_code
= SUBSIG_ILLINST
; break;
427 case ILL_PRVOPC
: sig_code
= SUBSIG_PRIVINST
; break;
428 case ILL_ILLTRP
: sig_code
= SUBSIG_BADTRAP(info
->si_trapno
); break;
429 default: sig_code
= SUBSIG_STACK
; break;
433 switch (info
->si_code
) {
434 case FPE_INTDIV
: sig_code
= SUBSIG_IDIVZERO
; break;
435 case FPE_INTOVF
: sig_code
= SUBSIG_FPINTOVFL
; break;
436 case FPE_FLTDIV
: sig_code
= SUBSIG_FPDIVZERO
; break;
437 case FPE_FLTOVF
: sig_code
= SUBSIG_FPOVFLOW
; break;
438 case FPE_FLTUND
: sig_code
= SUBSIG_FPUNFLOW
; break;
439 case FPE_FLTRES
: sig_code
= SUBSIG_FPINEXACT
; break;
440 case FPE_FLTINV
: sig_code
= SUBSIG_FPOPERROR
; break;
441 default: sig_code
= SUBSIG_FPERROR
; break;
445 switch (info
->si_code
) {
446 case BUS_ADRALN
: sig_code
= SUBSIG_ALIGNMENT
; break;
447 case BUS_ADRERR
: sig_code
= SUBSIG_MISCERROR
; break;
448 default: sig_code
= SUBSIG_BUSTIMEOUT
; break;
452 switch (info
->si_code
) {
453 case EMT_TAGOVF
: sig_code
= SUBSIG_TAG
; break;
457 if (info
->si_code
== (__SI_FAULT
|0x100)) {
458 /* See sys_sunos.c */
459 sig_code
= info
->si_trapno
;
466 err
|= __put_user((unsigned long)sig_address
, &sframep
->sig_address
);
467 err
|= __put_user(sig_code
, &sframep
->sig_code
);
468 err
|= __put_user(sc
, &sframep
->sig_scptr
);
472 regs
->u_regs
[UREG_FP
] = (unsigned long) sframep
;
473 regs
->pc
= (unsigned long) sa
->sa_handler
;
474 regs
->npc
= (regs
->pc
+ 4);
480 force_sigsegv(signr
, current
);
485 save_fpu_state(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
489 if (test_tsk_thread_flag(current
, TIF_USEDFPU
)) {
490 put_psr(get_psr() | PSR_EF
);
491 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
492 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
493 regs
->psr
&= ~(PSR_EF
);
494 clear_tsk_thread_flag(current
, TIF_USEDFPU
);
497 if (current
== last_task_used_math
) {
498 put_psr(get_psr() | PSR_EF
);
499 fpsave(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
,
500 ¤t
->thread
.fpqueue
[0], ¤t
->thread
.fpqdepth
);
501 last_task_used_math
= NULL
;
502 regs
->psr
&= ~(PSR_EF
);
505 err
|= __copy_to_user(&fpu
->si_float_regs
[0],
506 ¤t
->thread
.float_regs
[0],
507 (sizeof(unsigned long) * 32));
508 err
|= __put_user(current
->thread
.fsr
, &fpu
->si_fsr
);
509 err
|= __put_user(current
->thread
.fpqdepth
, &fpu
->si_fpqdepth
);
510 if (current
->thread
.fpqdepth
!= 0)
511 err
|= __copy_to_user(&fpu
->si_fpqueue
[0],
512 ¤t
->thread
.fpqueue
[0],
513 ((sizeof(unsigned long) +
514 (sizeof(unsigned long *)))*16));
520 new_setup_frame(struct k_sigaction
*ka
, struct pt_regs
*regs
,
521 int signo
, sigset_t
*oldset
)
523 struct new_signal_frame __user
*sf
;
524 int sigframe_size
, err
;
526 /* 1. Make sure everything is clean */
527 synchronize_user_stack();
529 sigframe_size
= NF_ALIGNEDSZ
;
531 sigframe_size
-= sizeof(__siginfo_fpu_t
);
533 sf
= (struct new_signal_frame __user
*)
534 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
536 if (invalid_frame_pointer(sf
, sigframe_size
))
537 goto sigill_and_return
;
539 if (current_thread_info()->w_saved
!= 0)
540 goto sigill_and_return
;
542 /* 2. Save the current process state */
543 err
= __copy_to_user(&sf
->info
.si_regs
, regs
, sizeof(struct pt_regs
));
545 err
|= __put_user(0, &sf
->extra_size
);
548 err
|= save_fpu_state(regs
, &sf
->fpu_state
);
549 err
|= __put_user(&sf
->fpu_state
, &sf
->fpu_save
);
551 err
|= __put_user(0, &sf
->fpu_save
);
554 err
|= __put_user(oldset
->sig
[0], &sf
->info
.si_mask
);
555 err
|= __copy_to_user(sf
->extramask
, &oldset
->sig
[1],
556 (_NSIG_WORDS
- 1) * sizeof(unsigned int));
557 err
|= __copy_to_user(sf
, (char *) regs
->u_regs
[UREG_FP
],
558 sizeof(struct reg_window
));
562 /* 3. signal handler back-trampoline and parameters */
563 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
564 regs
->u_regs
[UREG_I0
] = signo
;
565 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
566 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->info
;
568 /* 4. signal handler */
569 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
570 regs
->npc
= (regs
->pc
+ 4);
572 /* 5. return to kernel instructions */
574 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
576 regs
->u_regs
[UREG_I7
] = (unsigned long)(&(sf
->insns
[0]) - 2);
578 /* mov __NR_sigreturn, %g1 */
579 err
|= __put_user(0x821020d8, &sf
->insns
[0]);
582 err
|= __put_user(0x91d02010, &sf
->insns
[1]);
586 /* Flush instruction space. */
587 flush_sig_insns(current
->mm
, (unsigned long) &(sf
->insns
[0]));
594 force_sigsegv(signo
, current
);
598 new_setup_rt_frame(struct k_sigaction
*ka
, struct pt_regs
*regs
,
599 int signo
, sigset_t
*oldset
, siginfo_t
*info
)
601 struct rt_signal_frame __user
*sf
;
606 synchronize_user_stack();
607 sigframe_size
= RT_ALIGNEDSZ
;
609 sigframe_size
-= sizeof(__siginfo_fpu_t
);
610 sf
= (struct rt_signal_frame __user
*)
611 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
612 if (invalid_frame_pointer(sf
, sigframe_size
))
614 if (current_thread_info()->w_saved
!= 0)
617 err
= __put_user(regs
->pc
, &sf
->regs
.pc
);
618 err
|= __put_user(regs
->npc
, &sf
->regs
.npc
);
619 err
|= __put_user(regs
->y
, &sf
->regs
.y
);
623 err
|= __put_user(psr
, &sf
->regs
.psr
);
624 err
|= __copy_to_user(&sf
->regs
.u_regs
, regs
->u_regs
, sizeof(regs
->u_regs
));
625 err
|= __put_user(0, &sf
->extra_size
);
628 err
|= save_fpu_state(regs
, &sf
->fpu_state
);
629 err
|= __put_user(&sf
->fpu_state
, &sf
->fpu_save
);
631 err
|= __put_user(0, &sf
->fpu_save
);
633 err
|= __copy_to_user(&sf
->mask
, &oldset
->sig
[0], sizeof(sigset_t
));
635 /* Setup sigaltstack */
636 err
|= __put_user(current
->sas_ss_sp
, &sf
->stack
.ss_sp
);
637 err
|= __put_user(sas_ss_flags(regs
->u_regs
[UREG_FP
]), &sf
->stack
.ss_flags
);
638 err
|= __put_user(current
->sas_ss_size
, &sf
->stack
.ss_size
);
640 err
|= __copy_to_user(sf
, (char *) regs
->u_regs
[UREG_FP
],
641 sizeof(struct reg_window
));
643 err
|= copy_siginfo_to_user(&sf
->info
, info
);
648 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
649 regs
->u_regs
[UREG_I0
] = signo
;
650 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
651 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->regs
;
653 regs
->pc
= (unsigned long) ka
->sa
.sa_handler
;
654 regs
->npc
= (regs
->pc
+ 4);
657 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
659 regs
->u_regs
[UREG_I7
] = (unsigned long)(&(sf
->insns
[0]) - 2);
661 /* mov __NR_sigreturn, %g1 */
662 err
|= __put_user(0x821020d8, &sf
->insns
[0]);
665 err
|= __put_user(0x91d02010, &sf
->insns
[1]);
669 /* Flush instruction space. */
670 flush_sig_insns(current
->mm
, (unsigned long) &(sf
->insns
[0]));
677 force_sigsegv(signo
, current
);
680 /* Setup a Solaris stack frame */
682 setup_svr4_frame(struct sigaction
*sa
, unsigned long pc
, unsigned long npc
,
683 struct pt_regs
*regs
, int signr
, sigset_t
*oldset
)
685 svr4_signal_frame_t __user
*sfp
;
686 svr4_gregset_t __user
*gr
;
687 svr4_siginfo_t __user
*si
;
688 svr4_mcontext_t __user
*mc
;
689 svr4_gwindows_t __user
*gw
;
690 svr4_ucontext_t __user
*uc
;
692 struct thread_info
*tp
= current_thread_info();
695 synchronize_user_stack();
696 sfp
= (svr4_signal_frame_t __user
*)
697 get_sigframe(sa
, regs
, SVR4_SF_ALIGNED
+ sizeof(struct reg_window
));
699 if (invalid_frame_pointer(sfp
, sizeof(*sfp
)))
700 goto sigill_and_return
;
702 /* Start with a clean frame pointer and fill it */
703 err
= __clear_user(sfp
, sizeof(*sfp
));
705 /* Setup convenience variables */
712 /* FIXME: where am I supposed to put this?
713 * sc->sigc_onstack = old_status;
714 * anyways, it does not look like it is used for anything at all.
716 setv
.sigbits
[0] = oldset
->sig
[0];
717 setv
.sigbits
[1] = oldset
->sig
[1];
718 if (_NSIG_WORDS
>= 4) {
719 setv
.sigbits
[2] = oldset
->sig
[2];
720 setv
.sigbits
[3] = oldset
->sig
[3];
721 err
|= __copy_to_user(&uc
->sigmask
, &setv
, sizeof(svr4_sigset_t
));
723 err
|= __copy_to_user(&uc
->sigmask
, &setv
,
724 2 * sizeof(unsigned int));
726 /* Store registers */
727 err
|= __put_user(regs
->pc
, &((*gr
)[SVR4_PC
]));
728 err
|= __put_user(regs
->npc
, &((*gr
)[SVR4_NPC
]));
729 err
|= __put_user(regs
->psr
, &((*gr
)[SVR4_PSR
]));
730 err
|= __put_user(regs
->y
, &((*gr
)[SVR4_Y
]));
732 /* Copy g[1..7] and o[0..7] registers */
733 err
|= __copy_to_user(&(*gr
)[SVR4_G1
], ®s
->u_regs
[UREG_G1
],
735 err
|= __copy_to_user(&(*gr
)[SVR4_O0
], ®s
->u_regs
[UREG_I0
],
738 /* Setup sigaltstack */
739 err
|= __put_user(current
->sas_ss_sp
, &uc
->stack
.sp
);
740 err
|= __put_user(sas_ss_flags(regs
->u_regs
[UREG_FP
]), &uc
->stack
.flags
);
741 err
|= __put_user(current
->sas_ss_size
, &uc
->stack
.size
);
743 /* Save the currently window file: */
745 /* 1. Link sfp->uc->gwins to our windows */
746 err
|= __put_user(gw
, &mc
->gwin
);
748 /* 2. Number of windows to restore at setcontext(): */
749 err
|= __put_user(tp
->w_saved
, &gw
->count
);
751 /* 3. Save each valid window
752 * Currently, it makes a copy of the windows from the kernel copy.
753 * David's code for SunOS, makes the copy but keeps the pointer to
754 * the kernel. My version makes the pointer point to a userland
755 * copy of those. Mhm, I wonder if I shouldn't just ignore those
756 * on setcontext and use those that are on the kernel, the signal
757 * handler should not be modyfing those, mhm.
759 * These windows are just used in case synchronize_user_stack failed
760 * to flush the user windows.
762 for (window
= 0; window
< tp
->w_saved
; window
++) {
763 err
|= __put_user((int __user
*) &(gw
->win
[window
]), &gw
->winptr
[window
]);
764 err
|= __copy_to_user(&gw
->win
[window
],
765 &tp
->reg_window
[window
],
766 sizeof(svr4_rwindow_t
));
767 err
|= __put_user(0, gw
->winptr
[window
]);
770 /* 4. We just pay attention to the gw->count field on setcontext */
771 tp
->w_saved
= 0; /* So process is allowed to execute. */
773 /* Setup the signal information. Solaris expects a bunch of
774 * information to be passed to the signal handler, we don't provide
775 * that much currently, should use siginfo.
777 err
|= __put_user(signr
, &si
->siginfo
.signo
);
778 err
|= __put_user(SVR4_SINOINFO
, &si
->siginfo
.code
);
782 regs
->u_regs
[UREG_FP
] = (unsigned long) sfp
;
783 regs
->pc
= (unsigned long) sa
->sa_handler
;
784 regs
->npc
= (regs
->pc
+ 4);
786 /* Arguments passed to signal handler */
787 if (regs
->u_regs
[14]){
788 struct reg_window __user
*rw
= (struct reg_window __user
*)
791 err
|= __put_user(signr
, &rw
->ins
[0]);
792 err
|= __put_user(si
, &rw
->ins
[1]);
793 err
|= __put_user(uc
, &rw
->ins
[2]);
794 err
|= __put_user(sfp
, &rw
->ins
[6]); /* frame pointer */
798 regs
->u_regs
[UREG_I0
] = signr
;
799 regs
->u_regs
[UREG_I1
] = (unsigned long) si
;
800 regs
->u_regs
[UREG_I2
] = (unsigned long) uc
;
807 force_sigsegv(signr
, current
);
810 asmlinkage
int svr4_getcontext(svr4_ucontext_t __user
*uc
, struct pt_regs
*regs
)
812 svr4_gregset_t __user
*gr
;
813 svr4_mcontext_t __user
*mc
;
817 synchronize_user_stack();
819 if (current_thread_info()->w_saved
)
822 err
= clear_user(uc
, sizeof(*uc
));
826 /* Setup convenience variables */
830 setv
.sigbits
[0] = current
->blocked
.sig
[0];
831 setv
.sigbits
[1] = current
->blocked
.sig
[1];
832 if (_NSIG_WORDS
>= 4) {
833 setv
.sigbits
[2] = current
->blocked
.sig
[2];
834 setv
.sigbits
[3] = current
->blocked
.sig
[3];
835 err
|= __copy_to_user(&uc
->sigmask
, &setv
, sizeof(svr4_sigset_t
));
837 err
|= __copy_to_user(&uc
->sigmask
, &setv
,
838 2 * sizeof(unsigned int));
840 /* Store registers */
841 err
|= __put_user(regs
->pc
, &uc
->mcontext
.greg
[SVR4_PC
]);
842 err
|= __put_user(regs
->npc
, &uc
->mcontext
.greg
[SVR4_NPC
]);
843 err
|= __put_user(regs
->psr
, &uc
->mcontext
.greg
[SVR4_PSR
]);
844 err
|= __put_user(regs
->y
, &uc
->mcontext
.greg
[SVR4_Y
]);
846 /* Copy g[1..7] and o[0..7] registers */
847 err
|= __copy_to_user(&(*gr
)[SVR4_G1
], ®s
->u_regs
[UREG_G1
],
849 err
|= __copy_to_user(&(*gr
)[SVR4_O0
], ®s
->u_regs
[UREG_I0
],
852 /* Setup sigaltstack */
853 err
|= __put_user(current
->sas_ss_sp
, &uc
->stack
.sp
);
854 err
|= __put_user(sas_ss_flags(regs
->u_regs
[UREG_FP
]), &uc
->stack
.flags
);
855 err
|= __put_user(current
->sas_ss_size
, &uc
->stack
.size
);
857 /* The register file is not saved
858 * we have already stuffed all of it with sync_user_stack
860 return (err
? -EFAULT
: 0);
863 /* Set the context for a svr4 application, this is Solaris way to sigreturn */
864 asmlinkage
int svr4_setcontext(svr4_ucontext_t __user
*c
, struct pt_regs
*regs
)
866 svr4_gregset_t __user
*gr
;
867 unsigned long pc
, npc
, psr
;
874 /* Fixme: restore windows, or is this already taken care of in
875 * svr4_setup_frame when sync_user_windows is done?
877 flush_user_windows();
879 if (current_thread_info()->w_saved
)
880 goto sigsegv_and_return
;
882 if (((unsigned long) c
) & 3)
883 goto sigsegv_and_return
;
885 if (!__access_ok((unsigned long)c
, sizeof(*c
)))
886 goto sigsegv_and_return
;
888 /* Check for valid PC and nPC */
889 gr
= &c
->mcontext
.greg
;
890 err
= __get_user(pc
, &((*gr
)[SVR4_PC
]));
891 err
|= __get_user(npc
, &((*gr
)[SVR4_NPC
]));
894 goto sigsegv_and_return
;
896 /* Retrieve information from passed ucontext */
897 /* note that nPC is ored a 1, this is used to inform entry.S */
898 /* that we don't want it to mess with our PC and nPC */
900 /* This is pretty much atomic, no amount locking would prevent
901 * the races which exist anyways.
903 err
|= __copy_from_user(&setv
, &c
->sigmask
, sizeof(svr4_sigset_t
));
905 err
|= __get_user(st
.ss_sp
, &c
->stack
.sp
);
906 err
|= __get_user(st
.ss_flags
, &c
->stack
.flags
);
907 err
|= __get_user(st
.ss_size
, &c
->stack
.size
);
910 goto sigsegv_and_return
;
912 /* It is more difficult to avoid calling this function than to
913 call it and ignore errors. */
916 do_sigaltstack((const stack_t __user
*) &st
, NULL
,
917 regs
->u_regs
[UREG_I6
]);
920 set
.sig
[0] = setv
.sigbits
[0];
921 set
.sig
[1] = setv
.sigbits
[1];
922 if (_NSIG_WORDS
>= 4) {
923 set
.sig
[2] = setv
.sigbits
[2];
924 set
.sig
[3] = setv
.sigbits
[3];
926 sigdelsetmask(&set
, ~_BLOCKABLE
);
927 spin_lock_irq(¤t
->sighand
->siglock
);
928 current
->blocked
= set
;
930 spin_unlock_irq(¤t
->sighand
->siglock
);
933 err
|= __get_user(regs
->y
, &((*gr
)[SVR4_Y
]));
934 err
|= __get_user(psr
, &((*gr
)[SVR4_PSR
]));
935 regs
->psr
&= ~(PSR_ICC
);
936 regs
->psr
|= (psr
& PSR_ICC
);
938 /* Restore g[1..7] and o[0..7] registers */
939 err
|= __copy_from_user(®s
->u_regs
[UREG_G1
], &(*gr
)[SVR4_G1
],
941 err
|= __copy_from_user(®s
->u_regs
[UREG_I0
], &(*gr
)[SVR4_O0
],
943 return (err
? -EFAULT
: 0);
946 force_sig(SIGSEGV
, current
);
951 handle_signal(unsigned long signr
, struct k_sigaction
*ka
,
952 siginfo_t
*info
, sigset_t
*oldset
, struct pt_regs
*regs
,
956 setup_svr4_frame(&ka
->sa
, regs
->pc
, regs
->npc
, regs
, signr
, oldset
);
958 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
959 new_setup_rt_frame(ka
, regs
, signr
, oldset
, info
);
960 else if (current
->thread
.new_signal
)
961 new_setup_frame(ka
, regs
, signr
, oldset
);
963 setup_frame(&ka
->sa
, regs
, signr
, oldset
, info
);
965 spin_lock_irq(¤t
->sighand
->siglock
);
966 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
967 if (!(ka
->sa
.sa_flags
& SA_NOMASK
))
968 sigaddset(¤t
->blocked
, signr
);
970 spin_unlock_irq(¤t
->sighand
->siglock
);
973 static inline void syscall_restart(unsigned long orig_i0
, struct pt_regs
*regs
,
974 struct sigaction
*sa
)
976 switch(regs
->u_regs
[UREG_I0
]) {
977 case ERESTART_RESTARTBLOCK
:
979 no_system_call_restart
:
980 regs
->u_regs
[UREG_I0
] = EINTR
;
984 if (!(sa
->sa_flags
& SA_RESTART
))
985 goto no_system_call_restart
;
988 regs
->u_regs
[UREG_I0
] = orig_i0
;
994 /* Note that 'init' is a special process: it doesn't get signals it doesn't
995 * want to handle. Thus you cannot kill init even with a SIGKILL even by
998 asmlinkage
void do_signal(struct pt_regs
* regs
, unsigned long orig_i0
, int restart_syscall
)
1001 struct sparc_deliver_cookie cookie
;
1002 struct k_sigaction ka
;
1007 * XXX Disable svr4 signal handling until solaris emulation works.
1008 * It is buggy - Anton
1010 #define SVR4_SIGNAL_BROKEN 1
1011 #ifdef SVR4_SIGNAL_BROKEN
1012 int svr4_signal
= 0;
1014 int svr4_signal
= current
->personality
== PER_SVR4
;
1017 cookie
.restart_syscall
= restart_syscall
;
1018 cookie
.orig_i0
= orig_i0
;
1020 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
1021 oldset
= ¤t
->saved_sigmask
;
1023 oldset
= ¤t
->blocked
;
1025 signr
= get_signal_to_deliver(&info
, &ka
, regs
, &cookie
);
1027 if (cookie
.restart_syscall
)
1028 syscall_restart(cookie
.orig_i0
, regs
, &ka
.sa
);
1029 handle_signal(signr
, &ka
, &info
, oldset
,
1031 /* a signal was successfully delivered; the saved
1032 * sigmask will have been stored in the signal frame,
1033 * and will be restored by sigreturn, so we can simply
1034 * clear the TIF_RESTORE_SIGMASK flag.
1036 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
1037 clear_thread_flag(TIF_RESTORE_SIGMASK
);
1040 if (cookie
.restart_syscall
&&
1041 (regs
->u_regs
[UREG_I0
] == ERESTARTNOHAND
||
1042 regs
->u_regs
[UREG_I0
] == ERESTARTSYS
||
1043 regs
->u_regs
[UREG_I0
] == ERESTARTNOINTR
)) {
1044 /* replay the system call when we are done */
1045 regs
->u_regs
[UREG_I0
] = cookie
.orig_i0
;
1049 if (cookie
.restart_syscall
&&
1050 regs
->u_regs
[UREG_I0
] == ERESTART_RESTARTBLOCK
) {
1051 regs
->u_regs
[UREG_G1
] = __NR_restart_syscall
;
1056 /* if there's no signal to deliver, we just put the saved sigmask
1059 if (test_thread_flag(TIF_RESTORE_SIGMASK
)) {
1060 clear_thread_flag(TIF_RESTORE_SIGMASK
);
1061 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
1066 do_sys_sigstack(struct sigstack __user
*ssptr
, struct sigstack __user
*ossptr
,
1071 /* First see if old state is wanted. */
1073 if (put_user(current
->sas_ss_sp
+ current
->sas_ss_size
,
1074 &ossptr
->the_stack
) ||
1075 __put_user(on_sig_stack(sp
), &ossptr
->cur_status
))
1079 /* Now see if we want to update the new state. */
1083 if (get_user(ss_sp
, &ssptr
->the_stack
))
1085 /* If the current stack was set with sigaltstack, don't
1086 swap stacks while we are on it. */
1088 if (current
->sas_ss_sp
&& on_sig_stack(sp
))
1091 /* Since we don't know the extent of the stack, and we don't
1092 track onstack-ness, but rather calculate it, we must
1093 presume a size. Ho hum this interface is lossy. */
1094 current
->sas_ss_sp
= (unsigned long)ss_sp
- SIGSTKSZ
;
1095 current
->sas_ss_size
= SIGSTKSZ
;
1102 void ptrace_signal_deliver(struct pt_regs
*regs
, void *cookie
)
1104 struct sparc_deliver_cookie
*cp
= cookie
;
1106 if (cp
->restart_syscall
&&
1107 (regs
->u_regs
[UREG_I0
] == ERESTARTNOHAND
||
1108 regs
->u_regs
[UREG_I0
] == ERESTARTSYS
||
1109 regs
->u_regs
[UREG_I0
] == ERESTARTNOINTR
)) {
1110 /* replay the system call when we are done */
1111 regs
->u_regs
[UREG_I0
] = cp
->orig_i0
;
1114 cp
->restart_syscall
= 0;
1117 if (cp
->restart_syscall
&&
1118 regs
->u_regs
[UREG_I0
] == ERESTART_RESTARTBLOCK
) {
1119 regs
->u_regs
[UREG_G1
] = __NR_restart_syscall
;
1122 cp
->restart_syscall
= 0;