2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000, 2006 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10 #include <linux/cache.h>
11 #include <linux/sched.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/kernel.h>
16 #include <linux/signal.h>
17 #include <linux/syscalls.h>
18 #include <linux/errno.h>
19 #include <linux/wait.h>
20 #include <linux/ptrace.h>
21 #include <linux/compat.h>
22 #include <linux/suspend.h>
23 #include <linux/compiler.h>
27 #include <linux/bitops.h>
28 #include <asm/cacheflush.h>
30 #include <asm/uaccess.h>
31 #include <asm/ucontext.h>
32 #include <asm/system.h>
36 #define SI_PAD_SIZE32 ((SI_MAX_SIZE/sizeof(int)) - 3)
38 typedef struct compat_siginfo
{
44 int _pad
[SI_PAD_SIZE32
];
48 compat_pid_t _pid
; /* sender's pid */
49 compat_uid_t _uid
; /* sender's uid */
54 compat_pid_t _pid
; /* which child */
55 compat_uid_t _uid
; /* sender's uid */
56 int _status
; /* exit code */
57 compat_clock_t _utime
;
58 compat_clock_t _stime
;
63 compat_pid_t _pid
; /* which child */
64 compat_clock_t _utime
;
65 int _status
; /* exit code */
66 compat_clock_t _stime
;
69 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
71 s32 _addr
; /* faulting insn/memory ref. */
74 /* SIGPOLL, SIGXFSZ (To do ...) */
76 int _band
; /* POLL_IN, POLL_OUT, POLL_MSG */
82 timer_t _tid
; /* timer id */
83 int _overrun
; /* overrun count */
84 compat_sigval_t _sigval
;/* same as below */
85 int _sys_private
; /* not to be passed to user */
88 /* POSIX.1b signals */
90 compat_pid_t _pid
; /* sender's pid */
91 compat_uid_t _uid
; /* sender's uid */
92 compat_sigval_t _sigval
;
99 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
101 #define __NR_O32_sigreturn 4119
102 #define __NR_O32_rt_sigreturn 4193
103 #define __NR_O32_restart_syscall 4253
107 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
109 /* 32-bit compatibility types */
111 #define _NSIG_BPW32 32
112 #define _NSIG_WORDS32 (_NSIG / _NSIG_BPW32)
115 unsigned int sig
[_NSIG_WORDS32
];
118 typedef unsigned int __sighandler32_t
;
119 typedef void (*vfptr_t
)(void);
122 unsigned int sa_flags
;
123 __sighandler32_t sa_handler
;
124 compat_sigset_t sa_mask
;
127 /* IRIX compatible stack_t */
128 typedef struct sigaltstack32
{
130 compat_size_t ss_size
;
138 struct sigcontext32 uc_mcontext
;
139 sigset_t32 uc_sigmask
; /* mask last for extensibility */
142 extern void __put_sigset_unknown_nsig(void);
143 extern void __get_sigset_unknown_nsig(void);
145 static inline int put_sigset(const sigset_t
*kbuf
, compat_sigset_t __user
*ubuf
)
149 if (!access_ok(VERIFY_WRITE
, ubuf
, sizeof(*ubuf
)))
152 switch (_NSIG_WORDS
) {
154 __put_sigset_unknown_nsig();
156 err
|= __put_user (kbuf
->sig
[1] >> 32, &ubuf
->sig
[3]);
157 err
|= __put_user (kbuf
->sig
[1] & 0xffffffff, &ubuf
->sig
[2]);
159 err
|= __put_user (kbuf
->sig
[0] >> 32, &ubuf
->sig
[1]);
160 err
|= __put_user (kbuf
->sig
[0] & 0xffffffff, &ubuf
->sig
[0]);
166 static inline int get_sigset(sigset_t
*kbuf
, const compat_sigset_t __user
*ubuf
)
169 unsigned long sig
[4];
171 if (!access_ok(VERIFY_READ
, ubuf
, sizeof(*ubuf
)))
174 switch (_NSIG_WORDS
) {
176 __get_sigset_unknown_nsig();
178 err
|= __get_user (sig
[3], &ubuf
->sig
[3]);
179 err
|= __get_user (sig
[2], &ubuf
->sig
[2]);
180 kbuf
->sig
[1] = sig
[2] | (sig
[3] << 32);
182 err
|= __get_user (sig
[1], &ubuf
->sig
[1]);
183 err
|= __get_user (sig
[0], &ubuf
->sig
[0]);
184 kbuf
->sig
[0] = sig
[0] | (sig
[1] << 32);
191 * Atomically swap in the new signal mask, and wait for a signal.
194 save_static_function(sys32_sigsuspend
);
195 __attribute_used__ noinline
static int
196 _sys32_sigsuspend(nabi_no_regargs
struct pt_regs regs
)
198 compat_sigset_t __user
*uset
;
201 uset
= (compat_sigset_t __user
*) regs
.regs
[4];
202 if (get_sigset(&newset
, uset
))
204 sigdelsetmask(&newset
, ~_BLOCKABLE
);
206 spin_lock_irq(¤t
->sighand
->siglock
);
207 current
->saved_sigmask
= current
->blocked
;
208 current
->blocked
= newset
;
210 spin_unlock_irq(¤t
->sighand
->siglock
);
212 current
->state
= TASK_INTERRUPTIBLE
;
214 set_thread_flag(TIF_RESTORE_SIGMASK
);
215 return -ERESTARTNOHAND
;
218 save_static_function(sys32_rt_sigsuspend
);
219 __attribute_used__ noinline
static int
220 _sys32_rt_sigsuspend(nabi_no_regargs
struct pt_regs regs
)
222 compat_sigset_t __user
*uset
;
226 /* XXX Don't preclude handling different sized sigset_t's. */
227 sigsetsize
= regs
.regs
[5];
228 if (sigsetsize
!= sizeof(compat_sigset_t
))
231 uset
= (compat_sigset_t __user
*) regs
.regs
[4];
232 if (get_sigset(&newset
, uset
))
234 sigdelsetmask(&newset
, ~_BLOCKABLE
);
236 spin_lock_irq(¤t
->sighand
->siglock
);
237 current
->saved_sigmask
= current
->blocked
;
238 current
->blocked
= newset
;
240 spin_unlock_irq(¤t
->sighand
->siglock
);
242 current
->state
= TASK_INTERRUPTIBLE
;
244 set_thread_flag(TIF_RESTORE_SIGMASK
);
245 return -ERESTARTNOHAND
;
248 asmlinkage
int sys32_sigaction(int sig
, const struct sigaction32 __user
*act
,
249 struct sigaction32 __user
*oact
)
251 struct k_sigaction new_ka
, old_ka
;
259 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)))
261 err
|= __get_user(handler
, &act
->sa_handler
);
262 new_ka
.sa
.sa_handler
= (void __user
*)(s64
)handler
;
263 err
|= __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
264 err
|= __get_user(mask
, &act
->sa_mask
.sig
[0]);
268 siginitset(&new_ka
.sa
.sa_mask
, mask
);
271 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
274 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)))
276 err
|= __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
277 err
|= __put_user((u32
)(u64
)old_ka
.sa
.sa_handler
,
279 err
|= __put_user(old_ka
.sa
.sa_mask
.sig
[0], oact
->sa_mask
.sig
);
280 err
|= __put_user(0, &oact
->sa_mask
.sig
[1]);
281 err
|= __put_user(0, &oact
->sa_mask
.sig
[2]);
282 err
|= __put_user(0, &oact
->sa_mask
.sig
[3]);
290 asmlinkage
int sys32_sigaltstack(nabi_no_regargs
struct pt_regs regs
)
292 const stack32_t __user
*uss
= (const stack32_t __user
*) regs
.regs
[4];
293 stack32_t __user
*uoss
= (stack32_t __user
*) regs
.regs
[5];
294 unsigned long usp
= regs
.regs
[29];
297 mm_segment_t old_fs
= get_fs();
301 if (!access_ok(VERIFY_READ
, uss
, sizeof(*uss
)))
303 err
|= __get_user(sp
, &uss
->ss_sp
);
304 kss
.ss_sp
= (void __user
*) (long) sp
;
305 err
|= __get_user(kss
.ss_size
, &uss
->ss_size
);
306 err
|= __get_user(kss
.ss_flags
, &uss
->ss_flags
);
312 ret
= do_sigaltstack(uss
? (stack_t __user
*)&kss
: NULL
,
313 uoss
? (stack_t __user
*)&koss
: NULL
, usp
);
317 if (!access_ok(VERIFY_WRITE
, uoss
, sizeof(*uoss
)))
319 sp
= (int) (unsigned long) koss
.ss_sp
;
320 err
|= __put_user(sp
, &uoss
->ss_sp
);
321 err
|= __put_user(koss
.ss_size
, &uoss
->ss_size
);
322 err
|= __put_user(koss
.ss_flags
, &uoss
->ss_flags
);
329 static int restore_sigcontext32(struct pt_regs
*regs
, struct sigcontext32 __user
*sc
)
335 /* Always make any pending restarted system calls return -EINTR */
336 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
338 err
|= __get_user(regs
->cp0_epc
, &sc
->sc_pc
);
339 err
|= __get_user(regs
->hi
, &sc
->sc_mdhi
);
340 err
|= __get_user(regs
->lo
, &sc
->sc_mdlo
);
342 err
|= __get_user(treg
, &sc
->sc_hi1
); mthi1(treg
);
343 err
|= __get_user(treg
, &sc
->sc_lo1
); mtlo1(treg
);
344 err
|= __get_user(treg
, &sc
->sc_hi2
); mthi2(treg
);
345 err
|= __get_user(treg
, &sc
->sc_lo2
); mtlo2(treg
);
346 err
|= __get_user(treg
, &sc
->sc_hi3
); mthi3(treg
);
347 err
|= __get_user(treg
, &sc
->sc_lo3
); mtlo3(treg
);
348 err
|= __get_user(treg
, &sc
->sc_dsp
); wrdsp(treg
, DSP_MASK
);
351 #define restore_gp_reg(i) do { \
352 err |= __get_user(regs->regs[i], &sc->sc_regs[i]); \
354 restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
355 restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
356 restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
357 restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
358 restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
359 restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
360 restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
361 restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
362 restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
363 restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
365 #undef restore_gp_reg
367 err
|= __get_user(used_math
, &sc
->sc_used_math
);
368 conditional_used_math(used_math
);
373 /* restore fpu context if we have used it before */
375 err
|= restore_fp_context32(sc
);
377 /* signal handler may have used FPU. Give it up. */
387 u32 sf_ass
[4]; /* argument save space for o32 */
388 #if ICACHE_REFILLS_WORKAROUND_WAR
391 u32 sf_code
[2]; /* signal trampoline */
393 struct sigcontext32 sf_sc
;
395 #if ICACHE_REFILLS_WORKAROUND_WAR
396 u32 sf_code
[8] ____cacheline_aligned
; /* signal trampoline */
400 struct rt_sigframe32
{
401 u32 rs_ass
[4]; /* argument save space for o32 */
402 #if ICACHE_REFILLS_WORKAROUND_WAR
405 u32 rs_code
[2]; /* signal trampoline */
407 compat_siginfo_t rs_info
;
408 struct ucontext32 rs_uc
;
409 #if ICACHE_REFILLS_WORKAROUND_WAR
410 u32 rs_code
[8] __attribute__((aligned(32))); /* signal trampoline */
414 int copy_siginfo_to_user32(compat_siginfo_t __user
*to
, siginfo_t
*from
)
418 if (!access_ok (VERIFY_WRITE
, to
, sizeof(compat_siginfo_t
)))
421 /* If you change siginfo_t structure, please be sure
422 this code is fixed accordingly.
423 It should never copy any pad contained in the structure
424 to avoid security leaks, but must copy the generic
425 3 ints plus the relevant union member.
426 This routine must convert siginfo from 64bit to 32bit as well
428 err
= __put_user(from
->si_signo
, &to
->si_signo
);
429 err
|= __put_user(from
->si_errno
, &to
->si_errno
);
430 err
|= __put_user((short)from
->si_code
, &to
->si_code
);
431 if (from
->si_code
< 0)
432 err
|= __copy_to_user(&to
->_sifields
._pad
, &from
->_sifields
._pad
, SI_PAD_SIZE
);
434 switch (from
->si_code
>> 16) {
435 case __SI_TIMER
>> 16:
436 err
|= __put_user(from
->si_tid
, &to
->si_tid
);
437 err
|= __put_user(from
->si_overrun
, &to
->si_overrun
);
438 err
|= __put_user(from
->si_int
, &to
->si_int
);
440 case __SI_CHLD
>> 16:
441 err
|= __put_user(from
->si_utime
, &to
->si_utime
);
442 err
|= __put_user(from
->si_stime
, &to
->si_stime
);
443 err
|= __put_user(from
->si_status
, &to
->si_status
);
445 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
446 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
448 case __SI_FAULT
>> 16:
449 err
|= __put_user((unsigned long)from
->si_addr
, &to
->si_addr
);
451 case __SI_POLL
>> 16:
452 err
|= __put_user(from
->si_band
, &to
->si_band
);
453 err
|= __put_user(from
->si_fd
, &to
->si_fd
);
455 case __SI_RT
>> 16: /* This is not generated by the kernel as of now. */
456 case __SI_MESGQ
>> 16:
457 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
458 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
459 err
|= __put_user(from
->si_int
, &to
->si_int
);
466 save_static_function(sys32_sigreturn
);
467 __attribute_used__ noinline
static void
468 _sys32_sigreturn(nabi_no_regargs
struct pt_regs regs
)
470 struct sigframe __user
*frame
;
473 frame
= (struct sigframe __user
*) regs
.regs
[29];
474 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
476 if (__copy_from_user(&blocked
, &frame
->sf_mask
, sizeof(blocked
)))
479 sigdelsetmask(&blocked
, ~_BLOCKABLE
);
480 spin_lock_irq(¤t
->sighand
->siglock
);
481 current
->blocked
= blocked
;
483 spin_unlock_irq(¤t
->sighand
->siglock
);
485 if (restore_sigcontext32(®s
, &frame
->sf_sc
))
489 * Don't let your children do this ...
491 __asm__
__volatile__(
499 force_sig(SIGSEGV
, current
);
502 save_static_function(sys32_rt_sigreturn
);
503 __attribute_used__ noinline
static void
504 _sys32_rt_sigreturn(nabi_no_regargs
struct pt_regs regs
)
506 struct rt_sigframe32 __user
*frame
;
512 frame
= (struct rt_sigframe32 __user
*) regs
.regs
[29];
513 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
515 if (__copy_from_user(&set
, &frame
->rs_uc
.uc_sigmask
, sizeof(set
)))
518 sigdelsetmask(&set
, ~_BLOCKABLE
);
519 spin_lock_irq(¤t
->sighand
->siglock
);
520 current
->blocked
= set
;
522 spin_unlock_irq(¤t
->sighand
->siglock
);
524 if (restore_sigcontext32(®s
, &frame
->rs_uc
.uc_mcontext
))
527 /* The ucontext contains a stack32_t, so we must convert! */
528 if (__get_user(sp
, &frame
->rs_uc
.uc_stack
.ss_sp
))
530 st
.ss_sp
= (void __user
*)(long) sp
;
531 if (__get_user(st
.ss_size
, &frame
->rs_uc
.uc_stack
.ss_size
))
533 if (__get_user(st
.ss_flags
, &frame
->rs_uc
.uc_stack
.ss_flags
))
536 /* It is more difficult to avoid calling this function than to
537 call it and ignore errors. */
540 do_sigaltstack((stack_t __user
*)&st
, NULL
, regs
.regs
[29]);
544 * Don't let your children do this ...
546 __asm__
__volatile__(
554 force_sig(SIGSEGV
, current
);
557 static inline int setup_sigcontext32(struct pt_regs
*regs
,
558 struct sigcontext32 __user
*sc
)
562 err
|= __put_user(regs
->cp0_epc
, &sc
->sc_pc
);
563 err
|= __put_user(regs
->cp0_status
, &sc
->sc_status
);
565 #define save_gp_reg(i) { \
566 err |= __put_user(regs->regs[i], &sc->sc_regs[i]); \
568 __put_user(0, &sc
->sc_regs
[0]); save_gp_reg(1); save_gp_reg(2);
569 save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
570 save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
571 save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
572 save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
573 save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
574 save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
575 save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
579 err
|= __put_user(regs
->hi
, &sc
->sc_mdhi
);
580 err
|= __put_user(regs
->lo
, &sc
->sc_mdlo
);
582 err
|= __put_user(rddsp(DSP_MASK
), &sc
->sc_dsp
);
583 err
|= __put_user(mfhi1(), &sc
->sc_hi1
);
584 err
|= __put_user(mflo1(), &sc
->sc_lo1
);
585 err
|= __put_user(mfhi2(), &sc
->sc_hi2
);
586 err
|= __put_user(mflo2(), &sc
->sc_lo2
);
587 err
|= __put_user(mfhi3(), &sc
->sc_hi3
);
588 err
|= __put_user(mflo3(), &sc
->sc_lo3
);
591 err
|= __put_user(!!used_math(), &sc
->sc_used_math
);
597 * Save FPU state to signal context. Signal handler will "inherit"
602 if (!is_fpu_owner()) {
606 err
|= save_fp_context32(sc
);
615 * Determine which stack to use..
617 static inline void __user
*get_sigframe(struct k_sigaction
*ka
,
618 struct pt_regs
*regs
,
623 /* Default to using normal stack */
627 * FPU emulator may have it's own trampoline active just
628 * above the user stack, 16-bytes before the next lowest
629 * 16 byte boundary. Try to avoid trashing it.
633 /* This is the X/Open sanctioned signal stack switching. */
634 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) && (sas_ss_flags (sp
) == 0))
635 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
637 return (void __user
*)((sp
- frame_size
) & ALMASK
);
640 int setup_frame_32(struct k_sigaction
* ka
, struct pt_regs
*regs
,
641 int signr
, sigset_t
*set
)
643 struct sigframe __user
*frame
;
646 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
647 if (!access_ok(VERIFY_WRITE
, frame
, sizeof (*frame
)))
651 * Set up the return code ...
653 * li v0, __NR_O32_sigreturn
656 err
|= __put_user(0x24020000 + __NR_O32_sigreturn
, frame
->sf_code
+ 0);
657 err
|= __put_user(0x0000000c , frame
->sf_code
+ 1);
658 flush_cache_sigtramp((unsigned long) frame
->sf_code
);
660 err
|= setup_sigcontext32(regs
, &frame
->sf_sc
);
661 err
|= __copy_to_user(&frame
->sf_mask
, set
, sizeof(*set
));
666 * Arguments to signal handler:
669 * a1 = 0 (should be cause)
670 * a2 = pointer to struct sigcontext
672 * $25 and c0_epc point to the signal handler, $29 points to the
675 regs
->regs
[ 4] = signr
;
677 regs
->regs
[ 6] = (unsigned long) &frame
->sf_sc
;
678 regs
->regs
[29] = (unsigned long) frame
;
679 regs
->regs
[31] = (unsigned long) frame
->sf_code
;
680 regs
->cp0_epc
= regs
->regs
[25] = (unsigned long) ka
->sa
.sa_handler
;
683 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
684 current
->comm
, current
->pid
,
685 frame
, regs
->cp0_epc
, frame
->sf_code
);
690 force_sigsegv(signr
, current
);
694 int setup_rt_frame_32(struct k_sigaction
* ka
, struct pt_regs
*regs
,
695 int signr
, sigset_t
*set
, siginfo_t
*info
)
697 struct rt_sigframe32 __user
*frame
;
701 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
702 if (!access_ok(VERIFY_WRITE
, frame
, sizeof (*frame
)))
705 /* Set up to return from userspace. If provided, use a stub already
708 * Set up the return code ...
710 * li v0, __NR_O32_rt_sigreturn
713 err
|= __put_user(0x24020000 + __NR_O32_rt_sigreturn
, frame
->rs_code
+ 0);
714 err
|= __put_user(0x0000000c , frame
->rs_code
+ 1);
715 flush_cache_sigtramp((unsigned long) frame
->rs_code
);
717 /* Convert (siginfo_t -> compat_siginfo_t) and copy to user. */
718 err
|= copy_siginfo_to_user32(&frame
->rs_info
, info
);
720 /* Create the ucontext. */
721 err
|= __put_user(0, &frame
->rs_uc
.uc_flags
);
722 err
|= __put_user(0, &frame
->rs_uc
.uc_link
);
723 sp
= (int) (long) current
->sas_ss_sp
;
724 err
|= __put_user(sp
,
725 &frame
->rs_uc
.uc_stack
.ss_sp
);
726 err
|= __put_user(sas_ss_flags(regs
->regs
[29]),
727 &frame
->rs_uc
.uc_stack
.ss_flags
);
728 err
|= __put_user(current
->sas_ss_size
,
729 &frame
->rs_uc
.uc_stack
.ss_size
);
730 err
|= setup_sigcontext32(regs
, &frame
->rs_uc
.uc_mcontext
);
731 err
|= __copy_to_user(&frame
->rs_uc
.uc_sigmask
, set
, sizeof(*set
));
737 * Arguments to signal handler:
740 * a1 = 0 (should be cause)
741 * a2 = pointer to ucontext
743 * $25 and c0_epc point to the signal handler, $29 points to
744 * the struct rt_sigframe32.
746 regs
->regs
[ 4] = signr
;
747 regs
->regs
[ 5] = (unsigned long) &frame
->rs_info
;
748 regs
->regs
[ 6] = (unsigned long) &frame
->rs_uc
;
749 regs
->regs
[29] = (unsigned long) frame
;
750 regs
->regs
[31] = (unsigned long) frame
->rs_code
;
751 regs
->cp0_epc
= regs
->regs
[25] = (unsigned long) ka
->sa
.sa_handler
;
754 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
755 current
->comm
, current
->pid
,
756 frame
, regs
->cp0_epc
, frame
->rs_code
);
761 force_sigsegv(signr
, current
);
765 static inline int handle_signal(unsigned long sig
, siginfo_t
*info
,
766 struct k_sigaction
*ka
, sigset_t
*oldset
, struct pt_regs
* regs
)
770 switch (regs
->regs
[0]) {
771 case ERESTART_RESTARTBLOCK
:
773 regs
->regs
[2] = EINTR
;
776 if (!(ka
->sa
.sa_flags
& SA_RESTART
)) {
777 regs
->regs
[2] = EINTR
;
781 case ERESTARTNOINTR
: /* Userland will reload $v0. */
782 regs
->regs
[7] = regs
->regs
[26];
786 regs
->regs
[0] = 0; /* Don't deal with this again. */
788 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
789 ret
= current
->thread
.abi
->setup_rt_frame(ka
, regs
, sig
, oldset
, info
);
791 ret
= current
->thread
.abi
->setup_frame(ka
, regs
, sig
, oldset
);
793 spin_lock_irq(¤t
->sighand
->siglock
);
794 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
795 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
796 sigaddset(¤t
->blocked
,sig
);
798 spin_unlock_irq(¤t
->sighand
->siglock
);
803 void do_signal32(struct pt_regs
*regs
)
805 struct k_sigaction ka
;
811 * We want the common case to go fast, which is why we may in certain
812 * cases get here from kernel mode. Just return without doing anything
815 if (!user_mode(regs
))
821 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
822 oldset
= ¤t
->saved_sigmask
;
824 oldset
= ¤t
->blocked
;
826 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
828 /* Whee! Actually deliver the signal. */
829 if (handle_signal(signr
, &info
, &ka
, oldset
, regs
) == 0) {
831 * A signal was successfully delivered; the saved
832 * sigmask will have been stored in the signal frame,
833 * and will be restored by sigreturn, so we can simply
834 * clear the TIF_RESTORE_SIGMASK flag.
836 if (test_thread_flag(TIF_RESTORE_SIGMASK
))
837 clear_thread_flag(TIF_RESTORE_SIGMASK
);
843 * Who's code doesn't conform to the restartable syscall convention
844 * dies here!!! The li instruction, a single machine instruction,
845 * must directly be followed by the syscall instruction.
848 if (regs
->regs
[2] == ERESTARTNOHAND
||
849 regs
->regs
[2] == ERESTARTSYS
||
850 regs
->regs
[2] == ERESTARTNOINTR
) {
851 regs
->regs
[7] = regs
->regs
[26];
854 if (regs
->regs
[2] == ERESTART_RESTARTBLOCK
) {
855 regs
->regs
[2] = __NR_O32_restart_syscall
;
856 regs
->regs
[7] = regs
->regs
[26];
862 * If there's no signal to deliver, we just put the saved sigmask
865 if (test_thread_flag(TIF_RESTORE_SIGMASK
)) {
866 clear_thread_flag(TIF_RESTORE_SIGMASK
);
867 sigprocmask(SIG_SETMASK
, ¤t
->saved_sigmask
, NULL
);
871 asmlinkage
int sys32_rt_sigaction(int sig
, const struct sigaction32 __user
*act
,
872 struct sigaction32 __user
*oact
,
873 unsigned int sigsetsize
)
875 struct k_sigaction new_sa
, old_sa
;
878 /* XXX: Don't preclude handling different sized sigset_t's. */
879 if (sigsetsize
!= sizeof(sigset_t
))
886 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)))
888 err
|= __get_user(handler
, &act
->sa_handler
);
889 new_sa
.sa
.sa_handler
= (void __user
*)(s64
)handler
;
890 err
|= __get_user(new_sa
.sa
.sa_flags
, &act
->sa_flags
);
891 err
|= get_sigset(&new_sa
.sa
.sa_mask
, &act
->sa_mask
);
896 ret
= do_sigaction(sig
, act
? &new_sa
: NULL
, oact
? &old_sa
: NULL
);
901 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)))
904 err
|= __put_user((u32
)(u64
)old_sa
.sa
.sa_handler
,
906 err
|= __put_user(old_sa
.sa
.sa_flags
, &oact
->sa_flags
);
907 err
|= put_sigset(&old_sa
.sa
.sa_mask
, &oact
->sa_mask
);
915 asmlinkage
int sys32_rt_sigprocmask(int how
, compat_sigset_t __user
*set
,
916 compat_sigset_t __user
*oset
, unsigned int sigsetsize
)
918 sigset_t old_set
, new_set
;
920 mm_segment_t old_fs
= get_fs();
922 if (set
&& get_sigset(&new_set
, set
))
926 ret
= sys_rt_sigprocmask(how
, set
? (sigset_t __user
*)&new_set
: NULL
,
927 oset
? (sigset_t __user
*)&old_set
: NULL
,
931 if (!ret
&& oset
&& put_sigset(&old_set
, oset
))
937 asmlinkage
int sys32_rt_sigpending(compat_sigset_t __user
*uset
,
938 unsigned int sigsetsize
)
942 mm_segment_t old_fs
= get_fs();
945 ret
= sys_rt_sigpending((sigset_t __user
*)&set
, sigsetsize
);
948 if (!ret
&& put_sigset(&set
, uset
))
954 asmlinkage
int sys32_rt_sigqueueinfo(int pid
, int sig
, compat_siginfo_t __user
*uinfo
)
958 mm_segment_t old_fs
= get_fs();
960 if (copy_from_user (&info
, uinfo
, 3*sizeof(int)) ||
961 copy_from_user (info
._sifields
._pad
, uinfo
->_sifields
._pad
, SI_PAD_SIZE
))
964 ret
= sys_rt_sigqueueinfo(pid
, sig
, (siginfo_t __user
*)&info
);
970 sys32_waitid(int which
, compat_pid_t pid
,
971 compat_siginfo_t __user
*uinfo
, int options
,
972 struct compat_rusage __user
*uru
)
977 mm_segment_t old_fs
= get_fs();
981 ret
= sys_waitid(which
, pid
, (siginfo_t __user
*) &info
, options
,
982 uru
? (struct rusage __user
*) &ru
: NULL
);
985 if (ret
< 0 || info
.si_signo
== 0)
988 if (uru
&& (ret
= put_compat_rusage(&ru
, uru
)))
991 BUG_ON(info
.si_code
& __SI_MASK
);
992 info
.si_code
|= __SI_CHLD
;
993 return copy_siginfo_to_user32(uinfo
, &info
);