2 * irixsig.c: WHEEE, IRIX signals! YOW, am I compatible or what?!?!
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 * Copyright (C) 1997 - 2000 Ralf Baechle (ralf@gnu.org)
6 * Copyright (C) 2000 Silicon Graphics, Inc.
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
11 #include <linux/errno.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.h>
14 #include <linux/time.h>
15 #include <linux/ptrace.h>
17 #include <asm/ptrace.h>
18 #include <asm/uaccess.h>
22 #define _S(nr) (1<<((nr)-1))
24 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
31 u32 rmask
, cp0_status
;
35 u32 usedfp
, fpcsr
, fpeir
, sstk_flags
;
37 u64 cp0_cause
, cp0_badvaddr
, _unused0
;
45 static inline void dump_irix5_sigctx(struct sigctx_irix5
*c
)
49 printk("misc: rmask[%08lx] status[%08lx] pc[%08lx]\n",
50 (unsigned long) c
->rmask
,
51 (unsigned long) c
->cp0_status
,
52 (unsigned long) c
->pc
);
54 for(i
= 0; i
< 16; i
++)
55 printk("[%d]<%08lx> ", i
, (unsigned long) c
->regs
[i
]);
57 for(i
= 16; i
< 32; i
++)
58 printk("[%d]<%08lx> ", i
, (unsigned long) c
->regs
[i
]);
60 for(i
= 0; i
< 16; i
++)
61 printk("[%d]<%08lx> ", i
, (unsigned long) c
->fpregs
[i
]);
63 for(i
= 16; i
< 32; i
++)
64 printk("[%d]<%08lx> ", i
, (unsigned long) c
->fpregs
[i
]);
65 printk("misc: usedfp[%d] fpcsr[%08lx] fpeir[%08lx] stk_flgs[%08lx]\n",
66 (int) c
->usedfp
, (unsigned long) c
->fpcsr
,
67 (unsigned long) c
->fpeir
, (unsigned long) c
->sstk_flags
);
68 printk("misc: hi[%08lx] lo[%08lx] cause[%08lx] badvaddr[%08lx]\n",
69 (unsigned long) c
->hi
, (unsigned long) c
->lo
,
70 (unsigned long) c
->cp0_cause
, (unsigned long) c
->cp0_badvaddr
);
71 printk("misc: sigset<0>[%08lx] sigset<1>[%08lx] sigset<2>[%08lx] "
72 "sigset<3>[%08lx]\n", (unsigned long) c
->sigset
.sig
[0],
73 (unsigned long) c
->sigset
.sig
[1],
74 (unsigned long) c
->sigset
.sig
[2],
75 (unsigned long) c
->sigset
.sig
[3]);
79 static void setup_irix_frame(struct k_sigaction
*ka
, struct pt_regs
*regs
,
80 int signr
, sigset_t
*oldmask
)
83 struct sigctx_irix5
*ctx
;
87 sp
-= sizeof(struct sigctx_irix5
);
89 ctx
= (struct sigctx_irix5
*) sp
;
90 if (!access_ok(VERIFY_WRITE
, ctx
, sizeof(*ctx
)))
93 __put_user(0, &ctx
->weird_fpu_thing
);
94 __put_user(~(0x00000001), &ctx
->rmask
);
95 __put_user(0, &ctx
->regs
[0]);
96 for(i
= 1; i
< 32; i
++)
97 __put_user((u64
) regs
->regs
[i
], &ctx
->regs
[i
]);
99 __put_user((u64
) regs
->hi
, &ctx
->hi
);
100 __put_user((u64
) regs
->lo
, &ctx
->lo
);
101 __put_user((u64
) regs
->cp0_epc
, &ctx
->pc
);
102 __put_user(!!used_math(), &ctx
->usedfp
);
103 __put_user((u64
) regs
->cp0_cause
, &ctx
->cp0_cause
);
104 __put_user((u64
) regs
->cp0_badvaddr
, &ctx
->cp0_badvaddr
);
106 __put_user(0, &ctx
->sstk_flags
); /* XXX sigstack unimp... todo... */
108 __copy_to_user(&ctx
->sigset
, oldmask
, sizeof(irix_sigset_t
));
111 dump_irix5_sigctx(ctx
);
114 regs
->regs
[4] = (unsigned long) signr
;
115 regs
->regs
[5] = 0; /* XXX sigcode XXX */
116 regs
->regs
[6] = regs
->regs
[29] = sp
;
117 regs
->regs
[7] = (unsigned long) ka
->sa
.sa_handler
;
118 regs
->regs
[25] = regs
->cp0_epc
= (unsigned long) ka
->sa_restorer
;
123 force_sigsegv(signr
, current
);
127 setup_irix_rt_frame(struct k_sigaction
* ka
, struct pt_regs
*regs
,
128 int signr
, sigset_t
*oldmask
, siginfo_t
*info
)
130 printk("Aiee: setup_tr_frame wants to be written");
134 static inline void handle_signal(unsigned long sig
, siginfo_t
*info
,
135 struct k_sigaction
*ka
, sigset_t
*oldset
, struct pt_regs
* regs
)
137 switch(regs
->regs
[0]) {
139 regs
->regs
[2] = EINTR
;
142 if(!(ka
->sa
.sa_flags
& SA_RESTART
)) {
143 regs
->regs
[2] = EINTR
;
147 case ERESTARTNOINTR
: /* Userland will reload $v0. */
151 regs
->regs
[0] = 0; /* Don't deal with this again. */
153 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
154 setup_irix_rt_frame(ka
, regs
, sig
, oldset
, info
);
156 setup_irix_frame(ka
, regs
, sig
, oldset
);
158 if (!(ka
->sa
.sa_flags
& SA_NODEFER
)) {
159 spin_lock_irq(¤t
->sighand
->siglock
);
160 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
161 sigaddset(¤t
->blocked
,sig
);
163 spin_unlock_irq(¤t
->sighand
->siglock
);
167 asmlinkage
int do_irix_signal(sigset_t
*oldset
, struct pt_regs
*regs
)
169 struct k_sigaction ka
;
174 * We want the common case to go fast, which is why we may in certain
175 * cases get here from kernel mode. Just return without doing anything
178 if (!user_mode(regs
))
181 if (try_to_freeze(0))
185 oldset
= ¤t
->blocked
;
187 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
189 handle_signal(signr
, &info
, &ka
, oldset
, regs
);
195 * Who's code doesn't conform to the restartable syscall convention
196 * dies here!!! The li instruction, a single machine instruction,
197 * must directly be followed by the syscall instruction.
200 if (regs
->regs
[2] == ERESTARTNOHAND
||
201 regs
->regs
[2] == ERESTARTSYS
||
202 regs
->regs
[2] == ERESTARTNOINTR
) {
210 irix_sigreturn(struct pt_regs
*regs
)
212 struct sigctx_irix5
*context
, *magic
;
213 unsigned long umask
, mask
;
215 int sig
, i
, base
= 0;
218 /* Always make any pending restarted system calls return -EINTR */
219 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
221 if (regs
->regs
[2] == 1000)
224 context
= (struct sigctx_irix5
*) regs
->regs
[base
+ 4];
225 magic
= (struct sigctx_irix5
*) regs
->regs
[base
+ 5];
226 sig
= (int) regs
->regs
[base
+ 6];
228 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
229 current
->comm
, current
->pid
, context
, magic
, sig
);
233 if (!access_ok(VERIFY_READ
, context
, sizeof(struct sigctx_irix5
)))
237 dump_irix5_sigctx(context
);
240 __get_user(regs
->cp0_epc
, &context
->pc
);
241 umask
= context
->rmask
; mask
= 2;
242 for (i
= 1; i
< 32; i
++, mask
<<= 1) {
244 __get_user(regs
->regs
[i
], &context
->regs
[i
]);
246 __get_user(regs
->hi
, &context
->hi
);
247 __get_user(regs
->lo
, &context
->lo
);
249 if ((umask
& 1) && context
->usedfp
) {
250 fregs
= (u64
*) ¤t
->thread
.fpu
;
251 for(i
= 0; i
< 32; i
++)
252 fregs
[i
] = (u64
) context
->fpregs
[i
];
253 __get_user(current
->thread
.fpu
.hard
.fcr31
, &context
->fpcsr
);
256 /* XXX do sigstack crapola here... XXX */
258 if (__copy_from_user(&blocked
, &context
->sigset
, sizeof(blocked
)))
261 sigdelsetmask(&blocked
, ~_BLOCKABLE
);
262 spin_lock_irq(¤t
->sighand
->siglock
);
263 current
->blocked
= blocked
;
265 spin_unlock_irq(¤t
->sighand
->siglock
);
268 * Don't let your children do this ...
270 if (current_thread_info()->flags
& TIF_SYSCALL_TRACE
)
271 do_syscall_trace(regs
, 1);
272 __asm__
__volatile__(
280 force_sig(SIGSEGV
, current
);
283 struct sigact_irix5
{
285 void (*handler
)(int);
291 static inline void dump_sigact_irix5(struct sigact_irix5
*p
)
293 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p
->flags
,
294 (unsigned long) p
->handler
,
295 (unsigned long) p
->sigset
[0]);
300 irix_sigaction(int sig
, const struct sigaction
*act
,
301 struct sigaction
*oact
, void *trampoline
)
303 struct k_sigaction new_ka
, old_ka
;
307 printk(" (%d,%s,%s,%08lx) ", sig
, (!new ? "0" : "NEW"),
308 (!old
? "0" : "OLD"), trampoline
);
310 dump_sigact_irix5(new); printk(" ");
315 if (!access_ok(VERIFY_READ
, act
, sizeof(*act
)) ||
316 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
317 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
))
320 __copy_from_user(&mask
, &act
->sa_mask
, sizeof(sigset_t
));
323 * Hmmm... methinks IRIX libc always passes a valid trampoline
324 * value for all invocations of sigaction. Will have to
325 * investigate. POSIX POSIX, die die die...
327 new_ka
.sa_restorer
= trampoline
;
330 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
331 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
334 if (!access_ok(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
335 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
336 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
))
338 __copy_to_user(&old_ka
.sa
.sa_mask
, &oact
->sa_mask
,
345 asmlinkage
int irix_sigpending(irix_sigset_t
*set
)
347 return do_sigpending(set
, sizeof(*set
));
350 asmlinkage
int irix_sigprocmask(int how
, irix_sigset_t
*new, irix_sigset_t
*old
)
352 sigset_t oldbits
, newbits
;
355 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
357 __copy_from_user(&newbits
, new, sizeof(unsigned long)*4);
358 sigdelsetmask(&newbits
, ~_BLOCKABLE
);
360 spin_lock_irq(¤t
->sighand
->siglock
);
361 oldbits
= current
->blocked
;
365 sigorsets(&newbits
, &oldbits
, &newbits
);
369 sigandsets(&newbits
, &oldbits
, &newbits
);
376 siginitset(&newbits
, newbits
.sig
[0]);
383 spin_unlock_irq(¤t
->sighand
->siglock
);
386 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
388 __copy_to_user(old
, ¤t
->blocked
, sizeof(unsigned long)*4);
394 asmlinkage
int irix_sigsuspend(struct pt_regs
*regs
)
396 sigset_t
*uset
, saveset
, newset
;
398 uset
= (sigset_t
*) regs
->regs
[4];
399 if (copy_from_user(&newset
, uset
, sizeof(sigset_t
)))
401 sigdelsetmask(&newset
, ~_BLOCKABLE
);
403 spin_lock_irq(¤t
->sighand
->siglock
);
404 saveset
= current
->blocked
;
405 current
->blocked
= newset
;
407 spin_unlock_irq(¤t
->sighand
->siglock
);
409 regs
->regs
[2] = -EINTR
;
411 current
->state
= TASK_INTERRUPTIBLE
;
413 if (do_irix_signal(&saveset
, regs
))
418 /* hate hate hate... */
419 struct irix5_siginfo
{
420 int sig
, code
, error
;
422 char unused
[128 - (3 * 4)]; /* Safety net. */
428 int utime
, status
, stime
;
433 unsigned long fault_addr
;
440 unsigned long sigval
;
444 static inline unsigned long timespectojiffies(struct timespec
*value
)
446 unsigned long sec
= (unsigned) value
->tv_sec
;
447 long nsec
= value
->tv_nsec
;
449 if (sec
> (LONG_MAX
/ HZ
))
451 nsec
+= 1000000000L / HZ
- 1;
452 nsec
/= 1000000000L / HZ
;
453 return HZ
* sec
+ nsec
;
456 asmlinkage
int irix_sigpoll_sys(unsigned long *set
, struct irix5_siginfo
*info
,
459 long expire
= MAX_SCHEDULE_TIMEOUT
;
461 int i
, sig
, error
, timeo
= 0;
464 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
465 current
->comm
, current
->pid
, set
, info
, tp
);
468 /* Must always specify the signal set. */
472 if (!access_ok(VERIFY_READ
, set
, sizeof(kset
))) {
477 __copy_from_user(&kset
, set
, sizeof(set
));
481 if (info
&& clear_user(info
, sizeof(*info
))) {
487 if (!access_ok(VERIFY_READ
, tp
, sizeof(*tp
)))
489 if (!tp
->tv_sec
&& !tp
->tv_nsec
) {
493 expire
= timespectojiffies(tp
)+(tp
->tv_sec
||tp
->tv_nsec
);
499 current
->state
= TASK_INTERRUPTIBLE
;
500 expire
= schedule_timeout(expire
);
503 tmp
|= (current
->pending
.signal
.sig
[i
] & kset
.sig
[i
]);
511 if (signal_pending(current
))
517 for(sig
= 1; i
<= 65 /* IRIX_NSIG */; sig
++) {
518 if (sigismember (&kset
, sig
))
520 if (sigismember (¤t
->pending
.signal
, sig
)) {
521 /* XXX need more than this... */
529 /* Should not get here, but do something sane if we do. */
536 /* This is here because of irix5_siginfo definition. */
538 #define IRIX_P_PGID 2
541 extern int getrusage(struct task_struct
*, int, struct rusage __user
*);
549 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
551 asmlinkage
int irix_waitsys(int type
, int pid
, struct irix5_siginfo
*info
,
552 int options
, struct rusage
*ru
)
555 DECLARE_WAITQUEUE(wait
, current
);
556 struct task_struct
*tsk
;
557 struct task_struct
*p
;
558 struct list_head
*_p
;
564 if (!access_ok(VERIFY_WRITE
, info
, sizeof(*info
))) {
569 if (!access_ok(VERIFY_WRITE
, ru
, sizeof(*ru
))) {
574 if (options
& ~(W_MASK
)) {
578 if (type
!= IRIX_P_PID
&& type
!= IRIX_P_PGID
&& type
!= IRIX_P_ALL
) {
582 add_wait_queue(¤t
->signal
->wait_chldexit
, &wait
);
585 current
->state
= TASK_INTERRUPTIBLE
;
586 read_lock(&tasklist_lock
);
588 list_for_each(_p
,&tsk
->children
) {
589 p
= list_entry(_p
,struct task_struct
,sibling
);
590 if ((type
== IRIX_P_PID
) && p
->pid
!= pid
)
592 if ((type
== IRIX_P_PGID
) && process_group(p
) != pid
)
594 if ((p
->exit_signal
!= SIGCHLD
))
601 if (!(options
& (W_TRAPPED
|W_STOPPED
)) &&
602 !(p
->ptrace
& PT_PTRACED
))
604 read_unlock(&tasklist_lock
);
606 /* move to end of parent's list to avoid starvation */
607 write_lock_irq(&tasklist_lock
);
609 add_parent(p
, p
->parent
);
610 write_unlock_irq(&tasklist_lock
);
611 retval
= ru
? getrusage(p
, RUSAGE_BOTH
, ru
) : 0;
613 retval
|= __put_user(SIGCHLD
, &info
->sig
);
614 retval
|= __put_user(0, &info
->code
);
615 retval
|= __put_user(p
->pid
, &info
->stuff
.procinfo
.pid
);
616 retval
|= __put_user((p
->exit_code
>> 8) & 0xff,
617 &info
->stuff
.procinfo
.procdata
.child
.status
);
618 retval
|= __put_user(p
->utime
, &info
->stuff
.procinfo
.procdata
.child
.utime
);
619 retval
|= __put_user(p
->stime
, &info
->stuff
.procinfo
.procdata
.child
.stime
);
627 current
->signal
->cutime
+= p
->utime
+ p
->signal
->cutime
;
628 current
->signal
->cstime
+= p
->stime
+ p
->signal
->cstime
;
630 getrusage(p
, RUSAGE_BOTH
, ru
);
631 __put_user(SIGCHLD
, &info
->sig
);
632 __put_user(1, &info
->code
); /* CLD_EXITED */
633 __put_user(p
->pid
, &info
->stuff
.procinfo
.pid
);
634 __put_user((p
->exit_code
>> 8) & 0xff,
635 &info
->stuff
.procinfo
.procdata
.child
.status
);
637 &info
->stuff
.procinfo
.procdata
.child
.utime
);
639 &info
->stuff
.procinfo
.procdata
.child
.stime
);
641 if (p
->real_parent
!= p
->parent
) {
642 write_lock_irq(&tasklist_lock
);
644 p
->parent
= p
->real_parent
;
645 add_parent(p
, p
->parent
);
646 do_notify_parent(p
, SIGCHLD
);
647 write_unlock_irq(&tasklist_lock
);
654 tsk
= next_thread(tsk
);
656 read_unlock(&tasklist_lock
);
659 if (options
& W_NOHANG
)
661 retval
= -ERESTARTSYS
;
662 if (signal_pending(current
))
664 current
->state
= TASK_INTERRUPTIBLE
;
670 current
->state
= TASK_RUNNING
;
671 remove_wait_queue(¤t
->signal
->wait_chldexit
, &wait
);
677 struct irix5_context
{
681 struct { u32 sp
, size
, flags
; } stack
;
687 u32 weird_graphics_thing
;
690 asmlinkage
int irix_getcontext(struct pt_regs
*regs
)
693 struct irix5_context
*ctx
;
696 if (regs
->regs
[2] == 1000)
698 ctx
= (struct irix5_context
*) regs
->regs
[base
+ 4];
701 printk("[%s:%d] irix_getcontext(%p)\n",
702 current
->comm
, current
->pid
, ctx
);
705 if (!access_ok(VERIFY_WRITE
, ctx
, sizeof(*ctx
)))
708 __put_user(current
->thread
.irix_oldctx
, &ctx
->link
);
710 __copy_to_user(&ctx
->sigmask
, ¤t
->blocked
, sizeof(irix_sigset_t
));
712 /* XXX Do sigstack stuff someday... */
713 __put_user(0, &ctx
->stack
.sp
);
714 __put_user(0, &ctx
->stack
.size
);
715 __put_user(0, &ctx
->stack
.flags
);
717 __put_user(0, &ctx
->weird_graphics_thing
);
718 __put_user(0, &ctx
->regs
[0]);
719 for (i
= 1; i
< 32; i
++)
720 __put_user(regs
->regs
[i
], &ctx
->regs
[i
]);
721 __put_user(regs
->lo
, &ctx
->regs
[32]);
722 __put_user(regs
->hi
, &ctx
->regs
[33]);
723 __put_user(regs
->cp0_cause
, &ctx
->regs
[34]);
724 __put_user(regs
->cp0_epc
, &ctx
->regs
[35]);
731 printk("Wheee, no code for saving IRIX FPU context yet.\n");
733 __put_user(flags
, &ctx
->flags
);
738 asmlinkage
unsigned long irix_setcontext(struct pt_regs
*regs
)
741 struct irix5_context
*ctx
;
743 if(regs
->regs
[2] == 1000)
745 ctx
= (struct irix5_context
*) regs
->regs
[base
+ 4];
748 printk("[%s:%d] irix_setcontext(%p)\n",
749 current
->comm
, current
->pid
, ctx
);
752 if (!access_ok(VERIFY_READ
, ctx
, sizeof(*ctx
))) {
757 if (ctx
->flags
& 0x02) {
758 /* XXX sigstack garbage, todo... */
759 printk("Wheee, cannot do sigstack stuff in setcontext\n");
762 if (ctx
->flags
& 0x04) {
765 /* XXX extra control block stuff... todo... */
766 for(i
= 1; i
< 32; i
++)
767 regs
->regs
[i
] = ctx
->regs
[i
];
768 regs
->lo
= ctx
->regs
[32];
769 regs
->hi
= ctx
->regs
[33];
770 regs
->cp0_epc
= ctx
->regs
[35];
773 if (ctx
->flags
& 0x08) {
774 /* XXX fpu context, blah... */
775 printk("Wheee, cannot restore FPU context yet...\n");
777 current
->thread
.irix_oldctx
= ctx
->link
;
778 error
= regs
->regs
[2];
784 struct irix_sigstack
{ unsigned long sp
; int status
; };
786 asmlinkage
int irix_sigstack(struct irix_sigstack
*new, struct irix_sigstack
*old
)
791 printk("[%s:%d] irix_sigstack(%p,%p)\n",
792 current
->comm
, current
->pid
, new, old
);
795 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
800 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
809 struct irix_sigaltstack
{ unsigned long sp
; int size
; int status
; };
811 asmlinkage
int irix_sigaltstack(struct irix_sigaltstack
*new,
812 struct irix_sigaltstack
*old
)
817 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
818 current
->comm
, current
->pid
, new, old
);
821 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
826 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
837 struct irix_procset
{
838 int cmd
, ltype
, lid
, rtype
, rid
;
841 asmlinkage
int irix_sigsendset(struct irix_procset
*pset
, int sig
)
843 if (!access_ok(VERIFY_READ
, pset
, sizeof(*pset
)))
847 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
848 current
->comm
, current
->pid
,
849 pset
->cmd
, pset
->ltype
, pset
->lid
, pset
->rtype
, pset
->rid
,