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>
34 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36 /* This magic should be in g_upper[0] for all upper parts
39 #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269
41 unsigned int g_upper
[8];
42 unsigned int o_upper
[8];
44 } siginfo_extra_v8plus_t
;
46 struct signal_frame32
{
47 struct sparc_stackf32 ss
;
49 /* __siginfo_fpu_t * */ u32 fpu_save
;
50 unsigned int insns
[2];
51 unsigned int extramask
[_COMPAT_NSIG_WORDS
- 1];
52 unsigned int extra_size
; /* Should be sizeof(siginfo_extra_v8plus_t) */
53 /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
54 siginfo_extra_v8plus_t v8plus
;
55 /* __siginfo_rwin_t * */u32 rwin_save
;
56 } __attribute__((aligned(8)));
58 typedef struct compat_siginfo
{
64 int _pad
[SI_PAD_SIZE32
];
68 compat_pid_t _pid
; /* sender's pid */
69 unsigned int _uid
; /* sender's uid */
74 compat_timer_t _tid
; /* timer id */
75 int _overrun
; /* overrun count */
76 compat_sigval_t _sigval
; /* same as below */
77 int _sys_private
; /* not to be passed to user */
80 /* POSIX.1b signals */
82 compat_pid_t _pid
; /* sender's pid */
83 unsigned int _uid
; /* sender's uid */
84 compat_sigval_t _sigval
;
89 compat_pid_t _pid
; /* which child */
90 unsigned int _uid
; /* sender's uid */
91 int _status
; /* exit code */
92 compat_clock_t _utime
;
93 compat_clock_t _stime
;
96 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */
98 u32 _addr
; /* faulting insn/memory ref. */
104 int _band
; /* POLL_IN, POLL_OUT, POLL_MSG */
110 struct rt_signal_frame32
{
111 struct sparc_stackf32 ss
;
112 compat_siginfo_t info
;
113 struct pt_regs32 regs
;
114 compat_sigset_t mask
;
115 /* __siginfo_fpu_t * */ u32 fpu_save
;
116 unsigned int insns
[2];
118 unsigned int extra_size
; /* Should be sizeof(siginfo_extra_v8plus_t) */
119 /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
120 siginfo_extra_v8plus_t v8plus
;
121 /* __siginfo_rwin_t * */u32 rwin_save
;
122 } __attribute__((aligned(8)));
124 int copy_siginfo_to_user32(compat_siginfo_t __user
*to
, siginfo_t
*from
)
128 if (!access_ok(VERIFY_WRITE
, to
, sizeof(compat_siginfo_t
)))
131 /* If you change siginfo_t structure, please be sure
132 this code is fixed accordingly.
133 It should never copy any pad contained in the structure
134 to avoid security leaks, but must copy the generic
135 3 ints plus the relevant union member.
136 This routine must convert siginfo from 64bit to 32bit as well
138 err
= __put_user(from
->si_signo
, &to
->si_signo
);
139 err
|= __put_user(from
->si_errno
, &to
->si_errno
);
140 err
|= __put_user((short)from
->si_code
, &to
->si_code
);
141 if (from
->si_code
< 0)
142 err
|= __copy_to_user(&to
->_sifields
._pad
, &from
->_sifields
._pad
, SI_PAD_SIZE
);
144 switch (from
->si_code
>> 16) {
145 case __SI_TIMER
>> 16:
146 err
|= __put_user(from
->si_tid
, &to
->si_tid
);
147 err
|= __put_user(from
->si_overrun
, &to
->si_overrun
);
148 err
|= __put_user(from
->si_int
, &to
->si_int
);
150 case __SI_CHLD
>> 16:
151 err
|= __put_user(from
->si_utime
, &to
->si_utime
);
152 err
|= __put_user(from
->si_stime
, &to
->si_stime
);
153 err
|= __put_user(from
->si_status
, &to
->si_status
);
155 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
156 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
158 case __SI_FAULT
>> 16:
159 err
|= __put_user(from
->si_trapno
, &to
->si_trapno
);
160 err
|= __put_user((unsigned long)from
->si_addr
, &to
->si_addr
);
162 case __SI_POLL
>> 16:
163 err
|= __put_user(from
->si_band
, &to
->si_band
);
164 err
|= __put_user(from
->si_fd
, &to
->si_fd
);
166 case __SI_RT
>> 16: /* This is not generated by the kernel as of now. */
167 case __SI_MESGQ
>> 16:
168 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
169 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
170 err
|= __put_user(from
->si_int
, &to
->si_int
);
177 /* CAUTION: This is just a very minimalist implementation for the
178 * sake of compat_sys_rt_sigqueueinfo()
180 int copy_siginfo_from_user32(siginfo_t
*to
, compat_siginfo_t __user
*from
)
182 if (!access_ok(VERIFY_WRITE
, from
, sizeof(compat_siginfo_t
)))
185 if (copy_from_user(to
, from
, 3*sizeof(int)) ||
186 copy_from_user(to
->_sifields
._pad
, from
->_sifields
._pad
,
193 void do_sigreturn32(struct pt_regs
*regs
)
195 struct signal_frame32 __user
*sf
;
196 compat_uptr_t fpu_save
;
197 compat_uptr_t rwin_save
;
201 unsigned seta
[_COMPAT_NSIG_WORDS
];
204 /* Always make any pending restarted system calls return -EINTR */
205 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
207 synchronize_user_stack();
209 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
210 sf
= (struct signal_frame32 __user
*) regs
->u_regs
[UREG_FP
];
212 /* 1. Make sure we are not getting garbage from the user */
213 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)) ||
214 (((unsigned long) sf
) & 3))
217 get_user(pc
, &sf
->info
.si_regs
.pc
);
218 __get_user(npc
, &sf
->info
.si_regs
.npc
);
223 if (test_thread_flag(TIF_32BIT
)) {
230 /* 2. Restore the state */
231 err
= __get_user(regs
->y
, &sf
->info
.si_regs
.y
);
232 err
|= __get_user(psr
, &sf
->info
.si_regs
.psr
);
234 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
235 err
|= __get_user(regs
->u_regs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
236 if ((psr
& (PSR_VERS
|PSR_IMPL
)) == PSR_V8PLUS
) {
237 err
|= __get_user(i
, &sf
->v8plus
.g_upper
[0]);
238 if (i
== SIGINFO_EXTRA_V8PLUS_MAGIC
) {
241 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
242 err
|= __get_user(((u32
*)regs
->u_regs
)[2*i
], &sf
->v8plus
.g_upper
[i
]);
243 err
|= __get_user(asi
, &sf
->v8plus
.asi
);
244 regs
->tstate
&= ~TSTATE_ASI
;
245 regs
->tstate
|= ((asi
& 0xffUL
) << 24UL);
249 /* User can only change condition codes in %tstate. */
250 regs
->tstate
&= ~(TSTATE_ICC
|TSTATE_XCC
);
251 regs
->tstate
|= psr_to_tstate_icc(psr
);
253 /* Prevent syscall restart. */
254 pt_regs_clear_syscall(regs
);
256 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
257 if (!err
&& fpu_save
)
258 err
|= restore_fpu_state(regs
, compat_ptr(fpu_save
));
259 err
|= __get_user(rwin_save
, &sf
->rwin_save
);
260 if (!err
&& rwin_save
) {
261 if (restore_rwin_state(compat_ptr(rwin_save
)))
264 err
|= __get_user(seta
[0], &sf
->info
.si_mask
);
265 err
|= copy_from_user(seta
+1, &sf
->extramask
,
266 (_COMPAT_NSIG_WORDS
- 1) * sizeof(unsigned int));
269 switch (_NSIG_WORDS
) {
270 case 4: set
.sig
[3] = seta
[6] + (((long)seta
[7]) << 32);
271 case 3: set
.sig
[2] = seta
[4] + (((long)seta
[5]) << 32);
272 case 2: set
.sig
[1] = seta
[2] + (((long)seta
[3]) << 32);
273 case 1: set
.sig
[0] = seta
[0] + (((long)seta
[1]) << 32);
275 sigdelsetmask(&set
, ~_BLOCKABLE
);
276 set_current_blocked(&set
);
280 force_sig(SIGSEGV
, current
);
283 asmlinkage
void do_rt_sigreturn32(struct pt_regs
*regs
)
285 struct rt_signal_frame32 __user
*sf
;
286 unsigned int psr
, pc
, npc
, u_ss_sp
;
287 compat_uptr_t fpu_save
;
288 compat_uptr_t rwin_save
;
291 compat_sigset_t seta
;
295 /* Always make any pending restarted system calls return -EINTR */
296 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
298 synchronize_user_stack();
299 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
300 sf
= (struct rt_signal_frame32 __user
*) regs
->u_regs
[UREG_FP
];
302 /* 1. Make sure we are not getting garbage from the user */
303 if (!access_ok(VERIFY_READ
, sf
, sizeof(*sf
)) ||
304 (((unsigned long) sf
) & 3))
307 get_user(pc
, &sf
->regs
.pc
);
308 __get_user(npc
, &sf
->regs
.npc
);
313 if (test_thread_flag(TIF_32BIT
)) {
320 /* 2. Restore the state */
321 err
= __get_user(regs
->y
, &sf
->regs
.y
);
322 err
|= __get_user(psr
, &sf
->regs
.psr
);
324 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
325 err
|= __get_user(regs
->u_regs
[i
], &sf
->regs
.u_regs
[i
]);
326 if ((psr
& (PSR_VERS
|PSR_IMPL
)) == PSR_V8PLUS
) {
327 err
|= __get_user(i
, &sf
->v8plus
.g_upper
[0]);
328 if (i
== SIGINFO_EXTRA_V8PLUS_MAGIC
) {
331 for (i
= UREG_G1
; i
<= UREG_I7
; i
++)
332 err
|= __get_user(((u32
*)regs
->u_regs
)[2*i
], &sf
->v8plus
.g_upper
[i
]);
333 err
|= __get_user(asi
, &sf
->v8plus
.asi
);
334 regs
->tstate
&= ~TSTATE_ASI
;
335 regs
->tstate
|= ((asi
& 0xffUL
) << 24UL);
339 /* User can only change condition codes in %tstate. */
340 regs
->tstate
&= ~(TSTATE_ICC
|TSTATE_XCC
);
341 regs
->tstate
|= psr_to_tstate_icc(psr
);
343 /* Prevent syscall restart. */
344 pt_regs_clear_syscall(regs
);
346 err
|= __get_user(fpu_save
, &sf
->fpu_save
);
347 if (!err
&& fpu_save
)
348 err
|= restore_fpu_state(regs
, compat_ptr(fpu_save
));
349 err
|= copy_from_user(&seta
, &sf
->mask
, sizeof(compat_sigset_t
));
350 err
|= __get_user(u_ss_sp
, &sf
->stack
.ss_sp
);
351 st
.ss_sp
= compat_ptr(u_ss_sp
);
352 err
|= __get_user(st
.ss_flags
, &sf
->stack
.ss_flags
);
353 err
|= __get_user(st
.ss_size
, &sf
->stack
.ss_size
);
357 /* It is more difficult to avoid calling this function than to
358 call it and ignore errors. */
361 do_sigaltstack((stack_t __user
*) &st
, NULL
, (unsigned long)sf
);
364 err
|= __get_user(rwin_save
, &sf
->rwin_save
);
365 if (!err
&& rwin_save
) {
366 if (restore_rwin_state(compat_ptr(rwin_save
)))
370 switch (_NSIG_WORDS
) {
371 case 4: set
.sig
[3] = seta
.sig
[6] + (((long)seta
.sig
[7]) << 32);
372 case 3: set
.sig
[2] = seta
.sig
[4] + (((long)seta
.sig
[5]) << 32);
373 case 2: set
.sig
[1] = seta
.sig
[2] + (((long)seta
.sig
[3]) << 32);
374 case 1: set
.sig
[0] = seta
.sig
[0] + (((long)seta
.sig
[1]) << 32);
376 sigdelsetmask(&set
, ~_BLOCKABLE
);
377 set_current_blocked(&set
);
380 force_sig(SIGSEGV
, current
);
383 /* Checks if the fp is valid */
384 static int invalid_frame_pointer(void __user
*fp
, int fplen
)
386 if ((((unsigned long) fp
) & 7) || ((unsigned long)fp
) > 0x100000000ULL
- fplen
)
391 static void __user
*get_sigframe(struct sigaction
*sa
, struct pt_regs
*regs
, unsigned long framesize
)
395 regs
->u_regs
[UREG_FP
] &= 0x00000000ffffffffUL
;
396 sp
= regs
->u_regs
[UREG_FP
];
399 * If we are on the alternate signal stack and would overflow it, don't.
400 * Return an always-bogus address instead so we will die with SIGSEGV.
402 if (on_sig_stack(sp
) && !likely(on_sig_stack(sp
- framesize
)))
403 return (void __user
*) -1L;
405 /* This is the X/Open sanctioned signal stack switching. */
406 if (sa
->sa_flags
& SA_ONSTACK
) {
407 if (sas_ss_flags(sp
) == 0)
408 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
413 /* Always align the stack frame. This handles two cases. First,
414 * sigaltstack need not be mindful of platform specific stack
415 * alignment. Second, if we took this signal because the stack
416 * is not aligned properly, we'd like to take the signal cleanly
421 return (void __user
*) sp
;
424 /* The I-cache flush instruction only works in the primary ASI, which
425 * right now is the nucleus, aka. kernel space.
427 * Therefore we have to kick the instructions out using the kernel
428 * side linear mapping of the physical address backing the user
431 static void flush_signal_insns(unsigned long address
)
433 unsigned long pstate
, paddr
;
439 /* Commit all stores of the instructions we are about to flush. */
442 /* Disable cross-call reception. In this way even a very wide
443 * munmap() on another cpu can't tear down the page table
444 * hierarchy from underneath us, since that can't complete
445 * until the IPI tlb flush returns.
448 __asm__
__volatile__("rdpr %%pstate, %0" : "=r" (pstate
));
449 __asm__
__volatile__("wrpr %0, %1, %%pstate"
450 : : "r" (pstate
), "i" (PSTATE_IE
));
452 pgdp
= pgd_offset(current
->mm
, address
);
455 pudp
= pud_offset(pgdp
, address
);
458 pmdp
= pmd_offset(pudp
, address
);
462 ptep
= pte_offset_map(pmdp
, address
);
464 if (!pte_present(pte
))
467 paddr
= (unsigned long) page_address(pte_page(pte
));
469 __asm__
__volatile__("flush %0 + %1"
472 "r" (address
& (PAGE_SIZE
- 1))
478 __asm__
__volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate
));
482 static int setup_frame32(struct k_sigaction
*ka
, struct pt_regs
*regs
,
483 int signo
, sigset_t
*oldset
)
485 struct signal_frame32 __user
*sf
;
490 unsigned int seta
[_COMPAT_NSIG_WORDS
];
492 /* 1. Make sure everything is clean */
493 synchronize_user_stack();
494 save_and_clear_fpu();
496 wsaved
= get_thread_wsaved();
498 sigframe_size
= sizeof(*sf
);
499 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
500 sigframe_size
+= sizeof(__siginfo_fpu_t
);
502 sigframe_size
+= sizeof(__siginfo_rwin_t
);
504 sf
= (struct signal_frame32 __user
*)
505 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
507 if (invalid_frame_pointer(sf
, sigframe_size
))
512 /* 2. Save the current process state */
513 if (test_thread_flag(TIF_32BIT
)) {
514 regs
->tpc
&= 0xffffffff;
515 regs
->tnpc
&= 0xffffffff;
517 err
= put_user(regs
->tpc
, &sf
->info
.si_regs
.pc
);
518 err
|= __put_user(regs
->tnpc
, &sf
->info
.si_regs
.npc
);
519 err
|= __put_user(regs
->y
, &sf
->info
.si_regs
.y
);
520 psr
= tstate_to_psr(regs
->tstate
);
521 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
523 err
|= __put_user(psr
, &sf
->info
.si_regs
.psr
);
524 for (i
= 0; i
< 16; i
++)
525 err
|= __put_user(regs
->u_regs
[i
], &sf
->info
.si_regs
.u_regs
[i
]);
526 err
|= __put_user(sizeof(siginfo_extra_v8plus_t
), &sf
->extra_size
);
527 err
|= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC
, &sf
->v8plus
.g_upper
[0]);
528 for (i
= 1; i
< 16; i
++)
529 err
|= __put_user(((u32
*)regs
->u_regs
)[2*i
],
530 &sf
->v8plus
.g_upper
[i
]);
531 err
|= __put_user((regs
->tstate
& TSTATE_ASI
) >> 24UL,
535 __siginfo_fpu_t __user
*fp
= tail
;
537 err
|= save_fpu_state(regs
, fp
);
538 err
|= __put_user((u64
)fp
, &sf
->fpu_save
);
540 err
|= __put_user(0, &sf
->fpu_save
);
543 __siginfo_rwin_t __user
*rwp
= tail
;
544 tail
+= sizeof(*rwp
);
545 err
|= save_rwin_state(wsaved
, rwp
);
546 err
|= __put_user((u64
)rwp
, &sf
->rwin_save
);
547 set_thread_wsaved(0);
549 err
|= __put_user(0, &sf
->rwin_save
);
552 switch (_NSIG_WORDS
) {
553 case 4: seta
[7] = (oldset
->sig
[3] >> 32);
554 seta
[6] = oldset
->sig
[3];
555 case 3: seta
[5] = (oldset
->sig
[2] >> 32);
556 seta
[4] = oldset
->sig
[2];
557 case 2: seta
[3] = (oldset
->sig
[1] >> 32);
558 seta
[2] = oldset
->sig
[1];
559 case 1: seta
[1] = (oldset
->sig
[0] >> 32);
560 seta
[0] = oldset
->sig
[0];
562 err
|= __put_user(seta
[0], &sf
->info
.si_mask
);
563 err
|= __copy_to_user(sf
->extramask
, seta
+ 1,
564 (_COMPAT_NSIG_WORDS
- 1) * sizeof(unsigned int));
567 err
|= copy_in_user((u32 __user
*)sf
,
568 (u32 __user
*)(regs
->u_regs
[UREG_FP
]),
569 sizeof(struct reg_window32
));
571 struct reg_window
*rp
;
573 rp
= ¤t_thread_info()->reg_window
[wsaved
- 1];
574 for (i
= 0; i
< 8; i
++)
575 err
|= __put_user(rp
->locals
[i
], &sf
->ss
.locals
[i
]);
576 for (i
= 0; i
< 6; i
++)
577 err
|= __put_user(rp
->ins
[i
], &sf
->ss
.ins
[i
]);
578 err
|= __put_user(rp
->ins
[6], &sf
->ss
.fp
);
579 err
|= __put_user(rp
->ins
[7], &sf
->ss
.callers_pc
);
584 /* 3. signal handler back-trampoline and parameters */
585 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
586 regs
->u_regs
[UREG_I0
] = signo
;
587 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
588 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->info
;
590 /* 4. signal handler */
591 regs
->tpc
= (unsigned long) ka
->sa
.sa_handler
;
592 regs
->tnpc
= (regs
->tpc
+ 4);
593 if (test_thread_flag(TIF_32BIT
)) {
594 regs
->tpc
&= 0xffffffff;
595 regs
->tnpc
&= 0xffffffff;
598 /* 5. return to kernel instructions */
599 if (ka
->ka_restorer
) {
600 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
602 unsigned long address
= ((unsigned long)&(sf
->insns
[0]));
604 regs
->u_regs
[UREG_I7
] = (unsigned long) (&(sf
->insns
[0]) - 2);
606 err
= __put_user(0x821020d8, &sf
->insns
[0]); /*mov __NR_sigreturn, %g1*/
607 err
|= __put_user(0x91d02010, &sf
->insns
[1]); /*t 0x10*/
610 flush_signal_insns(address
);
619 force_sigsegv(signo
, current
);
623 static int setup_rt_frame32(struct k_sigaction
*ka
, struct pt_regs
*regs
,
624 unsigned long signr
, sigset_t
*oldset
,
627 struct rt_signal_frame32 __user
*sf
;
632 compat_sigset_t seta
;
634 /* 1. Make sure everything is clean */
635 synchronize_user_stack();
636 save_and_clear_fpu();
638 wsaved
= get_thread_wsaved();
640 sigframe_size
= sizeof(*sf
);
641 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
642 sigframe_size
+= sizeof(__siginfo_fpu_t
);
644 sigframe_size
+= sizeof(__siginfo_rwin_t
);
646 sf
= (struct rt_signal_frame32 __user
*)
647 get_sigframe(&ka
->sa
, regs
, sigframe_size
);
649 if (invalid_frame_pointer(sf
, sigframe_size
))
654 /* 2. Save the current process state */
655 if (test_thread_flag(TIF_32BIT
)) {
656 regs
->tpc
&= 0xffffffff;
657 regs
->tnpc
&= 0xffffffff;
659 err
= put_user(regs
->tpc
, &sf
->regs
.pc
);
660 err
|= __put_user(regs
->tnpc
, &sf
->regs
.npc
);
661 err
|= __put_user(regs
->y
, &sf
->regs
.y
);
662 psr
= tstate_to_psr(regs
->tstate
);
663 if (current_thread_info()->fpsaved
[0] & FPRS_FEF
)
665 err
|= __put_user(psr
, &sf
->regs
.psr
);
666 for (i
= 0; i
< 16; i
++)
667 err
|= __put_user(regs
->u_regs
[i
], &sf
->regs
.u_regs
[i
]);
668 err
|= __put_user(sizeof(siginfo_extra_v8plus_t
), &sf
->extra_size
);
669 err
|= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC
, &sf
->v8plus
.g_upper
[0]);
670 for (i
= 1; i
< 16; i
++)
671 err
|= __put_user(((u32
*)regs
->u_regs
)[2*i
],
672 &sf
->v8plus
.g_upper
[i
]);
673 err
|= __put_user((regs
->tstate
& TSTATE_ASI
) >> 24UL,
677 __siginfo_fpu_t __user
*fp
= tail
;
679 err
|= save_fpu_state(regs
, fp
);
680 err
|= __put_user((u64
)fp
, &sf
->fpu_save
);
682 err
|= __put_user(0, &sf
->fpu_save
);
685 __siginfo_rwin_t __user
*rwp
= tail
;
686 tail
+= sizeof(*rwp
);
687 err
|= save_rwin_state(wsaved
, rwp
);
688 err
|= __put_user((u64
)rwp
, &sf
->rwin_save
);
689 set_thread_wsaved(0);
691 err
|= __put_user(0, &sf
->rwin_save
);
694 /* Update the siginfo structure. */
695 err
|= copy_siginfo_to_user32(&sf
->info
, info
);
697 /* Setup sigaltstack */
698 err
|= __put_user(current
->sas_ss_sp
, &sf
->stack
.ss_sp
);
699 err
|= __put_user(sas_ss_flags(regs
->u_regs
[UREG_FP
]), &sf
->stack
.ss_flags
);
700 err
|= __put_user(current
->sas_ss_size
, &sf
->stack
.ss_size
);
702 switch (_NSIG_WORDS
) {
703 case 4: seta
.sig
[7] = (oldset
->sig
[3] >> 32);
704 seta
.sig
[6] = oldset
->sig
[3];
705 case 3: seta
.sig
[5] = (oldset
->sig
[2] >> 32);
706 seta
.sig
[4] = oldset
->sig
[2];
707 case 2: seta
.sig
[3] = (oldset
->sig
[1] >> 32);
708 seta
.sig
[2] = oldset
->sig
[1];
709 case 1: seta
.sig
[1] = (oldset
->sig
[0] >> 32);
710 seta
.sig
[0] = oldset
->sig
[0];
712 err
|= __copy_to_user(&sf
->mask
, &seta
, sizeof(compat_sigset_t
));
715 err
|= copy_in_user((u32 __user
*)sf
,
716 (u32 __user
*)(regs
->u_regs
[UREG_FP
]),
717 sizeof(struct reg_window32
));
719 struct reg_window
*rp
;
721 rp
= ¤t_thread_info()->reg_window
[wsaved
- 1];
722 for (i
= 0; i
< 8; i
++)
723 err
|= __put_user(rp
->locals
[i
], &sf
->ss
.locals
[i
]);
724 for (i
= 0; i
< 6; i
++)
725 err
|= __put_user(rp
->ins
[i
], &sf
->ss
.ins
[i
]);
726 err
|= __put_user(rp
->ins
[6], &sf
->ss
.fp
);
727 err
|= __put_user(rp
->ins
[7], &sf
->ss
.callers_pc
);
732 /* 3. signal handler back-trampoline and parameters */
733 regs
->u_regs
[UREG_FP
] = (unsigned long) sf
;
734 regs
->u_regs
[UREG_I0
] = signr
;
735 regs
->u_regs
[UREG_I1
] = (unsigned long) &sf
->info
;
736 regs
->u_regs
[UREG_I2
] = (unsigned long) &sf
->regs
;
738 /* 4. signal handler */
739 regs
->tpc
= (unsigned long) ka
->sa
.sa_handler
;
740 regs
->tnpc
= (regs
->tpc
+ 4);
741 if (test_thread_flag(TIF_32BIT
)) {
742 regs
->tpc
&= 0xffffffff;
743 regs
->tnpc
&= 0xffffffff;
746 /* 5. return to kernel instructions */
748 regs
->u_regs
[UREG_I7
] = (unsigned long)ka
->ka_restorer
;
750 unsigned long address
= ((unsigned long)&(sf
->insns
[0]));
752 regs
->u_regs
[UREG_I7
] = (unsigned long) (&(sf
->insns
[0]) - 2);
754 /* mov __NR_rt_sigreturn, %g1 */
755 err
|= __put_user(0x82102065, &sf
->insns
[0]);
758 err
|= __put_user(0x91d02010, &sf
->insns
[1]);
762 flush_signal_insns(address
);
771 force_sigsegv(signr
, current
);
775 static inline int handle_signal32(unsigned long signr
, struct k_sigaction
*ka
,
777 sigset_t
*oldset
, struct pt_regs
*regs
)
781 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
782 err
= setup_rt_frame32(ka
, regs
, signr
, oldset
, info
);
784 err
= setup_frame32(ka
, regs
, signr
, oldset
);
789 block_sigmask(ka
, signr
);
791 tracehook_signal_handler(signr
, info
, ka
, regs
, 0);
796 static inline void syscall_restart32(unsigned long orig_i0
, struct pt_regs
*regs
,
797 struct sigaction
*sa
)
799 switch (regs
->u_regs
[UREG_I0
]) {
800 case ERESTART_RESTARTBLOCK
:
802 no_system_call_restart
:
803 regs
->u_regs
[UREG_I0
] = EINTR
;
804 regs
->tstate
|= TSTATE_ICARRY
;
807 if (!(sa
->sa_flags
& SA_RESTART
))
808 goto no_system_call_restart
;
811 regs
->u_regs
[UREG_I0
] = orig_i0
;
817 /* Note that 'init' is a special process: it doesn't get signals it doesn't
818 * want to handle. Thus you cannot kill init even with a SIGKILL even by
821 void do_signal32(sigset_t
*oldset
, struct pt_regs
* regs
,
822 int restart_syscall
, unsigned long orig_i0
)
824 struct k_sigaction ka
;
828 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
830 /* If the debugger messes with the program counter, it clears
831 * the "in syscall" bit, directing us to not perform a syscall
834 if (restart_syscall
&& !pt_regs_is_syscall(regs
))
839 syscall_restart32(orig_i0
, regs
, &ka
.sa
);
840 if (handle_signal32(signr
, &ka
, &info
, oldset
, regs
) == 0) {
841 /* A signal was successfully delivered; the saved
842 * sigmask will have been stored in the signal frame,
843 * and will be restored by sigreturn, so we can simply
844 * clear the TS_RESTORE_SIGMASK flag.
846 current_thread_info()->status
&= ~TS_RESTORE_SIGMASK
;
850 if (restart_syscall
&&
851 (regs
->u_regs
[UREG_I0
] == ERESTARTNOHAND
||
852 regs
->u_regs
[UREG_I0
] == ERESTARTSYS
||
853 regs
->u_regs
[UREG_I0
] == ERESTARTNOINTR
)) {
854 /* replay the system call when we are done */
855 regs
->u_regs
[UREG_I0
] = orig_i0
;
858 pt_regs_clear_syscall(regs
);
860 if (restart_syscall
&&
861 regs
->u_regs
[UREG_I0
] == ERESTART_RESTARTBLOCK
) {
862 regs
->u_regs
[UREG_G1
] = __NR_restart_syscall
;
865 pt_regs_clear_syscall(regs
);
868 /* If there's no signal to deliver, we just put the saved sigmask
871 if (current_thread_info()->status
& TS_RESTORE_SIGMASK
) {
872 current_thread_info()->status
&= ~TS_RESTORE_SIGMASK
;
873 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
882 asmlinkage
int do_sys32_sigstack(u32 u_ssptr
, u32 u_ossptr
, unsigned long sp
)
884 struct sigstack32 __user
*ssptr
=
885 (struct sigstack32 __user
*)((unsigned long)(u_ssptr
));
886 struct sigstack32 __user
*ossptr
=
887 (struct sigstack32 __user
*)((unsigned long)(u_ossptr
));
890 /* First see if old state is wanted. */
892 if (put_user(current
->sas_ss_sp
+ current
->sas_ss_size
,
893 &ossptr
->the_stack
) ||
894 __put_user(on_sig_stack(sp
), &ossptr
->cur_status
))
898 /* Now see if we want to update the new state. */
902 if (get_user(ss_sp
, &ssptr
->the_stack
))
905 /* If the current stack was set with sigaltstack, don't
906 * swap stacks while we are on it.
909 if (current
->sas_ss_sp
&& on_sig_stack(sp
))
912 /* Since we don't know the extent of the stack, and we don't
913 * track onstack-ness, but rather calculate it, we must
914 * presume a size. Ho hum this interface is lossy.
916 current
->sas_ss_sp
= (unsigned long)ss_sp
- SIGSTKSZ
;
917 current
->sas_ss_size
= SIGSTKSZ
;
925 asmlinkage
long do_sys32_sigaltstack(u32 ussa
, u32 uossa
, unsigned long sp
)
931 stack_t32 __user
*uss32
= compat_ptr(ussa
);
932 stack_t32 __user
*uoss32
= compat_ptr(uossa
);
934 if (ussa
&& (get_user(u_ss_sp
, &uss32
->ss_sp
) ||
935 __get_user(uss
.ss_flags
, &uss32
->ss_flags
) ||
936 __get_user(uss
.ss_size
, &uss32
->ss_size
)))
938 uss
.ss_sp
= compat_ptr(u_ss_sp
);
941 ret
= do_sigaltstack(ussa
? (stack_t __user
*) &uss
: NULL
,
942 uossa
? (stack_t __user
*) &uoss
: NULL
, sp
);
944 if (!ret
&& uossa
&& (put_user(ptr_to_compat(uoss
.ss_sp
), &uoss32
->ss_sp
) ||
945 __put_user(uoss
.ss_flags
, &uoss32
->ss_flags
) ||
946 __put_user(uoss
.ss_size
, &uoss32
->ss_size
)))