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>
23 #include <asm/uaccess.h>
24 #include <asm/ptrace.h>
25 #include <asm/pgtable.h>
26 #include <asm/psrcompat.h>
27 #include <asm/fpumacro.h>
28 #include <asm/visasm.h>
29 #include <asm/compat_signal.h>
31 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33 /* This magic should be in g_upper[0] for all upper parts
36 #define SIGINFO_EXTRA_V8PLUS_MAGIC 0x130e269
38 unsigned int g_upper[8];
39 unsigned int o_upper[8];
41 } siginfo_extra_v8plus_t;
43 struct signal_frame32 {
44 struct sparc_stackf32 ss;
46 /* __siginfo_fpu32_t * */ u32 fpu_save;
47 unsigned int insns[2];
48 unsigned int extramask[_COMPAT_NSIG_WORDS - 1];
49 unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
50 /* Only valid if (info.si_regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
51 siginfo_extra_v8plus_t v8plus;
52 __siginfo_fpu_t fpu_state;
55 typedef struct compat_siginfo{
61 int _pad[SI_PAD_SIZE32];
65 compat_pid_t _pid; /* sender's pid */
66 unsigned int _uid; /* sender's uid */
71 compat_timer_t _tid; /* timer id */
72 int _overrun; /* overrun count */
73 compat_sigval_t _sigval; /* same as below */
74 int _sys_private; /* not to be passed to user */
77 /* POSIX.1b signals */
79 compat_pid_t _pid; /* sender's pid */
80 unsigned int _uid; /* sender's uid */
81 compat_sigval_t _sigval;
86 compat_pid_t _pid; /* which child */
87 unsigned int _uid; /* sender's uid */
88 int _status; /* exit code */
89 compat_clock_t _utime;
90 compat_clock_t _stime;
93 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGEMT */
95 u32 _addr; /* faulting insn/memory ref. */
101 int _band; /* POLL_IN, POLL_OUT, POLL_MSG */
107 struct rt_signal_frame32 {
108 struct sparc_stackf32 ss;
109 compat_siginfo_t info;
110 struct pt_regs32 regs;
111 compat_sigset_t mask;
112 /* __siginfo_fpu32_t * */ u32 fpu_save;
113 unsigned int insns[2];
115 unsigned int extra_size; /* Should be sizeof(siginfo_extra_v8plus_t) */
116 /* Only valid if (regs.psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS */
117 siginfo_extra_v8plus_t v8plus;
118 __siginfo_fpu_t fpu_state;
122 #define SF_ALIGNEDSZ (((sizeof(struct signal_frame32) + 7) & (~7)))
123 #define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame32) + 7) & (~7)))
125 int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
129 if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
132 /* If you change siginfo_t structure, please be sure
133 this code is fixed accordingly.
134 It should never copy any pad contained in the structure
135 to avoid security leaks, but must copy the generic
136 3 ints plus the relevant union member.
137 This routine must convert siginfo from 64bit to 32bit as well
139 err = __put_user(from->si_signo, &to->si_signo);
140 err |= __put_user(from->si_errno, &to->si_errno);
141 err |= __put_user((short)from->si_code, &to->si_code);
142 if (from->si_code < 0)
143 err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
145 switch (from->si_code >> 16) {
146 case __SI_TIMER >> 16:
147 err |= __put_user(from->si_tid, &to->si_tid);
148 err |= __put_user(from->si_overrun, &to->si_overrun);
149 err |= __put_user(from->si_int, &to->si_int);
151 case __SI_CHLD >> 16:
152 err |= __put_user(from->si_utime, &to->si_utime);
153 err |= __put_user(from->si_stime, &to->si_stime);
154 err |= __put_user(from->si_status, &to->si_status);
156 err |= __put_user(from->si_pid, &to->si_pid);
157 err |= __put_user(from->si_uid, &to->si_uid);
159 case __SI_FAULT >> 16:
160 err |= __put_user(from->si_trapno, &to->si_trapno);
161 err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
163 case __SI_POLL >> 16:
164 err |= __put_user(from->si_band, &to->si_band);
165 err |= __put_user(from->si_fd, &to->si_fd);
167 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
168 case __SI_MESGQ >> 16:
169 err |= __put_user(from->si_pid, &to->si_pid);
170 err |= __put_user(from->si_uid, &to->si_uid);
171 err |= __put_user(from->si_int, &to->si_int);
178 /* CAUTION: This is just a very minimalist implementation for the
179 * sake of compat_sys_rt_sigqueueinfo()
181 int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
183 if (!access_ok(VERIFY_WRITE, from, sizeof(compat_siginfo_t)))
186 if (copy_from_user(to, from, 3*sizeof(int)) ||
187 copy_from_user(to->_sifields._pad, from->_sifields._pad,
194 static int restore_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
196 unsigned long *fpregs = current_thread_info()->fpregs;
200 err = __get_user(fprs, &fpu->si_fprs);
202 regs->tstate &= ~TSTATE_PEF;
204 err |= copy_from_user(fpregs, &fpu->si_float_regs[0], (sizeof(unsigned int) * 32));
206 err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32], (sizeof(unsigned int) * 32));
207 err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
208 err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr);
209 current_thread_info()->fpsaved[0] |= fprs;
213 void do_sigreturn32(struct pt_regs *regs)
215 struct signal_frame32 __user *sf;
217 unsigned pc, npc, fpu_save;
219 unsigned seta[_COMPAT_NSIG_WORDS];
222 /* Always make any pending restarted system calls return -EINTR */
223 current_thread_info()->restart_block.fn = do_no_restart_syscall;
225 synchronize_user_stack();
227 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
228 sf = (struct signal_frame32 __user *) regs->u_regs[UREG_FP];
230 /* 1. Make sure we are not getting garbage from the user */
231 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
232 (((unsigned long) sf) & 3))
235 get_user(pc, &sf->info.si_regs.pc);
236 __get_user(npc, &sf->info.si_regs.npc);
241 if (test_thread_flag(TIF_32BIT)) {
248 /* 2. Restore the state */
249 err = __get_user(regs->y, &sf->info.si_regs.y);
250 err |= __get_user(psr, &sf->info.si_regs.psr);
252 for (i = UREG_G1; i <= UREG_I7; i++)
253 err |= __get_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
254 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
255 err |= __get_user(i, &sf->v8plus.g_upper[0]);
256 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
259 for (i = UREG_G1; i <= UREG_I7; i++)
260 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
261 err |= __get_user(asi, &sf->v8plus.asi);
262 regs->tstate &= ~TSTATE_ASI;
263 regs->tstate |= ((asi & 0xffUL) << 24UL);
267 /* User can only change condition codes in %tstate. */
268 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
269 regs->tstate |= psr_to_tstate_icc(psr);
271 err |= __get_user(fpu_save, &sf->fpu_save);
273 err |= restore_fpu_state32(regs, &sf->fpu_state);
274 err |= __get_user(seta[0], &sf->info.si_mask);
275 err |= copy_from_user(seta+1, &sf->extramask,
276 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
279 switch (_NSIG_WORDS) {
280 case 4: set.sig[3] = seta[6] + (((long)seta[7]) << 32);
281 case 3: set.sig[2] = seta[4] + (((long)seta[5]) << 32);
282 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32);
283 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32);
285 sigdelsetmask(&set, ~_BLOCKABLE);
286 spin_lock_irq(¤t->sighand->siglock);
287 current->blocked = set;
289 spin_unlock_irq(¤t->sighand->siglock);
293 force_sig(SIGSEGV, current);
296 asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
298 struct rt_signal_frame32 __user *sf;
299 unsigned int psr, pc, npc, fpu_save, u_ss_sp;
302 compat_sigset_t seta;
306 /* Always make any pending restarted system calls return -EINTR */
307 current_thread_info()->restart_block.fn = do_no_restart_syscall;
309 synchronize_user_stack();
310 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
311 sf = (struct rt_signal_frame32 __user *) regs->u_regs[UREG_FP];
313 /* 1. Make sure we are not getting garbage from the user */
314 if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
315 (((unsigned long) sf) & 3))
318 get_user(pc, &sf->regs.pc);
319 __get_user(npc, &sf->regs.npc);
324 if (test_thread_flag(TIF_32BIT)) {
331 /* 2. Restore the state */
332 err = __get_user(regs->y, &sf->regs.y);
333 err |= __get_user(psr, &sf->regs.psr);
335 for (i = UREG_G1; i <= UREG_I7; i++)
336 err |= __get_user(regs->u_regs[i], &sf->regs.u_regs[i]);
337 if ((psr & (PSR_VERS|PSR_IMPL)) == PSR_V8PLUS) {
338 err |= __get_user(i, &sf->v8plus.g_upper[0]);
339 if (i == SIGINFO_EXTRA_V8PLUS_MAGIC) {
342 for (i = UREG_G1; i <= UREG_I7; i++)
343 err |= __get_user(((u32 *)regs->u_regs)[2*i], &sf->v8plus.g_upper[i]);
344 err |= __get_user(asi, &sf->v8plus.asi);
345 regs->tstate &= ~TSTATE_ASI;
346 regs->tstate |= ((asi & 0xffUL) << 24UL);
350 /* User can only change condition codes in %tstate. */
351 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
352 regs->tstate |= psr_to_tstate_icc(psr);
354 err |= __get_user(fpu_save, &sf->fpu_save);
356 err |= restore_fpu_state32(regs, &sf->fpu_state);
357 err |= copy_from_user(&seta, &sf->mask, sizeof(compat_sigset_t));
358 err |= __get_user(u_ss_sp, &sf->stack.ss_sp);
359 st.ss_sp = compat_ptr(u_ss_sp);
360 err |= __get_user(st.ss_flags, &sf->stack.ss_flags);
361 err |= __get_user(st.ss_size, &sf->stack.ss_size);
365 /* It is more difficult to avoid calling this function than to
366 call it and ignore errors. */
369 do_sigaltstack((stack_t __user *) &st, NULL, (unsigned long)sf);
372 switch (_NSIG_WORDS) {
373 case 4: set.sig[3] = seta.sig[6] + (((long)seta.sig[7]) << 32);
374 case 3: set.sig[2] = seta.sig[4] + (((long)seta.sig[5]) << 32);
375 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32);
376 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32);
378 sigdelsetmask(&set, ~_BLOCKABLE);
379 spin_lock_irq(¤t->sighand->siglock);
380 current->blocked = set;
382 spin_unlock_irq(¤t->sighand->siglock);
385 force_sig(SIGSEGV, current);
388 /* Checks if the fp is valid */
389 static int invalid_frame_pointer(void __user *fp, int fplen)
391 if ((((unsigned long) fp) & 7) || ((unsigned long)fp) > 0x100000000ULL - fplen)
396 static void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
400 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
401 sp = regs->u_regs[UREG_FP];
403 /* This is the X/Open sanctioned signal stack switching. */
404 if (sa->sa_flags & SA_ONSTACK) {
405 if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
406 sp = current->sas_ss_sp + current->sas_ss_size;
408 return (void __user *)(sp - framesize);
411 static int save_fpu_state32(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
413 unsigned long *fpregs = current_thread_info()->fpregs;
417 fprs = current_thread_info()->fpsaved[0];
419 err |= copy_to_user(&fpu->si_float_regs[0], fpregs,
420 (sizeof(unsigned int) * 32));
422 err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16,
423 (sizeof(unsigned int) * 32));
424 err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
425 err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr);
426 err |= __put_user(fprs, &fpu->si_fprs);
431 static void setup_frame32(struct k_sigaction *ka, struct pt_regs *regs,
432 int signo, sigset_t *oldset)
434 struct signal_frame32 __user *sf;
438 unsigned int seta[_COMPAT_NSIG_WORDS];
440 /* 1. Make sure everything is clean */
441 synchronize_user_stack();
442 save_and_clear_fpu();
444 sigframe_size = SF_ALIGNEDSZ;
445 if (!(current_thread_info()->fpsaved[0] & FPRS_FEF))
446 sigframe_size -= sizeof(__siginfo_fpu_t);
448 sf = (struct signal_frame32 __user *)
449 get_sigframe(&ka->sa, regs, sigframe_size);
451 if (invalid_frame_pointer(sf, sigframe_size))
454 if (get_thread_wsaved() != 0)
457 /* 2. Save the current process state */
458 if (test_thread_flag(TIF_32BIT)) {
459 regs->tpc &= 0xffffffff;
460 regs->tnpc &= 0xffffffff;
462 err = put_user(regs->tpc, &sf->info.si_regs.pc);
463 err |= __put_user(regs->tnpc, &sf->info.si_regs.npc);
464 err |= __put_user(regs->y, &sf->info.si_regs.y);
465 psr = tstate_to_psr(regs->tstate);
466 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
468 err |= __put_user(psr, &sf->info.si_regs.psr);
469 for (i = 0; i < 16; i++)
470 err |= __put_user(regs->u_regs[i], &sf->info.si_regs.u_regs[i]);
471 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
472 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
473 for (i = 1; i < 16; i++)
474 err |= __put_user(((u32 *)regs->u_regs)[2*i],
475 &sf->v8plus.g_upper[i]);
476 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
480 err |= save_fpu_state32(regs, &sf->fpu_state);
481 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save);
483 err |= __put_user(0, &sf->fpu_save);
486 switch (_NSIG_WORDS) {
487 case 4: seta[7] = (oldset->sig[3] >> 32);
488 seta[6] = oldset->sig[3];
489 case 3: seta[5] = (oldset->sig[2] >> 32);
490 seta[4] = oldset->sig[2];
491 case 2: seta[3] = (oldset->sig[1] >> 32);
492 seta[2] = oldset->sig[1];
493 case 1: seta[1] = (oldset->sig[0] >> 32);
494 seta[0] = oldset->sig[0];
496 err |= __put_user(seta[0], &sf->info.si_mask);
497 err |= __copy_to_user(sf->extramask, seta + 1,
498 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int));
500 err |= copy_in_user((u32 __user *)sf,
501 (u32 __user *)(regs->u_regs[UREG_FP]),
502 sizeof(struct reg_window32));
507 /* 3. signal handler back-trampoline and parameters */
508 regs->u_regs[UREG_FP] = (unsigned long) sf;
509 regs->u_regs[UREG_I0] = signo;
510 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
511 regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
513 /* 4. signal handler */
514 regs->tpc = (unsigned long) ka->sa.sa_handler;
515 regs->tnpc = (regs->tpc + 4);
516 if (test_thread_flag(TIF_32BIT)) {
517 regs->tpc &= 0xffffffff;
518 regs->tnpc &= 0xffffffff;
521 /* 5. return to kernel instructions */
522 if (ka->ka_restorer) {
523 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
525 /* Flush instruction space. */
526 unsigned long address = ((unsigned long)&(sf->insns[0]));
527 pgd_t *pgdp = pgd_offset(current->mm, address);
528 pud_t *pudp = pud_offset(pgdp, address);
529 pmd_t *pmdp = pmd_offset(pudp, address);
533 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
535 err = __put_user(0x821020d8, &sf->insns[0]); /*mov __NR_sigreturn, %g1*/
536 err |= __put_user(0x91d02010, &sf->insns[1]); /*t 0x10*/
541 ptep = pte_offset_map(pmdp, address);
543 if (pte_present(pte)) {
544 unsigned long page = (unsigned long)
545 page_address(pte_page(pte));
548 __asm__ __volatile__("flush %0 + %1"
551 "r" (address & (PAGE_SIZE - 1))
562 force_sigsegv(signo, current);
565 static void setup_rt_frame32(struct k_sigaction *ka, struct pt_regs *regs,
566 unsigned long signr, sigset_t *oldset,
569 struct rt_signal_frame32 __user *sf;
573 compat_sigset_t seta;
575 /* 1. Make sure everything is clean */
576 synchronize_user_stack();
577 save_and_clear_fpu();
579 sigframe_size = RT_ALIGNEDSZ;
580 if (!(current_thread_info()->fpsaved[0] & FPRS_FEF))
581 sigframe_size -= sizeof(__siginfo_fpu_t);
583 sf = (struct rt_signal_frame32 __user *)
584 get_sigframe(&ka->sa, regs, sigframe_size);
586 if (invalid_frame_pointer(sf, sigframe_size))
589 if (get_thread_wsaved() != 0)
592 /* 2. Save the current process state */
593 if (test_thread_flag(TIF_32BIT)) {
594 regs->tpc &= 0xffffffff;
595 regs->tnpc &= 0xffffffff;
597 err = put_user(regs->tpc, &sf->regs.pc);
598 err |= __put_user(regs->tnpc, &sf->regs.npc);
599 err |= __put_user(regs->y, &sf->regs.y);
600 psr = tstate_to_psr(regs->tstate);
601 if (current_thread_info()->fpsaved[0] & FPRS_FEF)
603 err |= __put_user(psr, &sf->regs.psr);
604 for (i = 0; i < 16; i++)
605 err |= __put_user(regs->u_regs[i], &sf->regs.u_regs[i]);
606 err |= __put_user(sizeof(siginfo_extra_v8plus_t), &sf->extra_size);
607 err |= __put_user(SIGINFO_EXTRA_V8PLUS_MAGIC, &sf->v8plus.g_upper[0]);
608 for (i = 1; i < 16; i++)
609 err |= __put_user(((u32 *)regs->u_regs)[2*i],
610 &sf->v8plus.g_upper[i]);
611 err |= __put_user((regs->tstate & TSTATE_ASI) >> 24UL,
615 err |= save_fpu_state32(regs, &sf->fpu_state);
616 err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save);
618 err |= __put_user(0, &sf->fpu_save);
621 /* Update the siginfo structure. */
622 err |= copy_siginfo_to_user32(&sf->info, info);
624 /* Setup sigaltstack */
625 err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
626 err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
627 err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
629 switch (_NSIG_WORDS) {
630 case 4: seta.sig[7] = (oldset->sig[3] >> 32);
631 seta.sig[6] = oldset->sig[3];
632 case 3: seta.sig[5] = (oldset->sig[2] >> 32);
633 seta.sig[4] = oldset->sig[2];
634 case 2: seta.sig[3] = (oldset->sig[1] >> 32);
635 seta.sig[2] = oldset->sig[1];
636 case 1: seta.sig[1] = (oldset->sig[0] >> 32);
637 seta.sig[0] = oldset->sig[0];
639 err |= __copy_to_user(&sf->mask, &seta, sizeof(compat_sigset_t));
641 err |= copy_in_user((u32 __user *)sf,
642 (u32 __user *)(regs->u_regs[UREG_FP]),
643 sizeof(struct reg_window32));
647 /* 3. signal handler back-trampoline and parameters */
648 regs->u_regs[UREG_FP] = (unsigned long) sf;
649 regs->u_regs[UREG_I0] = signr;
650 regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
651 regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
653 /* 4. signal handler */
654 regs->tpc = (unsigned long) ka->sa.sa_handler;
655 regs->tnpc = (regs->tpc + 4);
656 if (test_thread_flag(TIF_32BIT)) {
657 regs->tpc &= 0xffffffff;
658 regs->tnpc &= 0xffffffff;
661 /* 5. return to kernel instructions */
663 regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
665 /* Flush instruction space. */
666 unsigned long address = ((unsigned long)&(sf->insns[0]));
667 pgd_t *pgdp = pgd_offset(current->mm, address);
668 pud_t *pudp = pud_offset(pgdp, address);
669 pmd_t *pmdp = pmd_offset(pudp, address);
672 regs->u_regs[UREG_I7] = (unsigned long) (&(sf->insns[0]) - 2);
674 /* mov __NR_rt_sigreturn, %g1 */
675 err |= __put_user(0x82102065, &sf->insns[0]);
678 err |= __put_user(0x91d02010, &sf->insns[1]);
683 ptep = pte_offset_map(pmdp, address);
684 if (pte_present(*ptep)) {
685 unsigned long page = (unsigned long)
686 page_address(pte_page(*ptep));
689 __asm__ __volatile__("flush %0 + %1"
692 "r" (address & (PAGE_SIZE - 1))
703 force_sigsegv(signr, current);
706 static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka,
708 sigset_t *oldset, struct pt_regs *regs)
710 if (ka->sa.sa_flags & SA_SIGINFO)
711 setup_rt_frame32(ka, regs, signr, oldset, info);
713 setup_frame32(ka, regs, signr, oldset);
715 spin_lock_irq(¤t->sighand->siglock);
716 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
717 if (!(ka->sa.sa_flags & SA_NOMASK))
718 sigaddset(¤t->blocked,signr);
720 spin_unlock_irq(¤t->sighand->siglock);
723 static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs,
724 struct sigaction *sa)
726 switch (regs->u_regs[UREG_I0]) {
727 case ERESTART_RESTARTBLOCK:
729 no_system_call_restart:
730 regs->u_regs[UREG_I0] = EINTR;
731 regs->tstate |= TSTATE_ICARRY;
734 if (!(sa->sa_flags & SA_RESTART))
735 goto no_system_call_restart;
738 regs->u_regs[UREG_I0] = orig_i0;
744 /* Note that 'init' is a special process: it doesn't get signals it doesn't
745 * want to handle. Thus you cannot kill init even with a SIGKILL even by
748 void do_signal32(sigset_t *oldset, struct pt_regs * regs,
749 struct signal_deliver_cookie *cookie)
751 struct k_sigaction ka;
755 signr = get_signal_to_deliver(&info, &ka, regs, cookie);
757 if (cookie->restart_syscall)
758 syscall_restart32(cookie->orig_i0, regs, &ka.sa);
759 handle_signal32(signr, &ka, &info, oldset, regs);
761 /* a signal was successfully delivered; the saved
762 * sigmask will have been stored in the signal frame,
763 * and will be restored by sigreturn, so we can simply
764 * clear the TIF_RESTORE_SIGMASK flag.
766 if (test_thread_flag(TIF_RESTORE_SIGMASK))
767 clear_thread_flag(TIF_RESTORE_SIGMASK);
770 if (cookie->restart_syscall &&
771 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
772 regs->u_regs[UREG_I0] == ERESTARTSYS ||
773 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
774 /* replay the system call when we are done */
775 regs->u_regs[UREG_I0] = cookie->orig_i0;
779 if (cookie->restart_syscall &&
780 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
781 regs->u_regs[UREG_G1] = __NR_restart_syscall;
786 /* if there's no signal to deliver, we just put the saved sigmask
789 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
790 clear_thread_flag(TIF_RESTORE_SIGMASK);
791 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
800 asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp)
802 struct sigstack32 __user *ssptr =
803 (struct sigstack32 __user *)((unsigned long)(u_ssptr));
804 struct sigstack32 __user *ossptr =
805 (struct sigstack32 __user *)((unsigned long)(u_ossptr));
808 /* First see if old state is wanted. */
810 if (put_user(current->sas_ss_sp + current->sas_ss_size,
811 &ossptr->the_stack) ||
812 __put_user(on_sig_stack(sp), &ossptr->cur_status))
816 /* Now see if we want to update the new state. */
820 if (get_user(ss_sp, &ssptr->the_stack))
823 /* If the current stack was set with sigaltstack, don't
824 * swap stacks while we are on it.
827 if (current->sas_ss_sp && on_sig_stack(sp))
830 /* Since we don't know the extent of the stack, and we don't
831 * track onstack-ness, but rather calculate it, we must
832 * presume a size. Ho hum this interface is lossy.
834 current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
835 current->sas_ss_size = SIGSTKSZ;
843 asmlinkage long do_sys32_sigaltstack(u32 ussa, u32 uossa, unsigned long sp)
849 stack_t32 __user *uss32 = compat_ptr(ussa);
850 stack_t32 __user *uoss32 = compat_ptr(uossa);
852 if (ussa && (get_user(u_ss_sp, &uss32->ss_sp) ||
853 __get_user(uss.ss_flags, &uss32->ss_flags) ||
854 __get_user(uss.ss_size, &uss32->ss_size)))
856 uss.ss_sp = compat_ptr(u_ss_sp);
859 ret = do_sigaltstack(ussa ? (stack_t __user *) &uss : NULL,
860 uossa ? (stack_t __user *) &uoss : NULL, sp);
862 if (!ret && uossa && (put_user(ptr_to_compat(uoss.ss_sp), &uoss32->ss_sp) ||
863 __put_user(uoss.ss_flags, &uoss32->ss_flags) ||
864 __put_user(uoss.ss_size, &uoss32->ss_size)))