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 if (signr == SIGSEGV)
125 ka->sa.sa_handler = SIG_DFL;
126 force_sig(SIGSEGV, current);
130 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
131 int signr, sigset_t *oldmask, siginfo_t *info)
133 printk("Aiee: setup_tr_frame wants to be written");
137 static inline void handle_signal(unsigned long sig, siginfo_t *info,
138 sigset_t *oldset, struct pt_regs * regs)
140 struct k_sigaction *ka = ¤t->sighand->action[sig-1];
142 switch(regs->regs[0]) {
144 regs->regs[2] = EINTR;
147 if(!(ka->sa.sa_flags & SA_RESTART)) {
148 regs->regs[2] = EINTR;
152 case ERESTARTNOINTR: /* Userland will reload $v0. */
156 regs->regs[0] = 0; /* Don't deal with this again. */
158 if (ka->sa.sa_flags & SA_SIGINFO)
159 setup_irix_rt_frame(ka, regs, sig, oldset, info);
161 setup_irix_frame(ka, regs, sig, oldset);
163 if (ka->sa.sa_flags & SA_ONESHOT)
164 ka->sa.sa_handler = SIG_DFL;
165 if (!(ka->sa.sa_flags & SA_NODEFER)) {
166 spin_lock_irq(¤t->sighand->siglock);
167 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
168 sigaddset(¤t->blocked,sig);
170 spin_unlock_irq(¤t->sighand->siglock);
174 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
180 * We want the common case to go fast, which is why we may in certain
181 * cases get here from kernel mode. Just return without doing anything
184 if (!user_mode(regs))
187 if (current->flags & PF_FREEZE) {
193 oldset = ¤t->blocked;
195 signr = get_signal_to_deliver(&info, regs, NULL);
197 handle_signal(signr, &info, oldset, regs);
203 * Who's code doesn't conform to the restartable syscall convention
204 * dies here!!! The li instruction, a single machine instruction,
205 * must directly be followed by the syscall instruction.
208 if (regs->regs[2] == ERESTARTNOHAND ||
209 regs->regs[2] == ERESTARTSYS ||
210 regs->regs[2] == ERESTARTNOINTR) {
218 irix_sigreturn(struct pt_regs *regs)
220 struct sigctx_irix5 *context, *magic;
221 unsigned long umask, mask;
223 int sig, i, base = 0;
226 /* Always make any pending restarted system calls return -EINTR */
227 current_thread_info()->restart_block.fn = do_no_restart_syscall;
229 if (regs->regs[2] == 1000)
232 context = (struct sigctx_irix5 *) regs->regs[base + 4];
233 magic = (struct sigctx_irix5 *) regs->regs[base + 5];
234 sig = (int) regs->regs[base + 6];
236 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
237 current->comm, current->pid, context, magic, sig);
241 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
245 dump_irix5_sigctx(context);
248 __get_user(regs->cp0_epc, &context->pc);
249 umask = context->rmask; mask = 2;
250 for (i = 1; i < 32; i++, mask <<= 1) {
252 __get_user(regs->regs[i], &context->regs[i]);
254 __get_user(regs->hi, &context->hi);
255 __get_user(regs->lo, &context->lo);
257 if ((umask & 1) && context->usedfp) {
258 fregs = (u64 *) ¤t->thread.fpu;
259 for(i = 0; i < 32; i++)
260 fregs[i] = (u64) context->fpregs[i];
261 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
264 /* XXX do sigstack crapola here... XXX */
266 if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
269 sigdelsetmask(&blocked, ~_BLOCKABLE);
270 spin_lock_irq(¤t->sighand->siglock);
271 current->blocked = blocked;
273 spin_unlock_irq(¤t->sighand->siglock);
276 * Don't let your children do this ...
278 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
279 do_syscall_trace(regs, 1);
280 __asm__ __volatile__(
288 force_sig(SIGSEGV, current);
291 struct sigact_irix5 {
293 void (*handler)(int);
299 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
301 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
302 (unsigned long) p->handler,
303 (unsigned long) p->sigset[0]);
308 irix_sigaction(int sig, const struct sigaction *act,
309 struct sigaction *oact, void *trampoline)
311 struct k_sigaction new_ka, old_ka;
315 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
316 (!old ? "0" : "OLD"), trampoline);
318 dump_sigact_irix5(new); printk(" ");
323 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
324 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
325 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
328 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
331 * Hmmm... methinks IRIX libc always passes a valid trampoline
332 * value for all invocations of sigaction. Will have to
333 * investigate. POSIX POSIX, die die die...
335 new_ka.sa_restorer = trampoline;
338 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
339 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
342 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
343 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
344 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
346 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
353 asmlinkage int irix_sigpending(irix_sigset_t *set)
355 return do_sigpending(set, sizeof(*set));
358 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
360 sigset_t oldbits, newbits;
364 error = verify_area(VERIFY_READ, new, sizeof(*new));
367 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
368 sigdelsetmask(&newbits, ~_BLOCKABLE);
370 spin_lock_irq(¤t->sighand->siglock);
371 oldbits = current->blocked;
375 sigorsets(&newbits, &oldbits, &newbits);
379 sigandsets(&newbits, &oldbits, &newbits);
386 siginitset(&newbits, newbits.sig[0]);
393 spin_unlock_irq(¤t->sighand->siglock);
396 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
399 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
405 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
407 sigset_t *uset, saveset, newset;
409 uset = (sigset_t *) regs->regs[4];
410 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
412 sigdelsetmask(&newset, ~_BLOCKABLE);
414 spin_lock_irq(¤t->sighand->siglock);
415 saveset = current->blocked;
416 current->blocked = newset;
418 spin_unlock_irq(¤t->sighand->siglock);
420 regs->regs[2] = -EINTR;
422 current->state = TASK_INTERRUPTIBLE;
424 if (do_irix_signal(&saveset, regs))
429 /* hate hate hate... */
430 struct irix5_siginfo {
431 int sig, code, error;
433 char unused[128 - (3 * 4)]; /* Safety net. */
439 int utime, status, stime;
444 unsigned long fault_addr;
451 unsigned long sigval;
455 static inline unsigned long timespectojiffies(struct timespec *value)
457 unsigned long sec = (unsigned) value->tv_sec;
458 long nsec = value->tv_nsec;
460 if (sec > (LONG_MAX / HZ))
462 nsec += 1000000000L / HZ - 1;
463 nsec /= 1000000000L / HZ;
464 return HZ * sec + nsec;
467 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
470 long expire = MAX_SCHEDULE_TIMEOUT;
472 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 error = verify_area(VERIFY_READ, set, sizeof(kset));
487 __copy_from_user(&kset, set, sizeof(set));
491 if (info && clear_user(info, sizeof(*info))) {
497 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
500 if(!tp->tv_sec && !tp->tv_nsec) {
504 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
510 current->state = TASK_INTERRUPTIBLE;
511 expire = schedule_timeout(expire);
514 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
522 if (signal_pending(current))
528 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
529 if (sigismember (&kset, sig))
531 if (sigismember (¤t->pending.signal, sig)) {
532 /* XXX need more than this... */
540 /* Should not get here, but do something sane if we do. */
547 /* This is here because of irix5_siginfo definition. */
552 extern int getrusage(struct task_struct *, int, struct rusage __user *);
560 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
562 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
563 int options, struct rusage *ru)
566 DECLARE_WAITQUEUE(wait, current);
567 struct task_struct *tsk;
568 struct task_struct *p;
569 struct list_head *_p;
575 retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
579 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
583 if (options & ~(W_MASK)) {
587 if (type != P_PID && type != P_PGID && type != P_ALL) {
591 add_wait_queue(¤t->wait_chldexit, &wait);
594 current->state = TASK_INTERRUPTIBLE;
595 read_lock(&tasklist_lock);
597 list_for_each(_p,&tsk->children) {
598 p = list_entry(_p,struct task_struct,sibling);
599 if ((type == P_PID) && p->pid != pid)
601 if ((type == P_PGID) && process_group(p) != pid)
603 if ((p->exit_signal != SIGCHLD))
610 if (!(options & (W_TRAPPED|W_STOPPED)) &&
611 !(p->ptrace & PT_PTRACED))
613 read_unlock(&tasklist_lock);
615 /* move to end of parent's list to avoid starvation */
616 write_lock_irq(&tasklist_lock);
618 add_parent(p, p->parent);
619 write_unlock_irq(&tasklist_lock);
620 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
622 retval |= __put_user(SIGCHLD, &info->sig);
623 retval |= __put_user(0, &info->code);
624 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
625 retval |= __put_user((p->exit_code >> 8) & 0xff,
626 &info->stuff.procinfo.procdata.child.status);
627 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
628 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
636 current->cutime += p->utime + p->cutime;
637 current->cstime += p->stime + p->cstime;
639 getrusage(p, RUSAGE_BOTH, ru);
640 __put_user(SIGCHLD, &info->sig);
641 __put_user(1, &info->code); /* CLD_EXITED */
642 __put_user(p->pid, &info->stuff.procinfo.pid);
643 __put_user((p->exit_code >> 8) & 0xff,
644 &info->stuff.procinfo.procdata.child.status);
646 &info->stuff.procinfo.procdata.child.utime);
648 &info->stuff.procinfo.procdata.child.stime);
650 if (p->real_parent != p->parent) {
651 write_lock_irq(&tasklist_lock);
653 p->parent = p->real_parent;
654 add_parent(p, p->parent);
655 do_notify_parent(p, SIGCHLD);
656 write_unlock_irq(&tasklist_lock);
663 tsk = next_thread(tsk);
665 read_unlock(&tasklist_lock);
668 if (options & W_NOHANG)
670 retval = -ERESTARTSYS;
671 if (signal_pending(current))
673 current->state = TASK_INTERRUPTIBLE;
679 current->state = TASK_RUNNING;
680 remove_wait_queue(¤t->wait_chldexit, &wait);
686 struct irix5_context {
690 struct { u32 sp, size, flags; } stack;
696 u32 weird_graphics_thing;
699 asmlinkage int irix_getcontext(struct pt_regs *regs)
701 int error, i, base = 0;
702 struct irix5_context *ctx;
705 if (regs->regs[2] == 1000)
707 ctx = (struct irix5_context *) regs->regs[base + 4];
710 printk("[%s:%d] irix_getcontext(%p)\n",
711 current->comm, current->pid, ctx);
714 error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
717 __put_user(current->thread.irix_oldctx, &ctx->link);
719 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
721 /* XXX Do sigstack stuff someday... */
722 __put_user(0, &ctx->stack.sp);
723 __put_user(0, &ctx->stack.size);
724 __put_user(0, &ctx->stack.flags);
726 __put_user(0, &ctx->weird_graphics_thing);
727 __put_user(0, &ctx->regs[0]);
728 for (i = 1; i < 32; i++)
729 __put_user(regs->regs[i], &ctx->regs[i]);
730 __put_user(regs->lo, &ctx->regs[32]);
731 __put_user(regs->hi, &ctx->regs[33]);
732 __put_user(regs->cp0_cause, &ctx->regs[34]);
733 __put_user(regs->cp0_epc, &ctx->regs[35]);
736 if(!current->used_math) {
740 printk("Wheee, no code for saving IRIX FPU context yet.\n");
742 __put_user(flags, &ctx->flags);
749 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
752 struct irix5_context *ctx;
754 if(regs->regs[2] == 1000)
756 ctx = (struct irix5_context *) regs->regs[base + 4];
759 printk("[%s:%d] irix_setcontext(%p)\n",
760 current->comm, current->pid, ctx);
763 error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
767 if (ctx->flags & 0x02) {
768 /* XXX sigstack garbage, todo... */
769 printk("Wheee, cannot do sigstack stuff in setcontext\n");
772 if (ctx->flags & 0x04) {
775 /* XXX extra control block stuff... todo... */
776 for(i = 1; i < 32; i++)
777 regs->regs[i] = ctx->regs[i];
778 regs->lo = ctx->regs[32];
779 regs->hi = ctx->regs[33];
780 regs->cp0_epc = ctx->regs[35];
783 if (ctx->flags & 0x08) {
784 /* XXX fpu context, blah... */
785 printk("Wheee, cannot restore FPU context yet...\n");
787 current->thread.irix_oldctx = ctx->link;
788 error = regs->regs[2];
794 struct irix_sigstack { unsigned long sp; int status; };
796 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
801 printk("[%s:%d] irix_sigstack(%p,%p)\n",
802 current->comm, current->pid, new, old);
805 error = verify_area(VERIFY_READ, new, sizeof(*new));
811 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
821 struct irix_sigaltstack { unsigned long sp; int size; int status; };
823 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
824 struct irix_sigaltstack *old)
829 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
830 current->comm, current->pid, new, old);
833 error = verify_area(VERIFY_READ, new, sizeof(*new));
839 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
851 struct irix_procset {
852 int cmd, ltype, lid, rtype, rid;
855 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
859 error = verify_area(VERIFY_READ, pset, sizeof(*pset));
863 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
864 current->comm, current->pid,
865 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,