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 spin_lock_irq(¤t->sighand->siglock);
159 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
160 if (!(ka->sa.sa_flags & SA_NODEFER))
161 sigaddset(¤t->blocked,sig);
163 spin_unlock_irq(¤t->sighand->siglock);
166 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
168 struct k_sigaction ka;
173 * We want the common case to go fast, which is why we may in certain
174 * cases get here from kernel mode. Just return without doing anything
177 if (!user_mode(regs))
184 oldset = ¤t->blocked;
186 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
188 handle_signal(signr, &info, &ka, oldset, regs);
194 * Who's code doesn't conform to the restartable syscall convention
195 * dies here!!! The li instruction, a single machine instruction,
196 * must directly be followed by the syscall instruction.
199 if (regs->regs[2] == ERESTARTNOHAND ||
200 regs->regs[2] == ERESTARTSYS ||
201 regs->regs[2] == ERESTARTNOINTR) {
209 irix_sigreturn(struct pt_regs *regs)
211 struct sigctx_irix5 *context, *magic;
212 unsigned long umask, mask;
214 int sig, i, base = 0;
217 /* Always make any pending restarted system calls return -EINTR */
218 current_thread_info()->restart_block.fn = do_no_restart_syscall;
220 if (regs->regs[2] == 1000)
223 context = (struct sigctx_irix5 *) regs->regs[base + 4];
224 magic = (struct sigctx_irix5 *) regs->regs[base + 5];
225 sig = (int) regs->regs[base + 6];
227 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
228 current->comm, current->pid, context, magic, sig);
232 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
236 dump_irix5_sigctx(context);
239 __get_user(regs->cp0_epc, &context->pc);
240 umask = context->rmask; mask = 2;
241 for (i = 1; i < 32; i++, mask <<= 1) {
243 __get_user(regs->regs[i], &context->regs[i]);
245 __get_user(regs->hi, &context->hi);
246 __get_user(regs->lo, &context->lo);
248 if ((umask & 1) && context->usedfp) {
249 fregs = (u64 *) ¤t->thread.fpu;
250 for(i = 0; i < 32; i++)
251 fregs[i] = (u64) context->fpregs[i];
252 __get_user(current->thread.fpu.hard.fcr31, &context->fpcsr);
255 /* XXX do sigstack crapola here... XXX */
257 if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
260 sigdelsetmask(&blocked, ~_BLOCKABLE);
261 spin_lock_irq(¤t->sighand->siglock);
262 current->blocked = blocked;
264 spin_unlock_irq(¤t->sighand->siglock);
267 * Don't let your children do this ...
269 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
270 do_syscall_trace(regs, 1);
271 __asm__ __volatile__(
279 force_sig(SIGSEGV, current);
282 struct sigact_irix5 {
284 void (*handler)(int);
290 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
292 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
293 (unsigned long) p->handler,
294 (unsigned long) p->sigset[0]);
299 irix_sigaction(int sig, const struct sigaction *act,
300 struct sigaction *oact, void *trampoline)
302 struct k_sigaction new_ka, old_ka;
306 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
307 (!old ? "0" : "OLD"), trampoline);
309 dump_sigact_irix5(new); printk(" ");
314 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
315 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
316 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
319 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
322 * Hmmm... methinks IRIX libc always passes a valid trampoline
323 * value for all invocations of sigaction. Will have to
324 * investigate. POSIX POSIX, die die die...
326 new_ka.sa_restorer = trampoline;
329 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
330 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
333 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
334 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
335 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
337 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
344 asmlinkage int irix_sigpending(irix_sigset_t *set)
346 return do_sigpending(set, sizeof(*set));
349 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
351 sigset_t oldbits, newbits;
354 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
356 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
357 sigdelsetmask(&newbits, ~_BLOCKABLE);
359 spin_lock_irq(¤t->sighand->siglock);
360 oldbits = current->blocked;
364 sigorsets(&newbits, &oldbits, &newbits);
368 sigandsets(&newbits, &oldbits, &newbits);
375 siginitset(&newbits, newbits.sig[0]);
382 spin_unlock_irq(¤t->sighand->siglock);
385 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
387 __copy_to_user(old, ¤t->blocked, sizeof(unsigned long)*4);
393 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
395 sigset_t *uset, saveset, newset;
397 uset = (sigset_t *) regs->regs[4];
398 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
400 sigdelsetmask(&newset, ~_BLOCKABLE);
402 spin_lock_irq(¤t->sighand->siglock);
403 saveset = current->blocked;
404 current->blocked = newset;
406 spin_unlock_irq(¤t->sighand->siglock);
408 regs->regs[2] = -EINTR;
410 current->state = TASK_INTERRUPTIBLE;
412 if (do_irix_signal(&saveset, regs))
417 /* hate hate hate... */
418 struct irix5_siginfo {
419 int sig, code, error;
421 char unused[128 - (3 * 4)]; /* Safety net. */
427 int utime, status, stime;
432 unsigned long fault_addr;
439 unsigned long sigval;
443 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
446 long expire = MAX_SCHEDULE_TIMEOUT;
448 int i, sig, error, timeo = 0;
451 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
452 current->comm, current->pid, set, info, tp);
455 /* Must always specify the signal set. */
459 if (!access_ok(VERIFY_READ, set, sizeof(kset))) {
464 __copy_from_user(&kset, set, sizeof(set));
468 if (info && clear_user(info, sizeof(*info))) {
474 if (!access_ok(VERIFY_READ, tp, sizeof(*tp)))
476 if (!tp->tv_sec && !tp->tv_nsec) {
480 expire = timespec_to_jiffies(tp) + (tp->tv_sec||tp->tv_nsec);
486 expire = schedule_timeout_interruptible(expire);
489 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
497 if (signal_pending(current))
503 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
504 if (sigismember (&kset, sig))
506 if (sigismember (¤t->pending.signal, sig)) {
507 /* XXX need more than this... */
515 /* Should not get here, but do something sane if we do. */
522 /* This is here because of irix5_siginfo definition. */
524 #define IRIX_P_PGID 2
527 extern int getrusage(struct task_struct *, int, struct rusage __user *);
535 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
537 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
538 int options, struct rusage *ru)
541 DECLARE_WAITQUEUE(wait, current);
542 struct task_struct *tsk;
543 struct task_struct *p;
544 struct list_head *_p;
550 if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) {
555 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru))) {
560 if (options & ~(W_MASK)) {
564 if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
568 add_wait_queue(¤t->signal->wait_chldexit, &wait);
571 current->state = TASK_INTERRUPTIBLE;
572 read_lock(&tasklist_lock);
574 list_for_each(_p,&tsk->children) {
575 p = list_entry(_p,struct task_struct,sibling);
576 if ((type == IRIX_P_PID) && p->pid != pid)
578 if ((type == IRIX_P_PGID) && process_group(p) != pid)
580 if ((p->exit_signal != SIGCHLD))
587 if (!(options & (W_TRAPPED|W_STOPPED)) &&
588 !(p->ptrace & PT_PTRACED))
590 read_unlock(&tasklist_lock);
592 /* move to end of parent's list to avoid starvation */
593 write_lock_irq(&tasklist_lock);
595 add_parent(p, p->parent);
596 write_unlock_irq(&tasklist_lock);
597 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
599 retval |= __put_user(SIGCHLD, &info->sig);
600 retval |= __put_user(0, &info->code);
601 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
602 retval |= __put_user((p->exit_code >> 8) & 0xff,
603 &info->stuff.procinfo.procdata.child.status);
604 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
605 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
613 current->signal->cutime += p->utime + p->signal->cutime;
614 current->signal->cstime += p->stime + p->signal->cstime;
616 getrusage(p, RUSAGE_BOTH, ru);
617 __put_user(SIGCHLD, &info->sig);
618 __put_user(1, &info->code); /* CLD_EXITED */
619 __put_user(p->pid, &info->stuff.procinfo.pid);
620 __put_user((p->exit_code >> 8) & 0xff,
621 &info->stuff.procinfo.procdata.child.status);
623 &info->stuff.procinfo.procdata.child.utime);
625 &info->stuff.procinfo.procdata.child.stime);
627 if (p->real_parent != p->parent) {
628 write_lock_irq(&tasklist_lock);
630 p->parent = p->real_parent;
631 add_parent(p, p->parent);
632 do_notify_parent(p, SIGCHLD);
633 write_unlock_irq(&tasklist_lock);
640 tsk = next_thread(tsk);
642 read_unlock(&tasklist_lock);
645 if (options & W_NOHANG)
647 retval = -ERESTARTSYS;
648 if (signal_pending(current))
650 current->state = TASK_INTERRUPTIBLE;
656 current->state = TASK_RUNNING;
657 remove_wait_queue(¤t->signal->wait_chldexit, &wait);
663 struct irix5_context {
667 struct { u32 sp, size, flags; } stack;
673 u32 weird_graphics_thing;
676 asmlinkage int irix_getcontext(struct pt_regs *regs)
679 struct irix5_context *ctx;
682 if (regs->regs[2] == 1000)
684 ctx = (struct irix5_context *) regs->regs[base + 4];
687 printk("[%s:%d] irix_getcontext(%p)\n",
688 current->comm, current->pid, ctx);
691 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
694 __put_user(current->thread.irix_oldctx, &ctx->link);
696 __copy_to_user(&ctx->sigmask, ¤t->blocked, sizeof(irix_sigset_t));
698 /* XXX Do sigstack stuff someday... */
699 __put_user(0, &ctx->stack.sp);
700 __put_user(0, &ctx->stack.size);
701 __put_user(0, &ctx->stack.flags);
703 __put_user(0, &ctx->weird_graphics_thing);
704 __put_user(0, &ctx->regs[0]);
705 for (i = 1; i < 32; i++)
706 __put_user(regs->regs[i], &ctx->regs[i]);
707 __put_user(regs->lo, &ctx->regs[32]);
708 __put_user(regs->hi, &ctx->regs[33]);
709 __put_user(regs->cp0_cause, &ctx->regs[34]);
710 __put_user(regs->cp0_epc, &ctx->regs[35]);
717 printk("Wheee, no code for saving IRIX FPU context yet.\n");
719 __put_user(flags, &ctx->flags);
724 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
727 struct irix5_context *ctx;
729 if(regs->regs[2] == 1000)
731 ctx = (struct irix5_context *) regs->regs[base + 4];
734 printk("[%s:%d] irix_setcontext(%p)\n",
735 current->comm, current->pid, ctx);
738 if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))) {
743 if (ctx->flags & 0x02) {
744 /* XXX sigstack garbage, todo... */
745 printk("Wheee, cannot do sigstack stuff in setcontext\n");
748 if (ctx->flags & 0x04) {
751 /* XXX extra control block stuff... todo... */
752 for(i = 1; i < 32; i++)
753 regs->regs[i] = ctx->regs[i];
754 regs->lo = ctx->regs[32];
755 regs->hi = ctx->regs[33];
756 regs->cp0_epc = ctx->regs[35];
759 if (ctx->flags & 0x08) {
760 /* XXX fpu context, blah... */
761 printk("Wheee, cannot restore FPU context yet...\n");
763 current->thread.irix_oldctx = ctx->link;
764 error = regs->regs[2];
770 struct irix_sigstack { unsigned long sp; int status; };
772 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
777 printk("[%s:%d] irix_sigstack(%p,%p)\n",
778 current->comm, current->pid, new, old);
781 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
786 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
795 struct irix_sigaltstack { unsigned long sp; int size; int status; };
797 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
798 struct irix_sigaltstack *old)
803 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
804 current->comm, current->pid, new, old);
807 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
812 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
823 struct irix_procset {
824 int cmd, ltype, lid, rtype, rid;
827 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
829 if (!access_ok(VERIFY_READ, pset, sizeof(*pset)))
833 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
834 current->comm, current->pid,
835 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,