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 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
138 switch(regs->regs[0]) {
140 regs->regs[2] = EINTR;
143 if(!(ka->sa.sa_flags & SA_RESTART)) {
144 regs->regs[2] = EINTR;
148 case ERESTARTNOINTR: /* Userland will reload $v0. */
152 regs->regs[0] = 0; /* Don't deal with this again. */
154 if (ka->sa.sa_flags & SA_SIGINFO)
155 setup_irix_rt_frame(ka, regs, sig, oldset, info);
157 setup_irix_frame(ka, regs, sig, oldset);
159 if (!(ka->sa.sa_flags & SA_NODEFER)) {
160 spin_lock_irq(¤t->sighand->siglock);
161 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
162 sigaddset(¤t->blocked,sig);
164 spin_unlock_irq(¤t->sighand->siglock);
168 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
170 struct k_sigaction ka;
175 * We want the common case to go fast, which is why we may in certain
176 * cases get here from kernel mode. Just return without doing anything
179 if (!user_mode(regs))
182 if (current->flags & PF_FREEZE) {
188 oldset = ¤t->blocked;
190 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
192 handle_signal(signr, &info, &ka, oldset, regs);
198 * Who's code doesn't conform to the restartable syscall convention
199 * dies here!!! The li instruction, a single machine instruction,
200 * must directly be followed by the syscall instruction.
203 if (regs->regs[2] == ERESTARTNOHAND ||
204 regs->regs[2] == ERESTARTSYS ||
205 regs->regs[2] == ERESTARTNOINTR) {
213 irix_sigreturn(struct pt_regs *regs)
215 struct sigctx_irix5 *context, *magic;
216 unsigned long umask, mask;
218 int sig, i, base = 0;
221 /* Always make any pending restarted system calls return -EINTR */
222 current_thread_info()->restart_block.fn = do_no_restart_syscall;
224 if (regs->regs[2] == 1000)
227 context = (struct sigctx_irix5 *) regs->regs[base + 4];
228 magic = (struct sigctx_irix5 *) regs->regs[base + 5];
229 sig = (int) regs->regs[base + 6];
231 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
232 current->comm, current->pid, context, magic, sig);
236 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
240 dump_irix5_sigctx(context);
243 __get_user(regs->cp0_epc, &context->pc);
244 umask = context->rmask; mask = 2;
245 for (i = 1; i < 32; i++, mask <<= 1) {
247 __get_user(regs->regs[i], &context->regs[i]);
249 __get_user(regs->hi, &context->hi);
250 __get_user(regs->lo, &context->lo);
252 if ((umask & 1) && context->usedfp) {
253 fregs = (u64 *) ¤t->thread.fpu;
254 for(i = 0; i < 32; i++)
255 fregs[i] = (u64) context->fpregs[i];
256 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
259 /* XXX do sigstack crapola here... XXX */
261 if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
264 sigdelsetmask(&blocked, ~_BLOCKABLE);
265 spin_lock_irq(¤t->sighand->siglock);
266 current->blocked = blocked;
268 spin_unlock_irq(¤t->sighand->siglock);
271 * Don't let your children do this ...
273 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
274 do_syscall_trace(regs, 1);
275 __asm__ __volatile__(
283 force_sig(SIGSEGV, current);
286 struct sigact_irix5 {
288 void (*handler)(int);
294 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
296 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
297 (unsigned long) p->handler,
298 (unsigned long) p->sigset[0]);
303 irix_sigaction(int sig, const struct sigaction *act,
304 struct sigaction *oact, void *trampoline)
306 struct k_sigaction new_ka, old_ka;
310 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
311 (!old ? "0" : "OLD"), trampoline);
313 dump_sigact_irix5(new); printk(" ");
318 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
319 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
320 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
323 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
326 * Hmmm... methinks IRIX libc always passes a valid trampoline
327 * value for all invocations of sigaction. Will have to
328 * investigate. POSIX POSIX, die die die...
330 new_ka.sa_restorer = trampoline;
333 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
334 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
337 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
338 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
339 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
341 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
348 asmlinkage int irix_sigpending(irix_sigset_t *set)
350 return do_sigpending(set, sizeof(*set));
353 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
355 sigset_t oldbits, newbits;
359 error = verify_area(VERIFY_READ, new, sizeof(*new));
362 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
363 sigdelsetmask(&newbits, ~_BLOCKABLE);
365 spin_lock_irq(¤t->sighand->siglock);
366 oldbits = current->blocked;
370 sigorsets(&newbits, &oldbits, &newbits);
374 sigandsets(&newbits, &oldbits, &newbits);
381 siginitset(&newbits, newbits.sig[0]);
388 spin_unlock_irq(¤t->sighand->siglock);
391 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
394 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
400 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
402 sigset_t *uset, saveset, newset;
404 uset = (sigset_t *) regs->regs[4];
405 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
407 sigdelsetmask(&newset, ~_BLOCKABLE);
409 spin_lock_irq(¤t->sighand->siglock);
410 saveset = current->blocked;
411 current->blocked = newset;
413 spin_unlock_irq(¤t->sighand->siglock);
415 regs->regs[2] = -EINTR;
417 current->state = TASK_INTERRUPTIBLE;
419 if (do_irix_signal(&saveset, regs))
424 /* hate hate hate... */
425 struct irix5_siginfo {
426 int sig, code, error;
428 char unused[128 - (3 * 4)]; /* Safety net. */
434 int utime, status, stime;
439 unsigned long fault_addr;
446 unsigned long sigval;
450 static inline unsigned long timespectojiffies(struct timespec *value)
452 unsigned long sec = (unsigned) value->tv_sec;
453 long nsec = value->tv_nsec;
455 if (sec > (LONG_MAX / HZ))
457 nsec += 1000000000L / HZ - 1;
458 nsec /= 1000000000L / HZ;
459 return HZ * sec + nsec;
462 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
465 long expire = MAX_SCHEDULE_TIMEOUT;
467 int i, sig, error, timeo = 0;
470 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
471 current->comm, current->pid, set, info, tp);
474 /* Must always specify the signal set. */
478 error = verify_area(VERIFY_READ, set, sizeof(kset));
482 __copy_from_user(&kset, set, sizeof(set));
486 if (info && clear_user(info, sizeof(*info))) {
492 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
495 if(!tp->tv_sec && !tp->tv_nsec) {
499 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
505 current->state = TASK_INTERRUPTIBLE;
506 expire = schedule_timeout(expire);
509 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
517 if (signal_pending(current))
523 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
524 if (sigismember (&kset, sig))
526 if (sigismember (¤t->pending.signal, sig)) {
527 /* XXX need more than this... */
535 /* Should not get here, but do something sane if we do. */
542 /* This is here because of irix5_siginfo definition. */
544 #define IRIX_P_PGID 2
547 extern int getrusage(struct task_struct *, int, struct rusage __user *);
555 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
557 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
558 int options, struct rusage *ru)
561 DECLARE_WAITQUEUE(wait, current);
562 struct task_struct *tsk;
563 struct task_struct *p;
564 struct list_head *_p;
570 retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
574 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
578 if (options & ~(W_MASK)) {
582 if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
586 add_wait_queue(¤t->wait_chldexit, &wait);
589 current->state = TASK_INTERRUPTIBLE;
590 read_lock(&tasklist_lock);
592 list_for_each(_p,&tsk->children) {
593 p = list_entry(_p,struct task_struct,sibling);
594 if ((type == IRIX_P_PID) && p->pid != pid)
596 if ((type == IRIX_P_PGID) && process_group(p) != pid)
598 if ((p->exit_signal != SIGCHLD))
605 if (!(options & (W_TRAPPED|W_STOPPED)) &&
606 !(p->ptrace & PT_PTRACED))
608 read_unlock(&tasklist_lock);
610 /* move to end of parent's list to avoid starvation */
611 write_lock_irq(&tasklist_lock);
613 add_parent(p, p->parent);
614 write_unlock_irq(&tasklist_lock);
615 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
617 retval |= __put_user(SIGCHLD, &info->sig);
618 retval |= __put_user(0, &info->code);
619 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
620 retval |= __put_user((p->exit_code >> 8) & 0xff,
621 &info->stuff.procinfo.procdata.child.status);
622 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
623 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
631 current->signal->cutime += p->utime + p->signal->cutime;
632 current->signal->cstime += p->stime + p->signal->cstime;
634 getrusage(p, RUSAGE_BOTH, ru);
635 __put_user(SIGCHLD, &info->sig);
636 __put_user(1, &info->code); /* CLD_EXITED */
637 __put_user(p->pid, &info->stuff.procinfo.pid);
638 __put_user((p->exit_code >> 8) & 0xff,
639 &info->stuff.procinfo.procdata.child.status);
641 &info->stuff.procinfo.procdata.child.utime);
643 &info->stuff.procinfo.procdata.child.stime);
645 if (p->real_parent != p->parent) {
646 write_lock_irq(&tasklist_lock);
648 p->parent = p->real_parent;
649 add_parent(p, p->parent);
650 do_notify_parent(p, SIGCHLD);
651 write_unlock_irq(&tasklist_lock);
658 tsk = next_thread(tsk);
660 read_unlock(&tasklist_lock);
663 if (options & W_NOHANG)
665 retval = -ERESTARTSYS;
666 if (signal_pending(current))
668 current->state = TASK_INTERRUPTIBLE;
674 current->state = TASK_RUNNING;
675 remove_wait_queue(¤t->wait_chldexit, &wait);
681 struct irix5_context {
685 struct { u32 sp, size, flags; } stack;
691 u32 weird_graphics_thing;
694 asmlinkage int irix_getcontext(struct pt_regs *regs)
696 int error, i, base = 0;
697 struct irix5_context *ctx;
700 if (regs->regs[2] == 1000)
702 ctx = (struct irix5_context *) regs->regs[base + 4];
705 printk("[%s:%d] irix_getcontext(%p)\n",
706 current->comm, current->pid, ctx);
709 error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
712 __put_user(current->thread.irix_oldctx, &ctx->link);
714 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
716 /* XXX Do sigstack stuff someday... */
717 __put_user(0, &ctx->stack.sp);
718 __put_user(0, &ctx->stack.size);
719 __put_user(0, &ctx->stack.flags);
721 __put_user(0, &ctx->weird_graphics_thing);
722 __put_user(0, &ctx->regs[0]);
723 for (i = 1; i < 32; i++)
724 __put_user(regs->regs[i], &ctx->regs[i]);
725 __put_user(regs->lo, &ctx->regs[32]);
726 __put_user(regs->hi, &ctx->regs[33]);
727 __put_user(regs->cp0_cause, &ctx->regs[34]);
728 __put_user(regs->cp0_epc, &ctx->regs[35]);
731 if(!current->used_math) {
735 printk("Wheee, no code for saving IRIX FPU context yet.\n");
737 __put_user(flags, &ctx->flags);
744 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
747 struct irix5_context *ctx;
749 if(regs->regs[2] == 1000)
751 ctx = (struct irix5_context *) regs->regs[base + 4];
754 printk("[%s:%d] irix_setcontext(%p)\n",
755 current->comm, current->pid, ctx);
758 error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
762 if (ctx->flags & 0x02) {
763 /* XXX sigstack garbage, todo... */
764 printk("Wheee, cannot do sigstack stuff in setcontext\n");
767 if (ctx->flags & 0x04) {
770 /* XXX extra control block stuff... todo... */
771 for(i = 1; i < 32; i++)
772 regs->regs[i] = ctx->regs[i];
773 regs->lo = ctx->regs[32];
774 regs->hi = ctx->regs[33];
775 regs->cp0_epc = ctx->regs[35];
778 if (ctx->flags & 0x08) {
779 /* XXX fpu context, blah... */
780 printk("Wheee, cannot restore FPU context yet...\n");
782 current->thread.irix_oldctx = ctx->link;
783 error = regs->regs[2];
789 struct irix_sigstack { unsigned long sp; int status; };
791 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
796 printk("[%s:%d] irix_sigstack(%p,%p)\n",
797 current->comm, current->pid, new, old);
800 error = verify_area(VERIFY_READ, new, sizeof(*new));
806 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
816 struct irix_sigaltstack { unsigned long sp; int size; int status; };
818 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
819 struct irix_sigaltstack *old)
824 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
825 current->comm, current->pid, new, old);
828 error = verify_area(VERIFY_READ, new, sizeof(*new));
834 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
846 struct irix_procset {
847 int cmd, ltype, lid, rtype, rid;
850 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
854 error = verify_area(VERIFY_READ, pset, sizeof(*pset));
858 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
859 current->comm, current->pid,
860 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,