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 int setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
80 int signr, sigset_t *oldmask)
82 struct sigctx_irix5 __user *ctx;
87 sp -= sizeof(struct sigctx_irix5);
89 ctx = (struct sigctx_irix5 __user *) sp;
90 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
93 error = __put_user(0, &ctx->weird_fpu_thing);
94 error |= __put_user(~(0x00000001), &ctx->rmask);
95 error |= __put_user(0, &ctx->regs[0]);
96 for(i = 1; i < 32; i++)
97 error |= __put_user((u64) regs->regs[i], &ctx->regs[i]);
99 error |= __put_user((u64) regs->hi, &ctx->hi);
100 error |= __put_user((u64) regs->lo, &ctx->lo);
101 error |= __put_user((u64) regs->cp0_epc, &ctx->pc);
102 error |= __put_user(!!used_math(), &ctx->usedfp);
103 error |= __put_user((u64) regs->cp0_cause, &ctx->cp0_cause);
104 error |= __put_user((u64) regs->cp0_badvaddr, &ctx->cp0_badvaddr);
106 error |= __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
108 error |= __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t)) ? -EFAULT : 0;
114 dump_irix5_sigctx(ctx);
117 regs->regs[4] = (unsigned long) signr;
118 regs->regs[5] = 0; /* XXX sigcode XXX */
119 regs->regs[6] = regs->regs[29] = sp;
120 regs->regs[7] = (unsigned long) ka->sa.sa_handler;
121 regs->regs[25] = regs->cp0_epc = (unsigned long) ka->sa_restorer;
126 force_sigsegv(signr, current);
131 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
132 int signr, sigset_t *oldmask, siginfo_t *info)
134 printk("Aiee: setup_tr_frame wants to be written");
138 static inline int handle_signal(unsigned long sig, siginfo_t *info,
139 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
143 switch(regs->regs[0]) {
145 regs->regs[2] = EINTR;
148 if(!(ka->sa.sa_flags & SA_RESTART)) {
149 regs->regs[2] = EINTR;
153 case ERESTARTNOINTR: /* Userland will reload $v0. */
157 regs->regs[0] = 0; /* Don't deal with this again. */
159 if (ka->sa.sa_flags & SA_SIGINFO)
160 ret = setup_irix_rt_frame(ka, regs, sig, oldset, info);
162 ret = setup_irix_frame(ka, regs, sig, oldset);
164 spin_lock_irq(¤t->sighand->siglock);
165 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
166 if (!(ka->sa.sa_flags & SA_NODEFER))
167 sigaddset(¤t->blocked,sig);
169 spin_unlock_irq(¤t->sighand->siglock);
174 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
176 struct k_sigaction ka;
181 * We want the common case to go fast, which is why we may in certain
182 * cases get here from kernel mode. Just return without doing anything
185 if (!user_mode(regs))
192 oldset = ¤t->blocked;
194 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
196 return handle_signal(signr, &info, &ka, oldset, regs);
200 * Who's code doesn't conform to the restartable syscall convention
201 * dies here!!! The li instruction, a single machine instruction,
202 * must directly be followed by the syscall instruction.
205 if (regs->regs[2] == ERESTARTNOHAND ||
206 regs->regs[2] == ERESTARTSYS ||
207 regs->regs[2] == ERESTARTNOINTR) {
215 irix_sigreturn(struct pt_regs *regs)
217 struct sigctx_irix5 __user *context, *magic;
218 unsigned long umask, mask;
221 int error, 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 __user *) regs->regs[base + 4];
231 magic = (struct sigctx_irix5 __user *) 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 error = __get_user(regs->cp0_epc, &context->pc);
247 error |= __get_user(umask, &context->rmask);
250 for (i = 1; i < 32; i++, mask <<= 1) {
252 error |= __get_user(regs->regs[i], &context->regs[i]);
254 error |= __get_user(regs->hi, &context->hi);
255 error |= __get_user(regs->lo, &context->lo);
257 error |= __get_user(usedfp, &context->usedfp);
258 if ((umask & 1) && usedfp) {
259 fregs = (u64 *) ¤t->thread.fpu;
261 for(i = 0; i < 32; i++)
262 error |= __get_user(fregs[i], &context->fpregs[i]);
263 error |= __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
266 /* XXX do sigstack crapola here... XXX */
268 error |= __copy_from_user(&blocked, &context->sigset, sizeof(blocked)) ? -EFAULT : 0;
273 sigdelsetmask(&blocked, ~_BLOCKABLE);
274 spin_lock_irq(¤t->sighand->siglock);
275 current->blocked = blocked;
277 spin_unlock_irq(¤t->sighand->siglock);
280 * Don't let your children do this ...
282 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
283 do_syscall_trace(regs, 1);
284 __asm__ __volatile__(
292 force_sig(SIGSEGV, current);
295 struct sigact_irix5 {
297 void (*handler)(int);
303 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
305 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
306 (unsigned long) p->handler,
307 (unsigned long) p->sigset[0]);
312 irix_sigaction(int sig, const struct sigaction __user *act,
313 struct sigaction __user *oact, void __user *trampoline)
315 struct k_sigaction new_ka, old_ka;
319 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
320 (!old ? "0" : "OLD"), trampoline);
322 dump_sigact_irix5(new); printk(" ");
329 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
331 err = __get_user(new_ka.sa.sa_handler, &act->sa_handler);
332 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
334 err |= __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t)) ? -EFAULT : 0;
339 * Hmmm... methinks IRIX libc always passes a valid trampoline
340 * value for all invocations of sigaction. Will have to
341 * investigate. POSIX POSIX, die die die...
343 new_ka.sa_restorer = trampoline;
346 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
347 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
352 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
355 err = __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
356 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
357 err |= __copy_to_user(&oact->sa_mask, &old_ka.sa.sa_mask,
358 sizeof(sigset_t)) ? -EFAULT : 0;
366 asmlinkage int irix_sigpending(irix_sigset_t __user *set)
368 return do_sigpending(set, sizeof(*set));
371 asmlinkage int irix_sigprocmask(int how, irix_sigset_t __user *new,
372 irix_sigset_t __user *old)
374 sigset_t oldbits, newbits;
377 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
379 if (__copy_from_user(&newbits, new, sizeof(unsigned long)*4))
381 sigdelsetmask(&newbits, ~_BLOCKABLE);
383 spin_lock_irq(¤t->sighand->siglock);
384 oldbits = current->blocked;
388 sigorsets(&newbits, &oldbits, &newbits);
392 sigandsets(&newbits, &oldbits, &newbits);
399 siginitset(&newbits, newbits.sig[0]);
406 spin_unlock_irq(¤t->sighand->siglock);
409 return copy_to_user(old, ¤t->blocked,
410 sizeof(unsigned long)*4) ? -EFAULT : 0;
415 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
417 sigset_t saveset, newset;
418 sigset_t __user *uset;
420 uset = (sigset_t __user *) regs->regs[4];
421 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
423 sigdelsetmask(&newset, ~_BLOCKABLE);
425 spin_lock_irq(¤t->sighand->siglock);
426 saveset = current->blocked;
427 current->blocked = newset;
429 spin_unlock_irq(¤t->sighand->siglock);
431 regs->regs[2] = -EINTR;
433 current->state = TASK_INTERRUPTIBLE;
435 if (do_irix_signal(&saveset, regs))
440 /* hate hate hate... */
441 struct irix5_siginfo {
442 int sig, code, error;
444 char unused[128 - (3 * 4)]; /* Safety net. */
450 int utime, status, stime;
455 unsigned long fault_addr;
462 unsigned long sigval;
466 asmlinkage int irix_sigpoll_sys(unsigned long __user *set,
467 struct irix5_siginfo __user *info, struct timespec __user *tp)
469 long expire = MAX_SCHEDULE_TIMEOUT;
471 int i, sig, error, timeo = 0;
475 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
476 current->comm, current->pid, set, info, tp);
479 /* Must always specify the signal set. */
483 if (copy_from_user(&kset, set, sizeof(set)))
486 if (info && clear_user(info, sizeof(*info))) {
492 if (copy_from_user(&ktp, tp, sizeof(*tp)))
495 if (!ktp.tv_sec && !ktp.tv_nsec)
498 expire = timespec_to_jiffies(&ktp) +
499 (ktp.tv_sec || ktp.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... */
529 return copy_to_user(&info->sig, &sig, sizeof(sig));
534 /* Should not get here, but do something sane if we do. */
541 /* This is here because of irix5_siginfo definition. */
543 #define IRIX_P_PGID 2
546 extern int getrusage(struct task_struct *, int, struct rusage __user *);
554 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
556 asmlinkage int irix_waitsys(int type, int pid,
557 struct irix5_siginfo __user *info, int options,
558 struct rusage __user *ru)
561 DECLARE_WAITQUEUE(wait, current);
562 struct task_struct *tsk;
563 struct task_struct *p;
564 struct list_head *_p;
569 if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
573 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)))
576 if (options & ~W_MASK)
579 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;
615 retval = __put_user(SIGCHLD, &info->sig);
616 retval |= __put_user(0, &info->code);
617 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
618 retval |= __put_user((p->exit_code >> 8) & 0xff,
619 &info->stuff.procinfo.procdata.child.status);
620 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
621 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
629 current->signal->cutime += p->utime + p->signal->cutime;
630 current->signal->cstime += p->stime + p->signal->cstime;
632 getrusage(p, RUSAGE_BOTH, ru);
633 retval = __put_user(SIGCHLD, &info->sig);
634 retval |= __put_user(1, &info->code); /* CLD_EXITED */
635 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
636 retval |= __put_user((p->exit_code >> 8) & 0xff,
637 &info->stuff.procinfo.procdata.child.status);
638 retval |= __put_user(p->utime,
639 &info->stuff.procinfo.procdata.child.utime);
640 retval |= __put_user(p->stime,
641 &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->signal->wait_chldexit, &wait);
680 struct irix5_context {
684 struct { u32 sp, size, flags; } stack;
690 u32 weird_graphics_thing;
693 asmlinkage int irix_getcontext(struct pt_regs *regs)
695 int error, i, base = 0;
696 struct irix5_context __user *ctx;
699 if (regs->regs[2] == 1000)
701 ctx = (struct irix5_context __user *) regs->regs[base + 4];
704 printk("[%s:%d] irix_getcontext(%p)\n",
705 current->comm, current->pid, ctx);
708 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)));
711 error = __put_user(current->thread.irix_oldctx, &ctx->link);
713 error |= __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t)) ? -EFAULT : 0;
715 /* XXX Do sigstack stuff someday... */
716 error |= __put_user(0, &ctx->stack.sp);
717 error |= __put_user(0, &ctx->stack.size);
718 error |= __put_user(0, &ctx->stack.flags);
720 error |= __put_user(0, &ctx->weird_graphics_thing);
721 error |= __put_user(0, &ctx->regs[0]);
722 for (i = 1; i < 32; i++)
723 error |= __put_user(regs->regs[i], &ctx->regs[i]);
724 error |= __put_user(regs->lo, &ctx->regs[32]);
725 error |= __put_user(regs->hi, &ctx->regs[33]);
726 error |= __put_user(regs->cp0_cause, &ctx->regs[34]);
727 error |= __put_user(regs->cp0_epc, &ctx->regs[35]);
734 printk("Wheee, no code for saving IRIX FPU context yet.\n");
736 error |= __put_user(flags, &ctx->flags);
741 asmlinkage void irix_setcontext(struct pt_regs *regs)
743 struct irix5_context __user *ctx;
747 if (regs->regs[2] == 1000)
749 ctx = (struct irix5_context __user *) regs->regs[base + 4];
752 printk("[%s:%d] irix_setcontext(%p)\n",
753 current->comm, current->pid, ctx);
756 if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)))
759 err = __get_user(flags, &ctx->flags);
761 /* XXX sigstack garbage, todo... */
762 printk("Wheee, cannot do sigstack stuff in setcontext\n");
768 /* XXX extra control block stuff... todo... */
769 for (i = 1; i < 32; i++)
770 err |= __get_user(regs->regs[i], &ctx->regs[i]);
771 err |= __get_user(regs->lo, &ctx->regs[32]);
772 err |= __get_user(regs->hi, &ctx->regs[33]);
773 err |= __get_user(regs->cp0_epc, &ctx->regs[35]);
777 /* XXX fpu context, blah... */
778 printk(KERN_ERR "Wheee, cannot restore FPU context yet...\n");
780 err |= __get_user(current->thread.irix_oldctx, &ctx->link);
785 * Don't let your children do this ...
787 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
788 do_syscall_trace(regs, 1);
789 __asm__ __volatile__(
797 force_sigsegv(SIGSEGV, current);
800 struct irix_sigstack {
805 asmlinkage int irix_sigstack(struct irix_sigstack __user *new,
806 struct irix_sigstack __user *old)
809 printk("[%s:%d] irix_sigstack(%p,%p)\n",
810 current->comm, current->pid, new, old);
813 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
818 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
825 struct irix_sigaltstack { unsigned long sp; int size; int status; };
827 asmlinkage int irix_sigaltstack(struct irix_sigaltstack __user *new,
828 struct irix_sigaltstack __user *old)
831 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
832 current->comm, current->pid, new, old);
835 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
839 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
846 struct irix_procset {
847 int cmd, ltype, lid, rtype, rid;
850 asmlinkage int irix_sigsendset(struct irix_procset __user *pset, int sig)
852 if (!access_ok(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,