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>
20 extern asmlinkage void do_syscall_trace(void);
24 #define _S(nr) (1<<((nr)-1))
26 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
33 u32 rmask, cp0_status;
37 u32 usedfp, fpcsr, fpeir, sstk_flags;
39 u64 cp0_cause, cp0_badvaddr, _unused0;
47 static inline void dump_irix5_sigctx(struct sigctx_irix5 *c)
51 printk("misc: rmask[%08lx] status[%08lx] pc[%08lx]\n",
52 (unsigned long) c->rmask,
53 (unsigned long) c->cp0_status,
54 (unsigned long) c->pc);
56 for(i = 0; i < 16; i++)
57 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
59 for(i = 16; i < 32; i++)
60 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
62 for(i = 0; i < 16; i++)
63 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
65 for(i = 16; i < 32; i++)
66 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
67 printk("misc: usedfp[%d] fpcsr[%08lx] fpeir[%08lx] stk_flgs[%08lx]\n",
68 (int) c->usedfp, (unsigned long) c->fpcsr,
69 (unsigned long) c->fpeir, (unsigned long) c->sstk_flags);
70 printk("misc: hi[%08lx] lo[%08lx] cause[%08lx] badvaddr[%08lx]\n",
71 (unsigned long) c->hi, (unsigned long) c->lo,
72 (unsigned long) c->cp0_cause, (unsigned long) c->cp0_badvaddr);
73 printk("misc: sigset<0>[%08lx] sigset<1>[%08lx] sigset<2>[%08lx] "
74 "sigset<3>[%08lx]\n", (unsigned long) c->sigset.sig[0],
75 (unsigned long) c->sigset.sig[1],
76 (unsigned long) c->sigset.sig[2],
77 (unsigned long) c->sigset.sig[3]);
81 static void setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
82 int signr, sigset_t *oldmask)
85 struct sigctx_irix5 *ctx;
89 sp -= sizeof(struct sigctx_irix5);
91 ctx = (struct sigctx_irix5 *) sp;
92 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
95 __put_user(0, &ctx->weird_fpu_thing);
96 __put_user(~(0x00000001), &ctx->rmask);
97 __put_user(0, &ctx->regs[0]);
98 for(i = 1; i < 32; i++)
99 __put_user((u64) regs->regs[i], &ctx->regs[i]);
101 __put_user((u64) regs->hi, &ctx->hi);
102 __put_user((u64) regs->lo, &ctx->lo);
103 __put_user((u64) regs->cp0_epc, &ctx->pc);
104 __put_user(current->used_math, &ctx->usedfp);
105 __put_user((u64) regs->cp0_cause, &ctx->cp0_cause);
106 __put_user((u64) regs->cp0_badvaddr, &ctx->cp0_badvaddr);
108 __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
110 __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t));
113 dump_irix5_sigctx(ctx);
116 regs->regs[4] = (unsigned long) signr;
117 regs->regs[5] = 0; /* XXX sigcode XXX */
118 regs->regs[6] = regs->regs[29] = sp;
119 regs->regs[7] = (unsigned long) ka->sa.sa_handler;
120 regs->regs[25] = regs->cp0_epc = (unsigned long) ka->sa_restorer;
125 if (signr == SIGSEGV)
126 ka->sa.sa_handler = SIG_DFL;
127 force_sig(SIGSEGV, 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 void handle_signal(unsigned long sig, siginfo_t *info,
139 sigset_t *oldset, struct pt_regs * regs)
141 struct k_sigaction *ka = ¤t->sighand->action[sig-1];
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 setup_irix_rt_frame(ka, regs, sig, oldset, info);
162 setup_irix_frame(ka, regs, sig, oldset);
164 if (ka->sa.sa_flags & SA_ONESHOT)
165 ka->sa.sa_handler = SIG_DFL;
166 if (!(ka->sa.sa_flags & SA_NODEFER)) {
167 spin_lock_irq(¤t->sighand->siglock);
168 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
169 sigaddset(¤t->blocked,sig);
171 spin_unlock_irq(¤t->sighand->siglock);
175 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
181 oldset = ¤t->blocked;
183 signr = get_signal_to_deliver(&info, regs, NULL);
185 handle_signal(signr, &info, oldset, regs);
190 * Who's code doesn't conform to the restartable syscall convention
191 * dies here!!! The li instruction, a single machine instruction,
192 * must directly be followed by the syscall instruction.
195 if (regs->regs[2] == ERESTARTNOHAND ||
196 regs->regs[2] == ERESTARTSYS ||
197 regs->regs[2] == ERESTARTNOINTR) {
205 irix_sigreturn(struct pt_regs *regs)
207 struct sigctx_irix5 *context, *magic;
208 unsigned long umask, mask;
210 int sig, i, base = 0;
213 /* Always make any pending restarted system calls return -EINTR */
214 current_thread_info()->restart_block.fn = do_no_restart_syscall;
216 if (regs->regs[2] == 1000)
219 context = (struct sigctx_irix5 *) regs->regs[base + 4];
220 magic = (struct sigctx_irix5 *) regs->regs[base + 5];
221 sig = (int) regs->regs[base + 6];
223 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
224 current->comm, current->pid, context, magic, sig);
228 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
232 dump_irix5_sigctx(context);
235 __get_user(regs->cp0_epc, &context->pc);
236 umask = context->rmask; mask = 2;
237 for (i = 1; i < 32; i++, mask <<= 1) {
239 __get_user(regs->regs[i], &context->regs[i]);
241 __get_user(regs->hi, &context->hi);
242 __get_user(regs->lo, &context->lo);
244 if ((umask & 1) && context->usedfp) {
245 fregs = (u64 *) ¤t->thread.fpu;
246 for(i = 0; i < 32; i++)
247 fregs[i] = (u64) context->fpregs[i];
248 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
251 /* XXX do sigstack crapola here... XXX */
253 if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
256 sigdelsetmask(&blocked, ~_BLOCKABLE);
257 spin_lock_irq(¤t->sighand->siglock);
258 current->blocked = blocked;
260 spin_unlock_irq(¤t->sighand->siglock);
263 * Don't let your children do this ...
265 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
267 __asm__ __volatile__(
275 force_sig(SIGSEGV, current);
278 struct sigact_irix5 {
280 void (*handler)(int);
286 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
288 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
289 (unsigned long) p->handler,
290 (unsigned long) p->sigset[0]);
295 irix_sigaction(int sig, const struct sigaction *act,
296 struct sigaction *oact, void *trampoline)
298 struct k_sigaction new_ka, old_ka;
302 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
303 (!old ? "0" : "OLD"), trampoline);
305 dump_sigact_irix5(new); printk(" ");
310 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
311 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
312 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
315 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
318 * Hmmm... methinks IRIX libc always passes a valid trampoline
319 * value for all invocations of sigaction. Will have to
320 * investigate. POSIX POSIX, die die die...
322 new_ka.sa_restorer = trampoline;
325 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
326 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
329 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
330 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
331 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
333 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
340 asmlinkage int irix_sigpending(irix_sigset_t *set)
342 return do_sigpending(set, sizeof(*set));
345 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
347 sigset_t oldbits, newbits;
351 error = verify_area(VERIFY_READ, new, sizeof(*new));
354 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
355 sigdelsetmask(&newbits, ~_BLOCKABLE);
357 spin_lock_irq(¤t->sighand->siglock);
358 oldbits = current->blocked;
362 sigorsets(&newbits, &oldbits, &newbits);
366 sigandsets(&newbits, &oldbits, &newbits);
373 siginitset(&newbits, newbits.sig[0]);
380 spin_unlock_irq(¤t->sighand->siglock);
383 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
386 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
392 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
394 sigset_t *uset, saveset, newset;
396 uset = (sigset_t *) regs->regs[4];
397 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
399 sigdelsetmask(&newset, ~_BLOCKABLE);
401 spin_lock_irq(¤t->sighand->siglock);
402 saveset = current->blocked;
403 current->blocked = newset;
405 spin_unlock_irq(¤t->sighand->siglock);
407 regs->regs[2] = -EINTR;
409 current->state = TASK_INTERRUPTIBLE;
411 if (do_irix_signal(&saveset, regs))
416 /* hate hate hate... */
417 struct irix5_siginfo {
418 int sig, code, error;
420 char unused[128 - (3 * 4)]; /* Safety net. */
426 int utime, status, stime;
431 unsigned long fault_addr;
438 unsigned long sigval;
442 static inline unsigned long timespectojiffies(struct timespec *value)
444 unsigned long sec = (unsigned) value->tv_sec;
445 long nsec = value->tv_nsec;
447 if (sec > (LONG_MAX / HZ))
449 nsec += 1000000000L / HZ - 1;
450 nsec /= 1000000000L / HZ;
451 return HZ * sec + nsec;
454 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
457 long expire = MAX_SCHEDULE_TIMEOUT;
459 int i, sig, error, timeo = 0;
462 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
463 current->comm, current->pid, set, info, tp);
466 /* Must always specify the signal set. */
470 error = verify_area(VERIFY_READ, set, sizeof(kset));
474 __copy_from_user(&kset, set, sizeof(set));
478 if (info && clear_user(info, sizeof(*info))) {
484 error = verify_area(VERIFY_READ, tp, sizeof(*tp));
487 if(!tp->tv_sec && !tp->tv_nsec) {
491 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
497 current->state = TASK_INTERRUPTIBLE;
498 expire = schedule_timeout(expire);
501 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
509 if (signal_pending(current))
515 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
516 if (sigismember (&kset, sig))
518 if (sigismember (¤t->pending.signal, sig)) {
519 /* XXX need more than this... */
527 /* Should not get here, but do something sane if we do. */
534 /* This is here because of irix5_siginfo definition. */
539 extern int getrusage(struct task_struct *, int, struct rusage *);
547 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
549 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
550 int options, struct rusage *ru)
553 DECLARE_WAITQUEUE(wait, current);
554 struct task_struct *tsk;
555 struct task_struct *p;
556 struct list_head *_p;
562 retval = verify_area(VERIFY_WRITE, info, sizeof(*info));
566 retval = verify_area(VERIFY_WRITE, ru, sizeof(*ru));
570 if (options & ~(W_MASK)) {
574 if (type != P_PID && type != P_PGID && type != P_ALL) {
578 add_wait_queue(¤t->wait_chldexit, &wait);
581 current->state = TASK_INTERRUPTIBLE;
582 read_lock(&tasklist_lock);
584 list_for_each(_p,&tsk->children) {
585 p = list_entry(_p,struct task_struct,sibling);
586 if ((type == P_PID) && p->pid != pid)
588 if ((type == P_PGID) && process_group(p) != pid)
590 if ((p->exit_signal != SIGCHLD))
597 if (!(options & (W_TRAPPED|W_STOPPED)) &&
598 !(p->ptrace & PT_PTRACED))
600 read_unlock(&tasklist_lock);
602 /* move to end of parent's list to avoid starvation */
603 write_lock_irq(&tasklist_lock);
605 add_parent(p, p->parent);
606 write_unlock_irq(&tasklist_lock);
607 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
609 retval |= __put_user(SIGCHLD, &info->sig);
610 retval |= __put_user(0, &info->code);
611 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
612 retval |= __put_user((p->exit_code >> 8) & 0xff,
613 &info->stuff.procinfo.procdata.child.status);
614 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
615 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
623 current->cutime += p->utime + p->cutime;
624 current->cstime += p->stime + p->cstime;
626 getrusage(p, RUSAGE_BOTH, ru);
627 __put_user(SIGCHLD, &info->sig);
628 __put_user(1, &info->code); /* CLD_EXITED */
629 __put_user(p->pid, &info->stuff.procinfo.pid);
630 __put_user((p->exit_code >> 8) & 0xff,
631 &info->stuff.procinfo.procdata.child.status);
633 &info->stuff.procinfo.procdata.child.utime);
635 &info->stuff.procinfo.procdata.child.stime);
637 if (p->real_parent != p->parent) {
638 write_lock_irq(&tasklist_lock);
640 p->parent = p->real_parent;
641 add_parent(p, p->parent);
642 do_notify_parent(p, SIGCHLD);
643 write_unlock_irq(&tasklist_lock);
650 tsk = next_thread(tsk);
652 read_unlock(&tasklist_lock);
655 if (options & W_NOHANG)
657 retval = -ERESTARTSYS;
658 if (signal_pending(current))
660 current->state = TASK_INTERRUPTIBLE;
666 current->state = TASK_RUNNING;
667 remove_wait_queue(¤t->wait_chldexit, &wait);
673 struct irix5_context {
677 struct { u32 sp, size, flags; } stack;
683 u32 weird_graphics_thing;
686 asmlinkage int irix_getcontext(struct pt_regs *regs)
688 int error, i, base = 0;
689 struct irix5_context *ctx;
692 if (regs->regs[2] == 1000)
694 ctx = (struct irix5_context *) regs->regs[base + 4];
697 printk("[%s:%d] irix_getcontext(%p)\n",
698 current->comm, current->pid, ctx);
701 error = verify_area(VERIFY_WRITE, ctx, sizeof(*ctx));
704 __put_user(current->thread.irix_oldctx, &ctx->link);
706 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
708 /* XXX Do sigstack stuff someday... */
709 __put_user(0, &ctx->stack.sp);
710 __put_user(0, &ctx->stack.size);
711 __put_user(0, &ctx->stack.flags);
713 __put_user(0, &ctx->weird_graphics_thing);
714 __put_user(0, &ctx->regs[0]);
715 for (i = 1; i < 32; i++)
716 __put_user(regs->regs[i], &ctx->regs[i]);
717 __put_user(regs->lo, &ctx->regs[32]);
718 __put_user(regs->hi, &ctx->regs[33]);
719 __put_user(regs->cp0_cause, &ctx->regs[34]);
720 __put_user(regs->cp0_epc, &ctx->regs[35]);
723 if(!current->used_math) {
727 printk("Wheee, no code for saving IRIX FPU context yet.\n");
729 __put_user(flags, &ctx->flags);
736 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
739 struct irix5_context *ctx;
741 if(regs->regs[2] == 1000)
743 ctx = (struct irix5_context *) regs->regs[base + 4];
746 printk("[%s:%d] irix_setcontext(%p)\n",
747 current->comm, current->pid, ctx);
750 error = verify_area(VERIFY_READ, ctx, sizeof(*ctx));
754 if (ctx->flags & 0x02) {
755 /* XXX sigstack garbage, todo... */
756 printk("Wheee, cannot do sigstack stuff in setcontext\n");
759 if (ctx->flags & 0x04) {
762 /* XXX extra control block stuff... todo... */
763 for(i = 1; i < 32; i++)
764 regs->regs[i] = ctx->regs[i];
765 regs->lo = ctx->regs[32];
766 regs->hi = ctx->regs[33];
767 regs->cp0_epc = ctx->regs[35];
770 if (ctx->flags & 0x08) {
771 /* XXX fpu context, blah... */
772 printk("Wheee, cannot restore FPU context yet...\n");
774 current->thread.irix_oldctx = ctx->link;
775 error = regs->regs[2];
781 struct irix_sigstack { unsigned long sp; int status; };
783 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
788 printk("[%s:%d] irix_sigstack(%p,%p)\n",
789 current->comm, current->pid, new, old);
792 error = verify_area(VERIFY_READ, new, sizeof(*new));
798 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
808 struct irix_sigaltstack { unsigned long sp; int size; int status; };
810 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
811 struct irix_sigaltstack *old)
816 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
817 current->comm, current->pid, new, old);
820 error = verify_area(VERIFY_READ, new, sizeof(*new));
826 error = verify_area(VERIFY_WRITE, old, sizeof(*old));
838 struct irix_procset {
839 int cmd, ltype, lid, rtype, rid;
842 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
846 error = verify_area(VERIFY_READ, pset, sizeof(*pset));
850 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
851 current->comm, current->pid,
852 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,