1 /* $Id: signal32.c,v 1.74 2002/02/09 19:49:30 davem Exp $
2 * arch/sparc64/kernel/signal32.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)
8 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
11 #include <linux/sched.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/errno.h>
15 #include <linux/wait.h>
16 #include <linux/ptrace.h>
17 #include <linux/unistd.h>
19 #include <linux/tty.h>
20 #include <linux/binfmts.h>
21 #include <linux/compat.h>
22 #include <linux/bitops.h>
24 #include <asm/uaccess.h>
25 #include <asm/ptrace.h>
26 #include <asm/pgtable.h>
27 #include <asm/psrcompat.h>
28 #include <asm/fpumacro.h>
29 #include <asm/visasm.h>
30 #include <asm/compat_signal.h>
32 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 /* Signal frames: the original one (compatible with SunOS):
36 * Set up a signal frame... Make the stack look the way SunOS
37 * expects it to look which is basically:
39 * ---------------------------------- <-- %sp at signal time
42 * Ptr to sigcontext area above
44 * The signal number itself
46 * ---------------------------------- <-- New %sp
48 struct signal_sframe32 {
49 struct reg_window32 sig_window;
52 /* struct sigcontext32 * */ u32 sig_scptr;
54 struct sigcontext32 sig_context;
55 unsigned int extramask[_COMPAT_NSIG_WORDS - 1];
58 /* This magic should be in g_upper[0] for all upper parts
61 #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269
63 unsigned int g_upper[8];
64 unsigned int o_upper[8];
66 } siginfo_extra_v8plus_t;
69 * And the new one, intended to be used for Linux applications only
70 * (we have enough in there to work with clone).
71 * All the interesting bits are in the info field.
73 struct new_signal_frame32 {
74 struct sparc_stackf32 ss;
76 /* __siginfo_fpu32_t * */ u32 fpu_save;
77 unsigned int insns[2];
78 unsigned int extramask[_COMPAT_NSIG_WORDS - 1];
79 unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
80 /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
81 siginfo_extra_v8plus_t v8plus;
82 __siginfo_fpu_t fpu_state;
85 typedef struct compat_siginfo{
91 int _pad[SI_PAD_SIZE32];
95 compat_pid_t _pid; /* sender's pid */
96 unsigned int _uid; /* sender's uid */
101 compat_timer_t _tid; /* timer id */
102 int _overrun; /* overrun count */
103 compat_sigval_t _sigval; /* same as below */
104 int _sys_private; /* not to be passed to user */
107 /* POSIX.1b signals */
109 compat_pid_t _pid; /* sender's pid */
110 unsigned int _uid; /* sender's uid */
111 compat_sigval_t _sigval;
116 compat_pid_t _pid; /* which child */
117 unsigned int _uid; /* sender's uid */
118 int _status; /* exit code */
119 compat_clock_t _utime;
120 compat_clock_t _stime;
123 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */
125 u32 _addr; /* faulting insn/memory ref. */
131 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
137 struct rt_signal_frame32 {
138 struct sparc_stackf32 ss;
139 compat_siginfo_t info;
140 struct pt_regs32 regs;
141 compat_sigset_t mask;
142 /* __siginfo_fpu32_t * */ u32 fpu_save;
143 unsigned int insns[2];
145 unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
146 /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
147 siginfo_extra_v8plus_t v8plus;
148 __siginfo_fpu_t fpu_state;
152 #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe32) + 7) & (~7)))
153 #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame32) + 7) & (~7)))
154 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame32) + 7) & (~7)))
156 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
160 if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
163 /* If you change siginfo_t structure, please be sure
164 this code is fixed accordingly.
165 It should never copy any pad contained in the structure
166 to avoid security leaks, but must copy the generic
167 3 ints plus the relevant union member.
168 This routine must convert siginfo from 64bit to 32bit as well
170 err = __put_user(from->si_signo, &to->si_signo);
171 err |= __put_user(from->si_errno, &to->si_errno);
172 err |= __put_user((short)from->si_code, &to->si_code);
173 if (from->si_code < 0)
174 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
176 switch (from->si_code >> 16) {
177 case __SI_TIMER >> 16:
178 err |= __put_user(from->si_tid, &to->si_tid);
179 err |= __put_user(from->si_overrun, &to->si_overrun);
180 err |= __put_user(from->si_int, &to->si_int);
182 case __SI_CHLD >> 16:
183 err |= __put_user(from->si_utime, &to->si_utime);
184 err |= __put_user(from->si_stime, &to->si_stime);
185 err |= __put_user(from->si_status, &to->si_status);
187 err |= __put_user(from->si_pid, &to->si_pid);
188 err |= __put_user(from->si_uid, &to->si_uid);
190 case __SI_FAULT >> 16:
191 err |= __put_user(from->si_trapno, &to->si_trapno);
192 err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
194 case __SI_POLL >> 16:
195 err |= __put_user(from->si_band, &to->si_band);
196 err |= __put_user(from->si_fd, &to->si_fd);
198 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
199 case __SI_MESGQ >> 16:
200 err |= __put_user(from->si_pid, &to->si_pid);
201 err |= __put_user(from->si_uid, &to->si_uid);
202 err |= __put_user(from->si_int, &to->si_int);
209 /* CAUTION: This is just a very minimalist implementation for the
210 * sake of compat_sys_rt_sigqueueinfo()
212 int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
214 if (!access_ok(VERIFY_WRITE, from, sizeof(compat_siginfo_t)))
217 if (copy_from_user(to, from, 3*sizeof(int)) ||
218 copy_from_user(to->_sifields._pad, from->_sifields._pad,
225 static int restore_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
227 unsigned long *fpregs = current_thread_info()->fpregs;
231 err = __get_user(fprs, &fpu->si_fprs);
233 regs->tstate &= ~TSTATE_PEF;
235 err |= copy_from_user(fpregs, &fpu->si_float_regs[0], (sizeof(unsigned int) * 32));
237 err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32], (sizeof(unsigned int) * 32));
238 err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
239 err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr);
240 current_thread_info()->fpsaved[0] |= fprs;
244 void do_new_sigreturn32(struct pt_regs *regs)
246 struct new_signal_frame32 __user *sf;
248 unsigned pc, npc, fpu_save;
250 unsigned seta[_COMPAT_NSIG_WORDS];
253 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
254 sf = (struct new_signal_frame32 __user *) regs->u_regs[UREG_FP];
256 /* 1. Make sure we are not getting garbage from the user */
257 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
258 (((unsigned long) sf) & 3))
261 get_user(pc, &sf->info.si_regs.pc);
262 __get_user(npc, &sf->info.si_regs.npc);
267 if (test_thread_flag(TIF_32BIT)) {
274 /* 2. Restore the state */
275 err = __get_user(regs->y, &sf->info.si_regs.y);
276 err |= __get_user(psr, &sf->info.si_regs.psr);
278 for (i = UREG_G1; i <= UREG_I7; i++)
279 err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
280 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
281 err |= __get_user(i, &sf->v8plus.g_upper[0]);
282 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
285 for (i = UREG_G1; i <= UREG_I7; i++)
286 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
287 err |= __get_user(asi, &sf->v8plus.asi);
288 regs->tstate &= ~TSTATE_ASI;
289 regs->tstate |= ((asi & 0xffUL) << 24UL);
293 /* User can only change condition codes in %tstate. */
294 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
295 regs->tstate |= psr_to_tstate_icc(psr);
297 err |= __get_user(fpu_save, &sf->fpu_save);
299 err |= restore_fpu_state32(regs, &sf->fpu_state);
300 err |= __get_user(seta[0], &sf->info.si_mask);
301 err |= copy_from_user(seta+1, &sf->extramask,
302 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
305 switch (_NSIG_WORDS) {
306 case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32);
307 case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32);
308 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32);
309 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32);
311 sigdelsetmask(&set, ~_BLOCKABLE);
312 spin_lock_irq(¤t->sighand->siglock);
313 current->blocked = set;
315 spin_unlock_irq(¤t->sighand->siglock);
319 force_sig(SIGSEGV, current);
322 asmlinkage void do_sigreturn32(struct pt_regs *regs)
324 struct sigcontext32 __user *scptr;
325 unsigned int pc, npc, psr;
327 unsigned int seta[_COMPAT_NSIG_WORDS];
330 /* Always make any pending restarted system calls return -EINTR */
331 current_thread_info()->restart_block.fn = do_no_restart_syscall;
333 synchronize_user_stack();
334 if (test_thread_flag(TIF_NEWSIGNALS)) {
335 do_new_sigreturn32(regs);
339 scptr = (struct sigcontext32 __user *)
340 (regs->u_regs[UREG_I0] & 0x00000000ffffffffUL);
341 /* Check sanity of the user arg. */
342 if (!access_ok(VERIFY_READ, scptr, sizeof(struct sigcontext32)) ||
343 (((unsigned long) scptr) & 3))
346 err = __get_user(pc, &scptr->sigc_pc);
347 err |= __get_user(npc, &scptr->sigc_npc);
350 goto segv; /* Nice try. */
352 err |= __get_user(seta[0], &scptr->sigc_mask);
353 /* Note that scptr + 1 points to extramask */
354 err |= copy_from_user(seta+1, scptr + 1,
355 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
358 switch (_NSIG_WORDS) {
359 case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32);
360 case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32);
361 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32);
362 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32);
364 sigdelsetmask(&set, ~_BLOCKABLE);
365 spin_lock_irq(¤t->sighand->siglock);
366 current->blocked = set;
368 spin_unlock_irq(¤t->sighand->siglock);
370 if (test_thread_flag(TIF_32BIT)) {
376 err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp);
377 err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0);
378 err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1);
380 /* User can only change condition codes in %tstate. */
381 err |= __get_user(psr, &scptr->sigc_psr);
384 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
385 regs->tstate |= psr_to_tstate_icc(psr);
389 force_sig(SIGSEGV, current);
392 asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
394 struct rt_signal_frame32 __user *sf;
395 unsigned int psr, pc, npc, fpu_save, u_ss_sp;
398 compat_sigset_t seta;
402 /* Always make any pending restarted system calls return -EINTR */
403 current_thread_info()->restart_block.fn = do_no_restart_syscall;
405 synchronize_user_stack();
406 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
407 sf = (struct rt_signal_frame32 __user *) regs->u_regs[UREG_FP];
409 /* 1. Make sure we are not getting garbage from the user */
410 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
411 (((unsigned long) sf) & 3))
414 get_user(pc, &sf->regs.pc);
415 __get_user(npc, &sf->regs.npc);
420 if (test_thread_flag(TIF_32BIT)) {
427 /* 2. Restore the state */
428 err = __get_user(regs->y, &sf->regs.y);
429 err |= __get_user(psr, &sf->regs.psr);
431 for (i = UREG_G1; i <= UREG_I7; i++)
432 err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]);
433 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
434 err |= __get_user(i, &sf->v8plus.g_upper[0]);
435 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
438 for (i = UREG_G1; i <= UREG_I7; i++)
439 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
440 err |= __get_user(asi, &sf->v8plus.asi);
441 regs->tstate &= ~TSTATE_ASI;
442 regs->tstate |= ((asi & 0xffUL) << 24UL);
446 /* User can only change condition codes in %tstate. */
447 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
448 regs->tstate |= psr_to_tstate_icc(psr);
450 err |= __get_user(fpu_save, &sf->fpu_save);
452 err |= restore_fpu_state32(regs, &sf->fpu_state);
453 err |= copy_from_user(&seta, &sf->mask, sizeof(compat_sigset_t));
454 err |= __get_user(u_ss_sp, &sf->stack.ss_sp);
455 st.ss_sp = compat_ptr(u_ss_sp);
456 err |= __get_user(st.ss_flags, &sf->stack.ss_flags);
457 err |= __get_user(st.ss_size, &sf->stack.ss_size);
461 /* It is more difficult to avoid calling this function than to
462 call it and ignore errors. */
465 do_sigaltstack((stack_t __user *) &st, NULL, (unsigned long)sf);
468 switch (_NSIG_WORDS) {
469 case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32);
470 case 3: set.sig[2] = seta.sig[4] + (((long)seta.sig[5]) << 32);
471 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32);
472 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32);
474 sigdelsetmask(&set, ~_BLOCKABLE);
475 spin_lock_irq(¤t->sighand->siglock);
476 current->blocked = set;
478 spin_unlock_irq(¤t->sighand->siglock);
481 force_sig(SIGSEGV, current);
484 /* Checks if the fp is valid */
485 static int invalid_frame_pointer(void __user *fp, int fplen)
487 if ((((unsigned long) fp) & 7) || ((unsigned long)fp) > 0x100000000ULL - fplen)
492 static void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
496 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
497 sp = regs->u_regs[UREG_FP];
499 /* This is the X/Open sanctioned signal stack switching. */
500 if (sa->sa_flags & SA_ONSTACK) {
501 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
502 sp = current->sas_ss_sp + current->sas_ss_size;
504 return (void __user *)(sp - framesize);
508 setup_frame32(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info)
510 struct signal_sframe32 __user *sframep;
511 struct sigcontext32 __user *sc;
512 unsigned int seta[_COMPAT_NSIG_WORDS];
514 void __user *sig_address;
516 unsigned long pc = regs->tpc;
517 unsigned long npc = regs->tnpc;
520 if (test_thread_flag(TIF_32BIT)) {
525 synchronize_user_stack();
526 save_and_clear_fpu();
528 sframep = (struct signal_sframe32 __user *)
529 get_sigframe(sa, regs, SF_ALIGNEDSZ);
530 if (invalid_frame_pointer(sframep, sizeof(*sframep))){
531 /* Don't change signal code and address, so that
532 * post mortem debuggers can have a look.
537 sc = &sframep->sig_context;
539 /* We've already made sure frame pointer isn't in kernel space... */
540 err = __put_user((sas_ss_flags(regs->u_regs[UREG_FP]) == SS_ONSTACK),
543 switch (_NSIG_WORDS) {
544 case 4: seta[7] = (oldset->sig[3] >> 32);
545 seta[6] = oldset->sig[3];
546 case 3: seta[5] = (oldset->sig[2] >> 32);
547 seta[4] = oldset->sig[2];
548 case 2: seta[3] = (oldset->sig[1] >> 32);
549 seta[2] = oldset->sig[1];
550 case 1: seta[1] = (oldset->sig[0] >> 32);
551 seta[0] = oldset->sig[0];
553 err |= __put_user(seta[0], &sc->sigc_mask);
554 err |= __copy_to_user(sframep->extramask, seta + 1,
555 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
556 err |= __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp);
557 err |= __put_user(pc, &sc->sigc_pc);
558 err |= __put_user(npc, &sc->sigc_npc);
559 psr = tstate_to_psr(regs->tstate);
560 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
562 err |= __put_user(psr, &sc->sigc_psr);
563 err |= __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1);
564 err |= __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0);
565 err |= __put_user(get_thread_wsaved(), &sc->sigc_oswins);
567 err |= copy_in_user((u32 __user *)sframep,
568 (u32 __user *)(regs->u_regs[UREG_FP]),
569 sizeof(struct reg_window32));
571 set_thread_wsaved(0); /* So process is allowed to execute. */
572 err |= __put_user(signr, &sframep->sig_num);
575 if (SI_FROMKERNEL (info) && (info->si_code & __SI_MASK) == __SI_FAULT) {
576 sig_address = info->si_addr;
579 switch (info->si_code) {
580 case SEGV_MAPERR: sig_code = SUBSIG_NOMAPPING; break;
581 default: sig_code = SUBSIG_PROTECTION; break;
585 switch (info->si_code) {
586 case ILL_ILLOPC: sig_code = SUBSIG_ILLINST; break;
587 case ILL_PRVOPC: sig_code = SUBSIG_PRIVINST; break;
588 case ILL_ILLTRP: sig_code = SUBSIG_BADTRAP(info->si_trapno); break;
589 default: sig_code = SUBSIG_STACK; break;
593 switch (info->si_code) {
594 case FPE_INTDIV: sig_code = SUBSIG_IDIVZERO; break;
595 case FPE_INTOVF: sig_code = SUBSIG_FPINTOVFL; break;
596 case FPE_FLTDIV: sig_code = SUBSIG_FPDIVZERO; break;
597 case FPE_FLTOVF: sig_code = SUBSIG_FPOVFLOW; break;
598 case FPE_FLTUND: sig_code = SUBSIG_FPUNFLOW; break;
599 case FPE_FLTRES: sig_code = SUBSIG_FPINEXACT; break;
600 case FPE_FLTINV: sig_code = SUBSIG_FPOPERROR; break;
601 default: sig_code = SUBSIG_FPERROR; break;
605 switch (info->si_code) {
606 case BUS_ADRALN: sig_code = SUBSIG_ALIGNMENT; break;
607 case BUS_ADRERR: sig_code = SUBSIG_MISCERROR; break;
608 default: sig_code = SUBSIG_BUSTIMEOUT; break;
612 switch (info->si_code) {
613 case EMT_TAGOVF: sig_code = SUBSIG_TAG; break;
617 if (info->si_code == (__SI_FAULT|0x100)) {
618 /* See sys_sunos32.c */
619 sig_code = info->si_trapno;
626 err |= __put_user(ptr_to_compat(sig_address), &sframep->sig_address);
627 err |= __put_user(sig_code, &sframep->sig_code);
628 err |= __put_user(ptr_to_compat(sc), &sframep->sig_scptr);
632 regs->u_regs[UREG_FP] = (unsigned long) sframep;
633 regs->tpc = (unsigned long) sa->sa_handler;
634 regs->tnpc = (regs->tpc + 4);
635 if (test_thread_flag(TIF_32BIT)) {
636 regs->tpc &= 0xffffffff;
637 regs->tnpc &= 0xffffffff;
642 force_sigsegv(signr, current);
646 static int save_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
648 unsigned long *fpregs = current_thread_info()->fpregs;
652 fprs = current_thread_info()->fpsaved[0];
654 err |= copy_to_user(&fpu->si_float_regs[0], fpregs,
655 (sizeof(unsigned int) * 32));
657 err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16,
658 (sizeof(unsigned int) * 32));
659 err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
660 err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr);
661 err |= __put_user(fprs, &fpu->si_fprs);
666 static void new_setup_frame32(struct k_sigaction *ka, struct pt_regs *regs,
667 int signo, sigset_t *oldset)
669 struct new_signal_frame32 __user *sf;
673 unsigned int seta[_COMPAT_NSIG_WORDS];
675 /* 1. Make sure everything is clean */
676 synchronize_user_stack();
677 save_and_clear_fpu();
679 sigframe_size = NF_ALIGNEDSZ;
680 if (!(current_thread_info()->fpsaved[0] & FPRS_FEF))
681 sigframe_size -= sizeof(__siginfo_fpu_t);
683 sf = (struct new_signal_frame32 __user *)
684 get_sigframe(&ka->sa, regs, sigframe_size);
686 if (invalid_frame_pointer(sf, sigframe_size))
689 if (get_thread_wsaved() != 0)
692 /* 2. Save the current process state */
693 if (test_thread_flag(TIF_32BIT)) {
694 regs->tpc &= 0xffffffff;
695 regs->tnpc &= 0xffffffff;
697 err = put_user(regs->tpc, &sf->info.si_regs.pc);
698 err |= __put_user(regs->tnpc, &sf->info.si_regs.npc);
699 err |= __put_user(regs->y, &sf->info.si_regs.y);
700 psr = tstate_to_psr(regs->tstate);
701 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
703 err |= __put_user(psr, &sf->info.si_regs.psr);
704 for (i = 0; i < 16; i++)
705 err |= __put_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
706 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
707 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
708 for (i = 1; i < 16; i++)
709 err |= __put_user(((u32 *)regs->u_regs)[2*i],
710 &sf->v8plus.g_upper[i]);
711 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
715 err |= save_fpu_state32(regs, &sf->fpu_state);
716 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save);
718 err |= __put_user(0, &sf->fpu_save);
721 switch (_NSIG_WORDS) {
722 case 4: seta[7] = (oldset->sig[3] >> 32);
723 seta[6] = oldset->sig[3];
724 case 3: seta[5] = (oldset->sig[2] >> 32);
725 seta[4] = oldset->sig[2];
726 case 2: seta[3] = (oldset->sig[1] >> 32);
727 seta[2] = oldset->sig[1];
728 case 1: seta[1] = (oldset->sig[0] >> 32);
729 seta[0] = oldset->sig[0];
731 err |= __put_user(seta[0], &sf->info.si_mask);
732 err |= __copy_to_user(sf->extramask, seta + 1,
733 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
735 err |= copy_in_user((u32 __user *)sf,
736 (u32 __user *)(regs->u_regs[UREG_FP]),
737 sizeof(struct reg_window32));
742 /* 3. signal handler back-trampoline and parameters */
743 regs->u_regs[UREG_FP] = (unsigned long) sf;
744 regs->u_regs[UREG_I0] = signo;
745 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
746 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
748 /* 4. signal handler */
749 regs->tpc = (unsigned long) ka->sa.sa_handler;
750 regs->tnpc = (regs->tpc + 4);
751 if (test_thread_flag(TIF_32BIT)) {
752 regs->tpc &= 0xffffffff;
753 regs->tnpc &= 0xffffffff;
756 /* 5. return to kernel instructions */
757 if (ka->ka_restorer) {
758 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
760 /* Flush instruction space. */
761 unsigned long address = ((unsigned long)&(sf->insns[0]));
762 pgd_t *pgdp = pgd_offset(current->mm, address);
763 pud_t *pudp = pud_offset(pgdp, address);
764 pmd_t *pmdp = pmd_offset(pudp, address);
768 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
770 err = __put_user(0x821020d8, &sf->insns[0]); /*mov __NR_sigreturn, %g1*/
771 err |= __put_user(0x91d02010, &sf->insns[1]); /*t 0x10*/
776 ptep = pte_offset_map(pmdp, address);
778 if (pte_present(pte)) {
779 unsigned long page = (unsigned long)
780 page_address(pte_page(pte));
783 __asm__ __volatile__("flush %0 + %1"
786 "r" (address & (PAGE_SIZE - 1))
797 force_sigsegv(signo, current);
800 static void setup_rt_frame32(struct k_sigaction *ka, struct pt_regs *regs,
801 unsigned long signr, sigset_t *oldset,
804 struct rt_signal_frame32 __user *sf;
808 compat_sigset_t seta;
810 /* 1. Make sure everything is clean */
811 synchronize_user_stack();
812 save_and_clear_fpu();
814 sigframe_size = RT_ALIGNEDSZ;
815 if (!(current_thread_info()->fpsaved[0] & FPRS_FEF))
816 sigframe_size -= sizeof(__siginfo_fpu_t);
818 sf = (struct rt_signal_frame32 __user *)
819 get_sigframe(&ka->sa, regs, sigframe_size);
821 if (invalid_frame_pointer(sf, sigframe_size))
824 if (get_thread_wsaved() != 0)
827 /* 2. Save the current process state */
828 if (test_thread_flag(TIF_32BIT)) {
829 regs->tpc &= 0xffffffff;
830 regs->tnpc &= 0xffffffff;
832 err = put_user(regs->tpc, &sf->regs.pc);
833 err |= __put_user(regs->tnpc, &sf->regs.npc);
834 err |= __put_user(regs->y, &sf->regs.y);
835 psr = tstate_to_psr(regs->tstate);
836 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
838 err |= __put_user(psr, &sf->regs.psr);
839 for (i = 0; i < 16; i++)
840 err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]);
841 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
842 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
843 for (i = 1; i < 16; i++)
844 err |= __put_user(((u32 *)regs->u_regs)[2*i],
845 &sf->v8plus.g_upper[i]);
846 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
850 err |= save_fpu_state32(regs, &sf->fpu_state);
851 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save);
853 err |= __put_user(0, &sf->fpu_save);
856 /* Update the siginfo structure. */
857 err |= copy_siginfo_to_user32(&sf->info, info);
859 /* Setup sigaltstack */
860 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
861 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
862 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
864 switch (_NSIG_WORDS) {
865 case 4: seta.sig[7] = (oldset->sig[3] >> 32);
866 seta.sig[6] = oldset->sig[3];
867 case 3: seta.sig[5] = (oldset->sig[2] >> 32);
868 seta.sig[4] = oldset->sig[2];
869 case 2: seta.sig[3] = (oldset->sig[1] >> 32);
870 seta.sig[2] = oldset->sig[1];
871 case 1: seta.sig[1] = (oldset->sig[0] >> 32);
872 seta.sig[0] = oldset->sig[0];
874 err |= __copy_to_user(&sf->mask, &seta, sizeof(compat_sigset_t));
876 err |= copy_in_user((u32 __user *)sf,
877 (u32 __user *)(regs->u_regs[UREG_FP]),
878 sizeof(struct reg_window32));
882 /* 3. signal handler back-trampoline and parameters */
883 regs->u_regs[UREG_FP] = (unsigned long) sf;
884 regs->u_regs[UREG_I0] = signr;
885 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
886 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
888 /* 4. signal handler */
889 regs->tpc = (unsigned long) ka->sa.sa_handler;
890 regs->tnpc = (regs->tpc + 4);
891 if (test_thread_flag(TIF_32BIT)) {
892 regs->tpc &= 0xffffffff;
893 regs->tnpc &= 0xffffffff;
896 /* 5. return to kernel instructions */
898 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
900 /* Flush instruction space. */
901 unsigned long address = ((unsigned long)&(sf->insns[0]));
902 pgd_t *pgdp = pgd_offset(current->mm, address);
903 pud_t *pudp = pud_offset(pgdp, address);
904 pmd_t *pmdp = pmd_offset(pudp, address);
907 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
909 /* mov __NR_rt_sigreturn, %g1 */
910 err |= __put_user(0x82102065, &sf->insns[0]);
913 err |= __put_user(0x91d02010, &sf->insns[1]);
918 ptep = pte_offset_map(pmdp, address);
919 if (pte_present(*ptep)) {
920 unsigned long page = (unsigned long)
921 page_address(pte_page(*ptep));
924 __asm__ __volatile__("flush %0 + %1"
927 "r" (address & (PAGE_SIZE - 1))
938 force_sigsegv(signr, current);
941 static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka,
943 sigset_t *oldset, struct pt_regs *regs)
945 if (ka->sa.sa_flags & SA_SIGINFO)
946 setup_rt_frame32(ka, regs, signr, oldset, info);
947 else if (test_thread_flag(TIF_NEWSIGNALS))
948 new_setup_frame32(ka, regs, signr, oldset);
950 setup_frame32(&ka->sa, regs, signr, oldset, info);
951 spin_lock_irq(¤t->sighand->siglock);
952 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
953 if (!(ka->sa.sa_flags & SA_NOMASK))
954 sigaddset(¤t->blocked,signr);
956 spin_unlock_irq(¤t->sighand->siglock);
959 static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs,
960 struct sigaction *sa)
962 switch (regs->u_regs[UREG_I0]) {
963 case ERESTART_RESTARTBLOCK:
965 no_system_call_restart:
966 regs->u_regs[UREG_I0] = EINTR;
967 regs->tstate |= TSTATE_ICARRY;
970 if (!(sa->sa_flags & SA_RESTART))
971 goto no_system_call_restart;
974 regs->u_regs[UREG_I0] = orig_i0;
980 /* Note that 'init' is a special process: it doesn't get signals it doesn't
981 * want to handle. Thus you cannot kill init even with a SIGKILL even by
984 void do_signal32(sigset_t *oldset, struct pt_regs * regs,
985 unsigned long orig_i0, int restart_syscall)
988 struct signal_deliver_cookie cookie;
989 struct k_sigaction ka;
992 cookie.restart_syscall = restart_syscall;
993 cookie.orig_i0 = orig_i0;
995 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
997 if (cookie.restart_syscall)
998 syscall_restart32(orig_i0, regs, &ka.sa);
999 handle_signal32(signr, &ka, &info, oldset, regs);
1001 /* a signal was successfully delivered; the saved
1002 * sigmask will have been stored in the signal frame,
1003 * and will be restored by sigreturn, so we can simply
1004 * clear the TIF_RESTORE_SIGMASK flag.
1006 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1007 clear_thread_flag(TIF_RESTORE_SIGMASK);
1010 if (cookie.restart_syscall &&
1011 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1012 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1013 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1014 /* replay the system call when we are done */
1015 regs->u_regs[UREG_I0] = cookie.orig_i0;
1019 if (cookie.restart_syscall &&
1020 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1021 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1026 /* if there's no signal to deliver, we just put the saved sigmask
1029 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
1030 clear_thread_flag(TIF_RESTORE_SIGMASK);
1031 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
1040 asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
1042 struct sigstack32 __user *ssptr =
1043 (struct sigstack32 __user *)((unsigned long)(u_ssptr));
1044 struct sigstack32 __user *ossptr =
1045 (struct sigstack32 __user *)((unsigned long)(u_ossptr));
1048 /* First see if old state is wanted. */
1050 if (put_user(current->sas_ss_sp + current->sas_ss_size,
1051 &ossptr->the_stack) ||
1052 __put_user(on_sig_stack(sp), &ossptr->cur_status))
1056 /* Now see if we want to update the new state. */
1060 if (get_user(ss_sp, &ssptr->the_stack))
1063 /* If the current stack was set with sigaltstack, don't
1064 * swap stacks while we are on it.
1067 if (current->sas_ss_sp && on_sig_stack(sp))
1070 /* Since we don't know the extent of the stack, and we don't
1071 * track onstack-ness, but rather calculate it, we must
1072 * presume a size. Ho hum this interface is lossy.
1074 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
1075 current->sas_ss_size = SIGSTKSZ;
1083 asmlinkage long do_sys32_sigaltstack(u32 ussa, u32 uossa, unsigned long sp)
1088 mm_segment_t old_fs;
1089 stack_t32 __user *uss32 = compat_ptr(ussa);
1090 stack_t32 __user *uoss32 = compat_ptr(uossa);
1092 if (ussa && (get_user(u_ss_sp, &uss32->ss_sp) ||
1093 __get_user(uss.ss_flags, &uss32->ss_flags) ||
1094 __get_user(uss.ss_size, &uss32->ss_size)))
1096 uss.ss_sp = compat_ptr(u_ss_sp);
1099 ret = do_sigaltstack(ussa ? (stack_t __user *) &uss : NULL,
1100 uossa ? (stack_t __user *) &uoss : NULL, sp);
1102 if (!ret && uossa && (put_user(ptr_to_compat(uoss.ss_sp), &uoss32->ss_sp) ||
1103 __put_user(uoss.ss_flags, &uoss32->ss_flags) ||
1104 __put_user(uoss.ss_size, &uoss32->ss_size)))