1 /* arch/sparc64/kernel/signal32.c
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
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/binfmts.h>
20 #include <linux/compat.h>
21 #include <linux/bitops.h>
22 #include <linux/tracehook.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 /* This magic should be in g_upper[0] for all upper parts
37 #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269
39 unsigned int g_upper
[8];
40 unsigned int o_upper
[8];
42 } siginfo_extra_v8plus_t
;
44 struct signal_frame32
{
45 struct sparc_stackf32 ss
;
47 /* __siginfo_fpu32_t * */ u32 fpu_save
;
48 unsigned int insns
[2];
49 unsigned int extramask
[_COMPAT_NSIG_WORDS
- 1];
50 unsigned int extra_size
; /* Should be sizeof(siginfo_extra_v8plus_t) */
51 /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
52 siginfo_extra_v8plus_t v8plus
;
53 __siginfo_fpu_t fpu_state
;
56 typedef struct compat_siginfo
{
62 int _pad
[SI_PAD_SIZE32
];
66 compat_pid_t _pid
; /* sender's pid */
67 unsigned int _uid
; /* sender's uid */
72 compat_timer_t _tid
; /* timer id */
73 int _overrun
; /* overrun count */
74 compat_sigval_t _sigval
; /* same as below */
75 int _sys_private
; /* not to be passed to user */
78 /* POSIX.1b signals */
80 compat_pid_t _pid
; /* sender's pid */
81 unsigned int _uid
; /* sender's uid */
82 compat_sigval_t _sigval
;
87 compat_pid_t _pid
; /* which child */
88 unsigned int _uid
; /* sender's uid */
89 int _status
; /* exit code */
90 compat_clock_t _utime
;
91 compat_clock_t _stime
;
94 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */
96 u32 _addr
; /* faulting insn/memory ref. */
102 int _band
; /* POLL_IN, POLL_OUT, POLL_MSG */
108 struct rt_signal_frame32
{
109 struct sparc_stackf32 ss
;
110 compat_siginfo_t info
;
111 struct pt_regs32 regs
;
112 compat_sigset_t mask
;
113 /* __siginfo_fpu32_t * */ u32 fpu_save
;
114 unsigned int insns
[2];
116 unsigned int extra_size
; /* Should be sizeof(siginfo_extra_v8plus_t) */
117 /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
118 siginfo_extra_v8plus_t v8plus
;
119 __siginfo_fpu_t fpu_state
;
123 #define SF_ALIGNEDSZ (((sizeof(struct signal_frame32) + 15) & (~15)))
124 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame32) + 15) & (~15)))
126 int copy_siginfo_to_user32(compat_siginfo_t __user
*to
, siginfo_t
*from
)
130 if (!access_ok(VERIFY_WRITE
, to
, sizeof(compat_siginfo_t
)))
133 /* If you change siginfo_t structure, please be sure
134 this code is fixed accordingly.
135 It should never copy any pad contained in the structure
136 to avoid security leaks, but must copy the generic
137 3 ints plus the relevant union member.
138 This routine must convert siginfo from 64bit to 32bit as well
140 err
= __put_user(from
->si_signo
, &to
->si_signo
);
141 err
|= __put_user(from
->si_errno
, &to
->si_errno
);
142 err
|= __put_user((short)from
->si_code
, &to
->si_code
);
143 if (from
->si_code
< 0)
144 err
|= __copy_to_user(&to
->_sifields
._pad
, &from
->_sifields
._pad
, SI_PAD_SIZE
);
146 switch (from
->si_code
>> 16) {
147 case __SI_TIMER
>> 16:
148 err
|= __put_user(from
->si_tid
, &to
->si_tid
);
149 err
|= __put_user(from
->si_overrun
, &to
->si_overrun
);
150 err
|= __put_user(from
->si_int
, &to
->si_int
);
152 case __SI_CHLD
>> 16:
153 err
|= __put_user(from
->si_utime
, &to
->si_utime
);
154 err
|= __put_user(from
->si_stime
, &to
->si_stime
);
155 err
|= __put_user(from
->si_status
, &to
->si_status
);
157 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
158 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
160 case __SI_FAULT
>> 16:
161 err
|= __put_user(from
->si_trapno
, &to
->si_trapno
);
162 err
|= __put_user((unsigned long)from
->si_addr
, &to
->si_addr
);
164 case __SI_POLL
>> 16:
165 err
|= __put_user(from
->si_band
, &to
->si_band
);
166 err
|= __put_user(from
->si_fd
, &to
->si_fd
);
168 case __SI_RT
>> 16: /* This is not generated by the kernel as of now. */
169 case __SI_MESGQ
>> 16:
170 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
171 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
172 err
|= __put_user(from
->si_int
, &to
->si_int
);
179 /* CAUTION: This is just a very minimalist implementation for the
180 * sake of compat_sys_rt_sigqueueinfo()
182 int copy_siginfo_from_user32(siginfo_t
*to
, compat_siginfo_t __user
*from
)
184 if (!access_ok(VERIFY_WRITE
, from
, sizeof(compat_siginfo_t
)))
187 if (copy_from_user(to
, from
, 3*sizeof(int)) ||
188 copy_from_user(to
->_sifields
._pad
, from
->_sifields
._pad
,
195 static int restore_fpu_state32(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
197 unsigned long *fpregs
= current_thread_info()->fpregs
;
201 err
= __get_user(fprs
, &fpu
->si_fprs
);
203 regs
->tstate
&= ~TSTATE_PEF
;
205 err
|= copy_from_user(fpregs
, &fpu
->si_float_regs
[0], (sizeof(unsigned int) * 32));
207 err
|= copy_from_user(fpregs
+16, &fpu
->si_float_regs
[32], (sizeof(unsigned int) * 32));
208 err
|= __get_user(current_thread_info()->xfsr
[0], &fpu
->si_fsr
);
209 err
|= __get_user(current_thread_info()->gsr
[0], &fpu
->si_gsr
);
210 current_thread_info()->fpsaved
[0] |= fprs
;
214 void do_sigreturn32(struct pt_regs
*regs
)
216 struct signal_frame32 __user
*sf
;
218 unsigned pc
, npc
, fpu_save
;
220 unsigned seta
[_COMPAT_NSIG_WORDS
];
223 /* Always make any pending restarted system calls return -EINTR */
224 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
226 synchronize_user_stack();
228 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
229 sf
= (struct signal_frame32 __user
*) regs
->u_regs
[UREG_FP
];
231 /* 1. Make sure we are not getting garbage from the user */
232 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)) ||
233 (((unsigned long) sf
) & 3))
236 get_user(pc
, &sf
->info
.si_regs
.pc
);
237 __get_user(npc
, &sf
->info
.si_regs
.npc
);
242 if (test_thread_flag(TIF_32BIT
)) {
249 /* 2. Restore the state */
250 err
= __get_user(regs
->y
, &sf
->info
.si_regs
.y
);
251 err
|= __get_user(psr
, &sf
->info
.si_regs
.psr
);
253 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
254 err
|= __get_user(regs
->u_regs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
255 if ((psr
& (PSR_VERS
|PSR_IMPL
)) == PSR_V8PLUS
) {
256 err
|= __get_user(i
, &sf
->v8plus
.g_upper
[0]);
257 if (i
== SIGINFO_EXTRA_V8PLUS_MAGIC
) {
260 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
261 err
|= __get_user(((u32
*)regs
->u_regs
)[2*i
], &sf
->v8plus
.g_upper
[i
]);
262 err
|= __get_user(asi
, &sf
->v8plus
.asi
);
263 regs
->tstate
&= ~TSTATE_ASI
;
264 regs
->tstate
|= ((asi
& 0xffUL
) << 24UL);
268 /* User can only change condition codes in %tstate. */
269 regs
->tstate
&= ~(TSTATE_ICC
|TSTATE_XCC
);
270 regs
->tstate
|= psr_to_tstate_icc(psr
);
272 /* Prevent syscall restart. */
273 pt_regs_clear_syscall(regs
);
275 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
277 err
|= restore_fpu_state32(regs
, &sf
->fpu_state
);
278 err
|= __get_user(seta
[0], &sf
->info
.si_mask
);
279 err
|= copy_from_user(seta
+1, &sf
->extramask
,
280 (_COMPAT_NSIG_WORDS
- 1) * sizeof(unsigned int));
283 switch (_NSIG_WORDS
) {
284 case 4: set
.sig
[3] = seta
[6] + (((long)seta
[7]) << 32);
285 case 3: set
.sig
[2] = seta
[4] + (((long)seta
[5]) << 32);
286 case 2: set
.sig
[1] = seta
[2] + (((long)seta
[3]) << 32);
287 case 1: set
.sig
[0] = seta
[0] + (((long)seta
[1]) << 32);
289 sigdelsetmask(&set
, ~_BLOCKABLE
);
290 spin_lock_irq(¤t
->sighand
->siglock
);
291 current
->blocked
= set
;
293 spin_unlock_irq(¤t
->sighand
->siglock
);
297 force_sig(SIGSEGV
, current
);
300 asmlinkage
void do_rt_sigreturn32(struct pt_regs
*regs
)
302 struct rt_signal_frame32 __user
*sf
;
303 unsigned int psr
, pc
, npc
, fpu_save
, u_ss_sp
;
306 compat_sigset_t seta
;
310 /* Always make any pending restarted system calls return -EINTR */
311 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
313 synchronize_user_stack();
314 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
315 sf
= (struct rt_signal_frame32 __user
*) regs
->u_regs
[UREG_FP
];
317 /* 1. Make sure we are not getting garbage from the user */
318 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)) ||
319 (((unsigned long) sf
) & 3))
322 get_user(pc
, &sf
->regs
.pc
);
323 __get_user(npc
, &sf
->regs
.npc
);
328 if (test_thread_flag(TIF_32BIT
)) {
335 /* 2. Restore the state */
336 err
= __get_user(regs
->y
, &sf
->regs
.y
);
337 err
|= __get_user(psr
, &sf
->regs
.psr
);
339 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
340 err
|= __get_user(regs
->u_regs
[i
], &sf
->regs
.u_regs
[i
]);
341 if ((psr
& (PSR_VERS
|PSR_IMPL
)) == PSR_V8PLUS
) {
342 err
|= __get_user(i
, &sf
->v8plus
.g_upper
[0]);
343 if (i
== SIGINFO_EXTRA_V8PLUS_MAGIC
) {
346 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
347 err
|= __get_user(((u32
*)regs
->u_regs
)[2*i
], &sf
->v8plus
.g_upper
[i
]);
348 err
|= __get_user(asi
, &sf
->v8plus
.asi
);
349 regs
->tstate
&= ~TSTATE_ASI
;
350 regs
->tstate
|= ((asi
& 0xffUL
) << 24UL);
354 /* User can only change condition codes in %tstate. */
355 regs
->tstate
&= ~(TSTATE_ICC
|TSTATE_XCC
);
356 regs
->tstate
|= psr_to_tstate_icc(psr
);
358 /* Prevent syscall restart. */
359 pt_regs_clear_syscall(regs
);
361 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
363 err
|= restore_fpu_state32(regs
, &sf
->fpu_state
);
364 err
|= copy_from_user(&seta
, &sf
->mask
, sizeof(compat_sigset_t
));
365 err
|= __get_user(u_ss_sp
, &sf
->stack
.ss_sp
);
366 st
.ss_sp
= compat_ptr(u_ss_sp
);
367 err
|= __get_user(st
.ss_flags
, &sf
->stack
.ss_flags
);
368 err
|= __get_user(st
.ss_size
, &sf
->stack
.ss_size
);
372 /* It is more difficult to avoid calling this function than to
373 call it and ignore errors. */
376 do_sigaltstack((stack_t __user
*) &st
, NULL
, (unsigned long)sf
);
379 switch (_NSIG_WORDS
) {
380 case 4: set
.sig
[3] = seta
.sig
[6] + (((long)seta
.sig
[7]) << 32);
381 case 3: set
.sig
[2] = seta
.sig
[4] + (((long)seta
.sig
[5]) << 32);
382 case 2: set
.sig
[1] = seta
.sig
[2] + (((long)seta
.sig
[3]) << 32);
383 case 1: set
.sig
[0] = seta
.sig
[0] + (((long)seta
.sig
[1]) << 32);
385 sigdelsetmask(&set
, ~_BLOCKABLE
);
386 spin_lock_irq(¤t
->sighand
->siglock
);
387 current
->blocked
= set
;
389 spin_unlock_irq(¤t
->sighand
->siglock
);
392 force_sig(SIGSEGV
, current
);
395 /* Checks if the fp is valid */
396 static int invalid_frame_pointer(void __user
*fp
, int fplen
)
398 if ((((unsigned long) fp
) & 7) || ((unsigned long)fp
) > 0x100000000ULL
- fplen
)
403 static void __user
*get_sigframe(struct sigaction
*sa
, struct pt_regs
*regs
, unsigned long framesize
)
407 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
408 sp
= regs
->u_regs
[UREG_FP
];
411 * If we are on the alternate signal stack and would overflow it, don't.
412 * Return an always-bogus address instead so we will die with SIGSEGV.
414 if (on_sig_stack(sp
) && !likely(on_sig_stack(sp
- framesize
)))
415 return (void __user
*) -1L;
417 /* This is the X/Open sanctioned signal stack switching. */
418 if (sa
->sa_flags
& SA_ONSTACK
) {
419 if (sas_ss_flags(sp
) == 0)
420 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
425 /* Always align the stack frame. This handles two cases. First,
426 * sigaltstack need not be mindful of platform specific stack
427 * alignment. Second, if we took this signal because the stack
428 * is not aligned properly, we'd like to take the signal cleanly
433 return (void __user
*) sp
;
436 static int save_fpu_state32(struct pt_regs
*regs
, __siginfo_fpu_t __user
*fpu
)
438 unsigned long *fpregs
= current_thread_info()->fpregs
;
442 fprs
= current_thread_info()->fpsaved
[0];
444 err
|= copy_to_user(&fpu
->si_float_regs
[0], fpregs
,
445 (sizeof(unsigned int) * 32));
447 err
|= copy_to_user(&fpu
->si_float_regs
[32], fpregs
+16,
448 (sizeof(unsigned int) * 32));
449 err
|= __put_user(current_thread_info()->xfsr
[0], &fpu
->si_fsr
);
450 err
|= __put_user(current_thread_info()->gsr
[0], &fpu
->si_gsr
);
451 err
|= __put_user(fprs
, &fpu
->si_fprs
);
456 /* The I-cache flush instruction only works in the primary ASI, which
457 * right now is the nucleus, aka. kernel space.
459 * Therefore we have to kick the instructions out using the kernel
460 * side linear mapping of the physical address backing the user
463 static void flush_signal_insns(unsigned long address
)
465 unsigned long pstate
, paddr
;
471 /* Commit all stores of the instructions we are about to flush. */
474 /* Disable cross-call reception. In this way even a very wide
475 * munmap() on another cpu can't tear down the page table
476 * hierarchy from underneath us, since that can't complete
477 * until the IPI tlb flush returns.
480 __asm__
__volatile__("rdpr %%pstate, %0" : "=r" (pstate
));
481 __asm__
__volatile__("wrpr %0, %1, %%pstate"
482 : : "r" (pstate
), "i" (PSTATE_IE
));
484 pgdp
= pgd_offset(current
->mm
, address
);
487 pudp
= pud_offset(pgdp
, address
);
490 pmdp
= pmd_offset(pudp
, address
);
494 ptep
= pte_offset_map(pmdp
, address
);
496 if (!pte_present(pte
))
499 paddr
= (unsigned long) page_address(pte_page(pte
));
501 __asm__
__volatile__("flush %0 + %1"
504 "r" (address
& (PAGE_SIZE
- 1))
510 __asm__
__volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate
));
514 static int setup_frame32(struct k_sigaction
*ka
, struct pt_regs
*regs
,
515 int signo
, sigset_t
*oldset
)
517 struct signal_frame32 __user
*sf
;
521 unsigned int seta
[_COMPAT_NSIG_WORDS
];
523 /* 1. Make sure everything is clean */
524 synchronize_user_stack();
525 save_and_clear_fpu();
527 sigframe_size
= SF_ALIGNEDSZ
;
528 if (!(current_thread_info()->fpsaved
[0] & FPRS_FEF
))
529 sigframe_size
-= sizeof(__siginfo_fpu_t
);
531 sf
= (struct signal_frame32 __user
*)
532 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
534 if (invalid_frame_pointer(sf
, sigframe_size
))
537 if (get_thread_wsaved() != 0)
540 /* 2. Save the current process state */
541 if (test_thread_flag(TIF_32BIT
)) {
542 regs
->tpc
&= 0xffffffff;
543 regs
->tnpc
&= 0xffffffff;
545 err
= put_user(regs
->tpc
, &sf
->info
.si_regs
.pc
);
546 err
|= __put_user(regs
->tnpc
, &sf
->info
.si_regs
.npc
);
547 err
|= __put_user(regs
->y
, &sf
->info
.si_regs
.y
);
548 psr
= tstate_to_psr(regs
->tstate
);
549 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
551 err
|= __put_user(psr
, &sf
->info
.si_regs
.psr
);
552 for (i
= 0; i
< 16; i
++)
553 err
|= __put_user(regs
->u_regs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
554 err
|= __put_user(sizeof(siginfo_extra_v8plus_t
), &sf
->extra_size
);
555 err
|= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC
, &sf
->v8plus
.g_upper
[0]);
556 for (i
= 1; i
< 16; i
++)
557 err
|= __put_user(((u32
*)regs
->u_regs
)[2*i
],
558 &sf
->v8plus
.g_upper
[i
]);
559 err
|= __put_user((regs
->tstate
& TSTATE_ASI
) >> 24UL,
563 err
|= save_fpu_state32(regs
, &sf
->fpu_state
);
564 err
|= __put_user((u64
)&sf
->fpu_state
, &sf
->fpu_save
);
566 err
|= __put_user(0, &sf
->fpu_save
);
569 switch (_NSIG_WORDS
) {
570 case 4: seta
[7] = (oldset
->sig
[3] >> 32);
571 seta
[6] = oldset
->sig
[3];
572 case 3: seta
[5] = (oldset
->sig
[2] >> 32);
573 seta
[4] = oldset
->sig
[2];
574 case 2: seta
[3] = (oldset
->sig
[1] >> 32);
575 seta
[2] = oldset
->sig
[1];
576 case 1: seta
[1] = (oldset
->sig
[0] >> 32);
577 seta
[0] = oldset
->sig
[0];
579 err
|= __put_user(seta
[0], &sf
->info
.si_mask
);
580 err
|= __copy_to_user(sf
->extramask
, seta
+ 1,
581 (_COMPAT_NSIG_WORDS
- 1) * sizeof(unsigned int));
583 err
|= copy_in_user((u32 __user
*)sf
,
584 (u32 __user
*)(regs
->u_regs
[UREG_FP
]),
585 sizeof(struct reg_window32
));
590 /* 3. signal handler back-trampoline and parameters */
591 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
592 regs
->u_regs
[UREG_I0
] = signo
;
593 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
594 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->info
;
596 /* 4. signal handler */
597 regs
->tpc
= (unsigned long) ka
->sa
.sa_handler
;
598 regs
->tnpc
= (regs
->tpc
+ 4);
599 if (test_thread_flag(TIF_32BIT
)) {
600 regs
->tpc
&= 0xffffffff;
601 regs
->tnpc
&= 0xffffffff;
604 /* 5. return to kernel instructions */
605 if (ka
->ka_restorer
) {
606 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
608 unsigned long address
= ((unsigned long)&(sf
->insns
[0]));
610 regs
->u_regs
[UREG_I7
] = (unsigned long) (&(sf
->insns
[0]) - 2);
612 err
= __put_user(0x821020d8, &sf
->insns
[0]); /*mov __NR_sigreturn, %g1*/
613 err
|= __put_user(0x91d02010, &sf
->insns
[1]); /*t 0x10*/
617 flush_signal_insns(address
);
626 force_sigsegv(signo
, current
);
630 static int setup_rt_frame32(struct k_sigaction
*ka
, struct pt_regs
*regs
,
631 unsigned long signr
, sigset_t
*oldset
,
634 struct rt_signal_frame32 __user
*sf
;
638 compat_sigset_t seta
;
640 /* 1. Make sure everything is clean */
641 synchronize_user_stack();
642 save_and_clear_fpu();
644 sigframe_size
= RT_ALIGNEDSZ
;
645 if (!(current_thread_info()->fpsaved
[0] & FPRS_FEF
))
646 sigframe_size
-= sizeof(__siginfo_fpu_t
);
648 sf
= (struct rt_signal_frame32 __user
*)
649 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
651 if (invalid_frame_pointer(sf
, sigframe_size
))
654 if (get_thread_wsaved() != 0)
657 /* 2. Save the current process state */
658 if (test_thread_flag(TIF_32BIT
)) {
659 regs
->tpc
&= 0xffffffff;
660 regs
->tnpc
&= 0xffffffff;
662 err
= put_user(regs
->tpc
, &sf
->regs
.pc
);
663 err
|= __put_user(regs
->tnpc
, &sf
->regs
.npc
);
664 err
|= __put_user(regs
->y
, &sf
->regs
.y
);
665 psr
= tstate_to_psr(regs
->tstate
);
666 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
668 err
|= __put_user(psr
, &sf
->regs
.psr
);
669 for (i
= 0; i
< 16; i
++)
670 err
|= __put_user(regs
->u_regs
[i
], &sf
->regs
.u_regs
[i
]);
671 err
|= __put_user(sizeof(siginfo_extra_v8plus_t
), &sf
->extra_size
);
672 err
|= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC
, &sf
->v8plus
.g_upper
[0]);
673 for (i
= 1; i
< 16; i
++)
674 err
|= __put_user(((u32
*)regs
->u_regs
)[2*i
],
675 &sf
->v8plus
.g_upper
[i
]);
676 err
|= __put_user((regs
->tstate
& TSTATE_ASI
) >> 24UL,
680 err
|= save_fpu_state32(regs
, &sf
->fpu_state
);
681 err
|= __put_user((u64
)&sf
->fpu_state
, &sf
->fpu_save
);
683 err
|= __put_user(0, &sf
->fpu_save
);
686 /* Update the siginfo structure. */
687 err
|= copy_siginfo_to_user32(&sf
->info
, info
);
689 /* Setup sigaltstack */
690 err
|= __put_user(current
->sas_ss_sp
, &sf
->stack
.ss_sp
);
691 err
|= __put_user(sas_ss_flags(regs
->u_regs
[UREG_FP
]), &sf
->stack
.ss_flags
);
692 err
|= __put_user(current
->sas_ss_size
, &sf
->stack
.ss_size
);
694 switch (_NSIG_WORDS
) {
695 case 4: seta
.sig
[7] = (oldset
->sig
[3] >> 32);
696 seta
.sig
[6] = oldset
->sig
[3];
697 case 3: seta
.sig
[5] = (oldset
->sig
[2] >> 32);
698 seta
.sig
[4] = oldset
->sig
[2];
699 case 2: seta
.sig
[3] = (oldset
->sig
[1] >> 32);
700 seta
.sig
[2] = oldset
->sig
[1];
701 case 1: seta
.sig
[1] = (oldset
->sig
[0] >> 32);
702 seta
.sig
[0] = oldset
->sig
[0];
704 err
|= __copy_to_user(&sf
->mask
, &seta
, sizeof(compat_sigset_t
));
706 err
|= copy_in_user((u32 __user
*)sf
,
707 (u32 __user
*)(regs
->u_regs
[UREG_FP
]),
708 sizeof(struct reg_window32
));
712 /* 3. signal handler back-trampoline and parameters */
713 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
714 regs
->u_regs
[UREG_I0
] = signr
;
715 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
716 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->regs
;
718 /* 4. signal handler */
719 regs
->tpc
= (unsigned long) ka
->sa
.sa_handler
;
720 regs
->tnpc
= (regs
->tpc
+ 4);
721 if (test_thread_flag(TIF_32BIT
)) {
722 regs
->tpc
&= 0xffffffff;
723 regs
->tnpc
&= 0xffffffff;
726 /* 5. return to kernel instructions */
728 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
730 unsigned long address
= ((unsigned long)&(sf
->insns
[0]));
732 regs
->u_regs
[UREG_I7
] = (unsigned long) (&(sf
->insns
[0]) - 2);
734 /* mov __NR_rt_sigreturn, %g1 */
735 err
|= __put_user(0x82102065, &sf
->insns
[0]);
738 err
|= __put_user(0x91d02010, &sf
->insns
[1]);
742 flush_signal_insns(address
);
751 force_sigsegv(signr
, current
);
755 static inline int handle_signal32(unsigned long signr
, struct k_sigaction
*ka
,
757 sigset_t
*oldset
, struct pt_regs
*regs
)
761 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
762 err
= setup_rt_frame32(ka
, regs
, signr
, oldset
, info
);
764 err
= setup_frame32(ka
, regs
, signr
, oldset
);
769 spin_lock_irq(¤t
->sighand
->siglock
);
770 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
771 if (!(ka
->sa
.sa_flags
& SA_NOMASK
))
772 sigaddset(¤t
->blocked
,signr
);
774 spin_unlock_irq(¤t
->sighand
->siglock
);
776 tracehook_signal_handler(signr
, info
, ka
, regs
, 0);
781 static inline void syscall_restart32(unsigned long orig_i0
, struct pt_regs
*regs
,
782 struct sigaction
*sa
)
784 switch (regs
->u_regs
[UREG_I0
]) {
785 case ERESTART_RESTARTBLOCK
:
787 no_system_call_restart
:
788 regs
->u_regs
[UREG_I0
] = EINTR
;
789 regs
->tstate
|= TSTATE_ICARRY
;
792 if (!(sa
->sa_flags
& SA_RESTART
))
793 goto no_system_call_restart
;
796 regs
->u_regs
[UREG_I0
] = orig_i0
;
802 /* Note that 'init' is a special process: it doesn't get signals it doesn't
803 * want to handle. Thus you cannot kill init even with a SIGKILL even by
806 void do_signal32(sigset_t
*oldset
, struct pt_regs
* regs
,
807 int restart_syscall
, unsigned long orig_i0
)
809 struct k_sigaction ka
;
813 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
815 /* If the debugger messes with the program counter, it clears
816 * the "in syscall" bit, directing us to not perform a syscall
819 if (restart_syscall
&& !pt_regs_is_syscall(regs
))
824 syscall_restart32(orig_i0
, regs
, &ka
.sa
);
825 if (handle_signal32(signr
, &ka
, &info
, oldset
, regs
) == 0) {
826 /* A signal was successfully delivered; the saved
827 * sigmask will have been stored in the signal frame,
828 * and will be restored by sigreturn, so we can simply
829 * clear the TS_RESTORE_SIGMASK flag.
831 current_thread_info()->status
&= ~TS_RESTORE_SIGMASK
;
835 if (restart_syscall
&&
836 (regs
->u_regs
[UREG_I0
] == ERESTARTNOHAND
||
837 regs
->u_regs
[UREG_I0
] == ERESTARTSYS
||
838 regs
->u_regs
[UREG_I0
] == ERESTARTNOINTR
)) {
839 /* replay the system call when we are done */
840 regs
->u_regs
[UREG_I0
] = orig_i0
;
843 pt_regs_clear_syscall(regs
);
845 if (restart_syscall
&&
846 regs
->u_regs
[UREG_I0
] == ERESTART_RESTARTBLOCK
) {
847 regs
->u_regs
[UREG_G1
] = __NR_restart_syscall
;
850 pt_regs_clear_syscall(regs
);
853 /* If there's no signal to deliver, we just put the saved sigmask
856 if (current_thread_info()->status
& TS_RESTORE_SIGMASK
) {
857 current_thread_info()->status
&= ~TS_RESTORE_SIGMASK
;
858 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
867 asmlinkage
int do_sys32_sigstack(u32 u_ssptr
, u32 u_ossptr
, unsigned long sp
)
869 struct sigstack32 __user
*ssptr
=
870 (struct sigstack32 __user
*)((unsigned long)(u_ssptr
));
871 struct sigstack32 __user
*ossptr
=
872 (struct sigstack32 __user
*)((unsigned long)(u_ossptr
));
875 /* First see if old state is wanted. */
877 if (put_user(current
->sas_ss_sp
+ current
->sas_ss_size
,
878 &ossptr
->the_stack
) ||
879 __put_user(on_sig_stack(sp
), &ossptr
->cur_status
))
883 /* Now see if we want to update the new state. */
887 if (get_user(ss_sp
, &ssptr
->the_stack
))
890 /* If the current stack was set with sigaltstack, don't
891 * swap stacks while we are on it.
894 if (current
->sas_ss_sp
&& on_sig_stack(sp
))
897 /* Since we don't know the extent of the stack, and we don't
898 * track onstack-ness, but rather calculate it, we must
899 * presume a size. Ho hum this interface is lossy.
901 current
->sas_ss_sp
= (unsigned long)ss_sp
- SIGSTKSZ
;
902 current
->sas_ss_size
= SIGSTKSZ
;
910 asmlinkage
long do_sys32_sigaltstack(u32 ussa
, u32 uossa
, unsigned long sp
)
916 stack_t32 __user
*uss32
= compat_ptr(ussa
);
917 stack_t32 __user
*uoss32
= compat_ptr(uossa
);
919 if (ussa
&& (get_user(u_ss_sp
, &uss32
->ss_sp
) ||
920 __get_user(uss
.ss_flags
, &uss32
->ss_flags
) ||
921 __get_user(uss
.ss_size
, &uss32
->ss_size
)))
923 uss
.ss_sp
= compat_ptr(u_ss_sp
);
926 ret
= do_sigaltstack(ussa
? (stack_t __user
*) &uss
: NULL
,
927 uossa
? (stack_t __user
*) &uoss
: NULL
, sp
);
929 if (!ret
&& uossa
&& (put_user(ptr_to_compat(uoss
.ss_sp
), &uoss32
->ss_sp
) ||
930 __put_user(uoss
.ss_flags
, &uoss32
->ss_flags
) ||
931 __put_user(uoss
.ss_size
, &uoss32
->ss_size
)))