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 (verify_area(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 (verify_area(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;
356 error = verify_area(VERIFY_READ, new, sizeof(*new));
359 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
360 sigdelsetmask(&newbits, ~_BLOCKABLE);
362 spin_lock_irq(¤t->sighand->siglock);
363 oldbits = current->blocked;
367 sigorsets(&newbits, &oldbits, &newbits);
371 sigandsets(&newbits, &oldbits, &newbits);
378 siginitset(&newbits, newbits.sig[0]);
385 spin_unlock_irq(¤t->sighand->siglock);
388 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
391 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
397 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
399 sigset_t *uset, saveset, newset;
401 uset = (sigset_t *) regs->regs[4];
402 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
404 sigdelsetmask(&newset, ~_BLOCKABLE);
406 spin_lock_irq(¤t->sighand->siglock);
407 saveset = current->blocked;
408 current->blocked = newset;
410 spin_unlock_irq(¤t->sighand->siglock);
412 regs->regs[2] = -EINTR;
414 current->state = TASK_INTERRUPTIBLE;
416 if (do_irix_signal(&saveset, regs))
421 /* hate hate hate... */
422 struct irix5_siginfo {
423 int sig, code, error;
425 char unused[128 - (3 * 4)]; /* Safety net. */
431 int utime, status, stime;
436 unsigned long fault_addr;
443 unsigned long sigval;
447 static inline unsigned long timespectojiffies(struct timespec *value)
449 unsigned long sec = (unsigned) value->tv_sec;
450 long nsec = value->tv_nsec;
452 if (sec > (LONG_MAX / HZ))
454 nsec += 1000000000L / HZ - 1;
455 nsec /= 1000000000L / HZ;
456 return HZ * sec + nsec;
459 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
462 long expire = MAX_SCHEDULE_TIMEOUT;
464 int i, sig, error, timeo = 0;
467 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
468 current->comm, current->pid, set, info, tp);
471 /* Must always specify the signal set. */
475 error = verify_area(VERIFY_READ, set, sizeof(kset));
479 __copy_from_user(&kset, set, sizeof(set));
483 if (info && clear_user(info, sizeof(*info))) {
489 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
492 if(!tp->tv_sec && !tp->tv_nsec) {
496 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
502 current->state = TASK_INTERRUPTIBLE;
503 expire = schedule_timeout(expire);
506 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
514 if (signal_pending(current))
520 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
521 if (sigismember (&kset, sig))
523 if (sigismember (¤t->pending.signal, sig)) {
524 /* XXX need more than this... */
532 /* Should not get here, but do something sane if we do. */
539 /* This is here because of irix5_siginfo definition. */
541 #define IRIX_P_PGID 2
544 extern int getrusage(struct task_struct *, int, struct rusage __user *);
552 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
554 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
555 int options, struct rusage *ru)
558 DECLARE_WAITQUEUE(wait, current);
559 struct task_struct *tsk;
560 struct task_struct *p;
561 struct list_head *_p;
567 retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
571 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
575 if (options & ~(W_MASK)) {
579 if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
583 add_wait_queue(¤t->signal->wait_chldexit, &wait);
586 current->state = TASK_INTERRUPTIBLE;
587 read_lock(&tasklist_lock);
589 list_for_each(_p,&tsk->children) {
590 p = list_entry(_p,struct task_struct,sibling);
591 if ((type == IRIX_P_PID) && p->pid != pid)
593 if ((type == IRIX_P_PGID) && process_group(p) != pid)
595 if ((p->exit_signal != SIGCHLD))
602 if (!(options & (W_TRAPPED|W_STOPPED)) &&
603 !(p->ptrace & PT_PTRACED))
605 read_unlock(&tasklist_lock);
607 /* move to end of parent's list to avoid starvation */
608 write_lock_irq(&tasklist_lock);
610 add_parent(p, p->parent);
611 write_unlock_irq(&tasklist_lock);
612 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
614 retval |= __put_user(SIGCHLD, &info->sig);
615 retval |= __put_user(0, &info->code);
616 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
617 retval |= __put_user((p->exit_code >> 8) & 0xff,
618 &info->stuff.procinfo.procdata.child.status);
619 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
620 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
628 current->signal->cutime += p->utime + p->signal->cutime;
629 current->signal->cstime += p->stime + p->signal->cstime;
631 getrusage(p, RUSAGE_BOTH, ru);
632 __put_user(SIGCHLD, &info->sig);
633 __put_user(1, &info->code); /* CLD_EXITED */
634 __put_user(p->pid, &info->stuff.procinfo.pid);
635 __put_user((p->exit_code >> 8) & 0xff,
636 &info->stuff.procinfo.procdata.child.status);
638 &info->stuff.procinfo.procdata.child.utime);
640 &info->stuff.procinfo.procdata.child.stime);
642 if (p->real_parent != p->parent) {
643 write_lock_irq(&tasklist_lock);
645 p->parent = p->real_parent;
646 add_parent(p, p->parent);
647 do_notify_parent(p, SIGCHLD);
648 write_unlock_irq(&tasklist_lock);
655 tsk = next_thread(tsk);
657 read_unlock(&tasklist_lock);
660 if (options & W_NOHANG)
662 retval = -ERESTARTSYS;
663 if (signal_pending(current))
665 current->state = TASK_INTERRUPTIBLE;
671 current->state = TASK_RUNNING;
672 remove_wait_queue(¤t->signal->wait_chldexit, &wait);
678 struct irix5_context {
682 struct { u32 sp, size, flags; } stack;
688 u32 weird_graphics_thing;
691 asmlinkage int irix_getcontext(struct pt_regs *regs)
693 int error, i, base = 0;
694 struct irix5_context *ctx;
697 if (regs->regs[2] == 1000)
699 ctx = (struct irix5_context *) regs->regs[base + 4];
702 printk("[%s:%d] irix_getcontext(%p)\n",
703 current->comm, current->pid, ctx);
706 error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
709 __put_user(current->thread.irix_oldctx, &ctx->link);
711 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
713 /* XXX Do sigstack stuff someday... */
714 __put_user(0, &ctx->stack.sp);
715 __put_user(0, &ctx->stack.size);
716 __put_user(0, &ctx->stack.flags);
718 __put_user(0, &ctx->weird_graphics_thing);
719 __put_user(0, &ctx->regs[0]);
720 for (i = 1; i < 32; i++)
721 __put_user(regs->regs[i], &ctx->regs[i]);
722 __put_user(regs->lo, &ctx->regs[32]);
723 __put_user(regs->hi, &ctx->regs[33]);
724 __put_user(regs->cp0_cause, &ctx->regs[34]);
725 __put_user(regs->cp0_epc, &ctx->regs[35]);
732 printk("Wheee, no code for saving IRIX FPU context yet.\n");
734 __put_user(flags, &ctx->flags);
741 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
744 struct irix5_context *ctx;
746 if(regs->regs[2] == 1000)
748 ctx = (struct irix5_context *) regs->regs[base + 4];
751 printk("[%s:%d] irix_setcontext(%p)\n",
752 current->comm, current->pid, ctx);
755 error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
759 if (ctx->flags & 0x02) {
760 /* XXX sigstack garbage, todo... */
761 printk("Wheee, cannot do sigstack stuff in setcontext\n");
764 if (ctx->flags & 0x04) {
767 /* XXX extra control block stuff... todo... */
768 for(i = 1; i < 32; i++)
769 regs->regs[i] = ctx->regs[i];
770 regs->lo = ctx->regs[32];
771 regs->hi = ctx->regs[33];
772 regs->cp0_epc = ctx->regs[35];
775 if (ctx->flags & 0x08) {
776 /* XXX fpu context, blah... */
777 printk("Wheee, cannot restore FPU context yet...\n");
779 current->thread.irix_oldctx = ctx->link;
780 error = regs->regs[2];
786 struct irix_sigstack { unsigned long sp; int status; };
788 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
793 printk("[%s:%d] irix_sigstack(%p,%p)\n",
794 current->comm, current->pid, new, old);
797 error = verify_area(VERIFY_READ, new, sizeof(*new));
803 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
813 struct irix_sigaltstack { unsigned long sp; int size; int status; };
815 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
816 struct irix_sigaltstack *old)
821 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
822 current->comm, current->pid, new, old);
825 error = verify_area(VERIFY_READ, new, sizeof(*new));
831 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
843 struct irix_procset {
844 int cmd, ltype, lid, rtype, rid;
847 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
851 error = verify_area(VERIFY_READ, pset, sizeof(*pset));
855 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
856 current->comm, current->pid,
857 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,