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>
16 #include <linux/suspend.h>
18 #include <asm/ptrace.h>
19 #include <asm/uaccess.h>
23 #define _S(nr) (1<<((nr)-1))
25 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
32 u32 rmask, cp0_status;
36 u32 usedfp, fpcsr, fpeir, sstk_flags;
38 u64 cp0_cause, cp0_badvaddr, _unused0;
46 static inline void dump_irix5_sigctx(struct sigctx_irix5 *c)
50 printk("misc: rmask[%08lx] status[%08lx] pc[%08lx]\n",
51 (unsigned long) c->rmask,
52 (unsigned long) c->cp0_status,
53 (unsigned long) c->pc);
55 for(i = 0; i < 16; i++)
56 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
58 for(i = 16; i < 32; i++)
59 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
61 for(i = 0; i < 16; i++)
62 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
64 for(i = 16; i < 32; i++)
65 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
66 printk("misc: usedfp[%d] fpcsr[%08lx] fpeir[%08lx] stk_flgs[%08lx]\n",
67 (int) c->usedfp, (unsigned long) c->fpcsr,
68 (unsigned long) c->fpeir, (unsigned long) c->sstk_flags);
69 printk("misc: hi[%08lx] lo[%08lx] cause[%08lx] badvaddr[%08lx]\n",
70 (unsigned long) c->hi, (unsigned long) c->lo,
71 (unsigned long) c->cp0_cause, (unsigned long) c->cp0_badvaddr);
72 printk("misc: sigset<0>[%08lx] sigset<1>[%08lx] sigset<2>[%08lx] "
73 "sigset<3>[%08lx]\n", (unsigned long) c->sigset.sig[0],
74 (unsigned long) c->sigset.sig[1],
75 (unsigned long) c->sigset.sig[2],
76 (unsigned long) c->sigset.sig[3]);
80 static void setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
81 int signr, sigset_t *oldmask)
84 struct sigctx_irix5 *ctx;
88 sp -= sizeof(struct sigctx_irix5);
90 ctx = (struct sigctx_irix5 *) sp;
91 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
94 __put_user(0, &ctx->weird_fpu_thing);
95 __put_user(~(0x00000001), &ctx->rmask);
96 __put_user(0, &ctx->regs[0]);
97 for(i = 1; i < 32; i++)
98 __put_user((u64) regs->regs[i], &ctx->regs[i]);
100 __put_user((u64) regs->hi, &ctx->hi);
101 __put_user((u64) regs->lo, &ctx->lo);
102 __put_user((u64) regs->cp0_epc, &ctx->pc);
103 __put_user(current->used_math, &ctx->usedfp);
104 __put_user((u64) regs->cp0_cause, &ctx->cp0_cause);
105 __put_user((u64) regs->cp0_badvaddr, &ctx->cp0_badvaddr);
107 __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
109 __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t));
112 dump_irix5_sigctx(ctx);
115 regs->regs[4] = (unsigned long) signr;
116 regs->regs[5] = 0; /* XXX sigcode XXX */
117 regs->regs[6] = regs->regs[29] = sp;
118 regs->regs[7] = (unsigned long) ka->sa.sa_handler;
119 regs->regs[25] = regs->cp0_epc = (unsigned long) ka->sa_restorer;
124 force_sigsegv(signr, current);
128 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
129 int signr, sigset_t *oldmask, siginfo_t *info)
131 printk("Aiee: setup_tr_frame wants to be written");
135 static inline void handle_signal(unsigned long sig, siginfo_t *info,
136 sigset_t *oldset, struct pt_regs * regs)
138 struct k_sigaction *ka = ¤t->sighand->action[sig-1];
140 switch(regs->regs[0]) {
142 regs->regs[2] = EINTR;
145 if(!(ka->sa.sa_flags & SA_RESTART)) {
146 regs->regs[2] = EINTR;
150 case ERESTARTNOINTR: /* Userland will reload $v0. */
154 regs->regs[0] = 0; /* Don't deal with this again. */
156 if (ka->sa.sa_flags & SA_SIGINFO)
157 setup_irix_rt_frame(ka, regs, sig, oldset, info);
159 setup_irix_frame(ka, regs, sig, oldset);
161 if (ka->sa.sa_flags & SA_ONESHOT)
162 ka->sa.sa_handler = SIG_DFL;
163 if (!(ka->sa.sa_flags & SA_NODEFER)) {
164 spin_lock_irq(¤t->sighand->siglock);
165 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
166 sigaddset(¤t->blocked,sig);
168 spin_unlock_irq(¤t->sighand->siglock);
172 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
178 * We want the common case to go fast, which is why we may in certain
179 * cases get here from kernel mode. Just return without doing anything
182 if (!user_mode(regs))
185 if (current->flags & PF_FREEZE) {
191 oldset = ¤t->blocked;
193 signr = get_signal_to_deliver(&info, regs, NULL);
195 handle_signal(signr, &info, oldset, regs);
201 * Who's code doesn't conform to the restartable syscall convention
202 * dies here!!! The li instruction, a single machine instruction,
203 * must directly be followed by the syscall instruction.
206 if (regs->regs[2] == ERESTARTNOHAND ||
207 regs->regs[2] == ERESTARTSYS ||
208 regs->regs[2] == ERESTARTNOINTR) {
216 irix_sigreturn(struct pt_regs *regs)
218 struct sigctx_irix5 *context, *magic;
219 unsigned long umask, mask;
221 int sig, i, base = 0;
224 /* Always make any pending restarted system calls return -EINTR */
225 current_thread_info()->restart_block.fn = do_no_restart_syscall;
227 if (regs->regs[2] == 1000)
230 context = (struct sigctx_irix5 *) regs->regs[base + 4];
231 magic = (struct sigctx_irix5 *) regs->regs[base + 5];
232 sig = (int) regs->regs[base + 6];
234 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
235 current->comm, current->pid, context, magic, sig);
239 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
243 dump_irix5_sigctx(context);
246 __get_user(regs->cp0_epc, &context->pc);
247 umask = context->rmask; mask = 2;
248 for (i = 1; i < 32; i++, mask <<= 1) {
250 __get_user(regs->regs[i], &context->regs[i]);
252 __get_user(regs->hi, &context->hi);
253 __get_user(regs->lo, &context->lo);
255 if ((umask & 1) && context->usedfp) {
256 fregs = (u64 *) ¤t->thread.fpu;
257 for(i = 0; i < 32; i++)
258 fregs[i] = (u64) context->fpregs[i];
259 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
262 /* XXX do sigstack crapola here... XXX */
264 if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
267 sigdelsetmask(&blocked, ~_BLOCKABLE);
268 spin_lock_irq(¤t->sighand->siglock);
269 current->blocked = blocked;
271 spin_unlock_irq(¤t->sighand->siglock);
274 * Don't let your children do this ...
276 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
277 do_syscall_trace(regs, 1);
278 __asm__ __volatile__(
286 force_sig(SIGSEGV, current);
289 struct sigact_irix5 {
291 void (*handler)(int);
297 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
299 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
300 (unsigned long) p->handler,
301 (unsigned long) p->sigset[0]);
306 irix_sigaction(int sig, const struct sigaction *act,
307 struct sigaction *oact, void *trampoline)
309 struct k_sigaction new_ka, old_ka;
313 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
314 (!old ? "0" : "OLD"), trampoline);
316 dump_sigact_irix5(new); printk(" ");
321 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
322 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
323 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
326 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
329 * Hmmm... methinks IRIX libc always passes a valid trampoline
330 * value for all invocations of sigaction. Will have to
331 * investigate. POSIX POSIX, die die die...
333 new_ka.sa_restorer = trampoline;
336 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
337 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
340 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
341 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
342 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
344 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
351 asmlinkage int irix_sigpending(irix_sigset_t *set)
353 return do_sigpending(set, sizeof(*set));
356 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
358 sigset_t oldbits, newbits;
362 error = verify_area(VERIFY_READ, new, sizeof(*new));
365 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
366 sigdelsetmask(&newbits, ~_BLOCKABLE);
368 spin_lock_irq(¤t->sighand->siglock);
369 oldbits = current->blocked;
373 sigorsets(&newbits, &oldbits, &newbits);
377 sigandsets(&newbits, &oldbits, &newbits);
384 siginitset(&newbits, newbits.sig[0]);
391 spin_unlock_irq(¤t->sighand->siglock);
394 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
397 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
403 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
405 sigset_t *uset, saveset, newset;
407 uset = (sigset_t *) regs->regs[4];
408 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
410 sigdelsetmask(&newset, ~_BLOCKABLE);
412 spin_lock_irq(¤t->sighand->siglock);
413 saveset = current->blocked;
414 current->blocked = newset;
416 spin_unlock_irq(¤t->sighand->siglock);
418 regs->regs[2] = -EINTR;
420 current->state = TASK_INTERRUPTIBLE;
422 if (do_irix_signal(&saveset, regs))
427 /* hate hate hate... */
428 struct irix5_siginfo {
429 int sig, code, error;
431 char unused[128 - (3 * 4)]; /* Safety net. */
437 int utime, status, stime;
442 unsigned long fault_addr;
449 unsigned long sigval;
453 static inline unsigned long timespectojiffies(struct timespec *value)
455 unsigned long sec = (unsigned) value->tv_sec;
456 long nsec = value->tv_nsec;
458 if (sec > (LONG_MAX / HZ))
460 nsec += 1000000000L / HZ - 1;
461 nsec /= 1000000000L / HZ;
462 return HZ * sec + nsec;
465 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
468 long expire = MAX_SCHEDULE_TIMEOUT;
470 int i, sig, error, timeo = 0;
473 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
474 current->comm, current->pid, set, info, tp);
477 /* Must always specify the signal set. */
481 error = verify_area(VERIFY_READ, set, sizeof(kset));
485 __copy_from_user(&kset, set, sizeof(set));
489 if (info && clear_user(info, sizeof(*info))) {
495 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
498 if(!tp->tv_sec && !tp->tv_nsec) {
502 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
508 current->state = TASK_INTERRUPTIBLE;
509 expire = schedule_timeout(expire);
512 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
520 if (signal_pending(current))
526 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
527 if (sigismember (&kset, sig))
529 if (sigismember (¤t->pending.signal, sig)) {
530 /* XXX need more than this... */
538 /* Should not get here, but do something sane if we do. */
545 /* This is here because of irix5_siginfo definition. */
550 extern int getrusage(struct task_struct *, int, struct rusage __user *);
558 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
560 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
561 int options, struct rusage *ru)
564 DECLARE_WAITQUEUE(wait, current);
565 struct task_struct *tsk;
566 struct task_struct *p;
567 struct list_head *_p;
573 retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
577 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
581 if (options & ~(W_MASK)) {
585 if (type != P_PID && type != P_PGID && type != P_ALL) {
589 add_wait_queue(¤t->wait_chldexit, &wait);
592 current->state = TASK_INTERRUPTIBLE;
593 read_lock(&tasklist_lock);
595 list_for_each(_p,&tsk->children) {
596 p = list_entry(_p,struct task_struct,sibling);
597 if ((type == P_PID) && p->pid != pid)
599 if ((type == P_PGID) && process_group(p) != pid)
601 if ((p->exit_signal != SIGCHLD))
608 if (!(options & (W_TRAPPED|W_STOPPED)) &&
609 !(p->ptrace & PT_PTRACED))
611 read_unlock(&tasklist_lock);
613 /* move to end of parent's list to avoid starvation */
614 write_lock_irq(&tasklist_lock);
616 add_parent(p, p->parent);
617 write_unlock_irq(&tasklist_lock);
618 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
620 retval |= __put_user(SIGCHLD, &info->sig);
621 retval |= __put_user(0, &info->code);
622 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
623 retval |= __put_user((p->exit_code >> 8) & 0xff,
624 &info->stuff.procinfo.procdata.child.status);
625 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
626 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
634 current->cutime += p->utime + p->cutime;
635 current->cstime += p->stime + p->cstime;
637 getrusage(p, RUSAGE_BOTH, ru);
638 __put_user(SIGCHLD, &info->sig);
639 __put_user(1, &info->code); /* CLD_EXITED */
640 __put_user(p->pid, &info->stuff.procinfo.pid);
641 __put_user((p->exit_code >> 8) & 0xff,
642 &info->stuff.procinfo.procdata.child.status);
644 &info->stuff.procinfo.procdata.child.utime);
646 &info->stuff.procinfo.procdata.child.stime);
648 if (p->real_parent != p->parent) {
649 write_lock_irq(&tasklist_lock);
651 p->parent = p->real_parent;
652 add_parent(p, p->parent);
653 do_notify_parent(p, SIGCHLD);
654 write_unlock_irq(&tasklist_lock);
661 tsk = next_thread(tsk);
663 read_unlock(&tasklist_lock);
666 if (options & W_NOHANG)
668 retval = -ERESTARTSYS;
669 if (signal_pending(current))
671 current->state = TASK_INTERRUPTIBLE;
677 current->state = TASK_RUNNING;
678 remove_wait_queue(¤t->wait_chldexit, &wait);
684 struct irix5_context {
688 struct { u32 sp, size, flags; } stack;
694 u32 weird_graphics_thing;
697 asmlinkage int irix_getcontext(struct pt_regs *regs)
699 int error, i, base = 0;
700 struct irix5_context *ctx;
703 if (regs->regs[2] == 1000)
705 ctx = (struct irix5_context *) regs->regs[base + 4];
708 printk("[%s:%d] irix_getcontext(%p)\n",
709 current->comm, current->pid, ctx);
712 error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
715 __put_user(current->thread.irix_oldctx, &ctx->link);
717 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
719 /* XXX Do sigstack stuff someday... */
720 __put_user(0, &ctx->stack.sp);
721 __put_user(0, &ctx->stack.size);
722 __put_user(0, &ctx->stack.flags);
724 __put_user(0, &ctx->weird_graphics_thing);
725 __put_user(0, &ctx->regs[0]);
726 for (i = 1; i < 32; i++)
727 __put_user(regs->regs[i], &ctx->regs[i]);
728 __put_user(regs->lo, &ctx->regs[32]);
729 __put_user(regs->hi, &ctx->regs[33]);
730 __put_user(regs->cp0_cause, &ctx->regs[34]);
731 __put_user(regs->cp0_epc, &ctx->regs[35]);
734 if(!current->used_math) {
738 printk("Wheee, no code for saving IRIX FPU context yet.\n");
740 __put_user(flags, &ctx->flags);
747 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
750 struct irix5_context *ctx;
752 if(regs->regs[2] == 1000)
754 ctx = (struct irix5_context *) regs->regs[base + 4];
757 printk("[%s:%d] irix_setcontext(%p)\n",
758 current->comm, current->pid, ctx);
761 error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
765 if (ctx->flags & 0x02) {
766 /* XXX sigstack garbage, todo... */
767 printk("Wheee, cannot do sigstack stuff in setcontext\n");
770 if (ctx->flags & 0x04) {
773 /* XXX extra control block stuff... todo... */
774 for(i = 1; i < 32; i++)
775 regs->regs[i] = ctx->regs[i];
776 regs->lo = ctx->regs[32];
777 regs->hi = ctx->regs[33];
778 regs->cp0_epc = ctx->regs[35];
781 if (ctx->flags & 0x08) {
782 /* XXX fpu context, blah... */
783 printk("Wheee, cannot restore FPU context yet...\n");
785 current->thread.irix_oldctx = ctx->link;
786 error = regs->regs[2];
792 struct irix_sigstack { unsigned long sp; int status; };
794 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
799 printk("[%s:%d] irix_sigstack(%p,%p)\n",
800 current->comm, current->pid, new, old);
803 error = verify_area(VERIFY_READ, new, sizeof(*new));
809 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
819 struct irix_sigaltstack { unsigned long sp; int size; int status; };
821 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
822 struct irix_sigaltstack *old)
827 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
828 current->comm, current->pid, new, old);
831 error = verify_area(VERIFY_READ, new, sizeof(*new));
837 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
849 struct irix_procset {
850 int cmd, ltype, lid, rtype, rid;
853 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
857 error = verify_area(VERIFY_READ, pset, sizeof(*pset));
861 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
862 current->comm, current->pid,
863 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,