Linux 2.6.19.7
[linux-2.6/suspend2-2.6.19.git] / arch / mips / kernel / irixsig.c
blob2132485caa744bbeddca7b4af11070b2e8c8591f
1 /*
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.
7 */
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/mm.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/resource.h>
18 #include <asm/ptrace.h>
19 #include <asm/uaccess.h>
20 #include <asm/unistd.h>
22 #undef DEBUG_SIG
24 #define _S(nr) (1<<((nr)-1))
26 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
28 typedef struct {
29 unsigned long sig[4];
30 } irix_sigset_t;
32 struct sigctx_irix5 {
33 u32 rmask, cp0_status;
34 u64 pc;
35 u64 regs[32];
36 u64 fpregs[32];
37 u32 usedfp, fpcsr, fpeir, sstk_flags;
38 u64 hi, lo;
39 u64 cp0_cause, cp0_badvaddr, _unused0;
40 irix_sigset_t sigset;
41 u64 weird_fpu_thing;
42 u64 _unused1[31];
45 #ifdef DEBUG_SIG
46 /* Debugging */
47 static inline void dump_irix5_sigctx(struct sigctx_irix5 *c)
49 int i;
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);
55 printk("regs: ");
56 for(i = 0; i < 16; i++)
57 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
58 printk("\nregs: ");
59 for(i = 16; i < 32; i++)
60 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
61 printk("\nfpregs: ");
62 for(i = 0; i < 16; i++)
63 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
64 printk("\nfpregs: ");
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]);
79 #endif
81 static int setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
82 int signr, sigset_t *oldmask)
84 struct sigctx_irix5 __user *ctx;
85 unsigned long sp;
86 int error, i;
88 sp = regs->regs[29];
89 sp -= sizeof(struct sigctx_irix5);
90 sp &= ~(0xf);
91 ctx = (struct sigctx_irix5 __user *) sp;
92 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
93 goto segv_and_exit;
95 error = __put_user(0, &ctx->weird_fpu_thing);
96 error |= __put_user(~(0x00000001), &ctx->rmask);
97 error |= __put_user(0, &ctx->regs[0]);
98 for(i = 1; i < 32; i++)
99 error |= __put_user((u64) regs->regs[i], &ctx->regs[i]);
101 error |= __put_user((u64) regs->hi, &ctx->hi);
102 error |= __put_user((u64) regs->lo, &ctx->lo);
103 error |= __put_user((u64) regs->cp0_epc, &ctx->pc);
104 error |= __put_user(!!used_math(), &ctx->usedfp);
105 error |= __put_user((u64) regs->cp0_cause, &ctx->cp0_cause);
106 error |= __put_user((u64) regs->cp0_badvaddr, &ctx->cp0_badvaddr);
108 error |= __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
110 error |= __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t)) ? -EFAULT : 0;
112 if (error)
113 goto segv_and_exit;
115 #ifdef DEBUG_SIG
116 dump_irix5_sigctx(ctx);
117 #endif
119 regs->regs[4] = (unsigned long) signr;
120 regs->regs[5] = 0; /* XXX sigcode XXX */
121 regs->regs[6] = regs->regs[29] = sp;
122 regs->regs[7] = (unsigned long) ka->sa.sa_handler;
123 regs->regs[25] = regs->cp0_epc = (unsigned long) ka->sa_restorer;
125 return 1;
127 segv_and_exit:
128 force_sigsegv(signr, current);
129 return 0;
132 static int inline
133 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
134 int signr, sigset_t *oldmask, siginfo_t *info)
136 printk("Aiee: setup_tr_frame wants to be written");
137 do_exit(SIGSEGV);
140 static inline int handle_signal(unsigned long sig, siginfo_t *info,
141 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
143 int ret;
145 switch(regs->regs[0]) {
146 case ERESTARTNOHAND:
147 regs->regs[2] = EINTR;
148 break;
149 case ERESTARTSYS:
150 if(!(ka->sa.sa_flags & SA_RESTART)) {
151 regs->regs[2] = EINTR;
152 break;
154 /* fallthrough */
155 case ERESTARTNOINTR: /* Userland will reload $v0. */
156 regs->cp0_epc -= 8;
159 regs->regs[0] = 0; /* Don't deal with this again. */
161 if (ka->sa.sa_flags & SA_SIGINFO)
162 ret = setup_irix_rt_frame(ka, regs, sig, oldset, info);
163 else
164 ret = setup_irix_frame(ka, regs, sig, oldset);
166 spin_lock_irq(&current->sighand->siglock);
167 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
168 if (!(ka->sa.sa_flags & SA_NODEFER))
169 sigaddset(&current->blocked,sig);
170 recalc_sigpending();
171 spin_unlock_irq(&current->sighand->siglock);
173 return ret;
176 void do_irix_signal(struct pt_regs *regs)
178 struct k_sigaction ka;
179 siginfo_t info;
180 int signr;
181 sigset_t *oldset;
184 * We want the common case to go fast, which is why we may in certain
185 * cases get here from kernel mode. Just return without doing anything
186 * if so.
188 if (!user_mode(regs))
189 return;
191 if (test_thread_flag(TIF_RESTORE_SIGMASK))
192 oldset = &current->saved_sigmask;
193 else
194 oldset = &current->blocked;
196 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
197 if (signr > 0) {
198 /* Whee! Actually deliver the signal. */
199 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
200 /* a signal was successfully delivered; the saved
201 * sigmask will have been stored in the signal frame,
202 * and will be restored by sigreturn, so we can simply
203 * clear the TIF_RESTORE_SIGMASK flag */
204 if (test_thread_flag(TIF_RESTORE_SIGMASK))
205 clear_thread_flag(TIF_RESTORE_SIGMASK);
208 return;
212 * Who's code doesn't conform to the restartable syscall convention
213 * dies here!!! The li instruction, a single machine instruction,
214 * must directly be followed by the syscall instruction.
216 if (regs->regs[0]) {
217 if (regs->regs[2] == ERESTARTNOHAND ||
218 regs->regs[2] == ERESTARTSYS ||
219 regs->regs[2] == ERESTARTNOINTR) {
220 regs->cp0_epc -= 8;
222 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
223 regs->regs[2] = __NR_restart_syscall;
224 regs->regs[7] = regs->regs[26];
225 regs->cp0_epc -= 4;
227 regs->regs[0] = 0; /* Don't deal with this again. */
231 * If there's no signal to deliver, we just put the saved sigmask
232 * back
234 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
235 clear_thread_flag(TIF_RESTORE_SIGMASK);
236 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
240 asmlinkage void
241 irix_sigreturn(struct pt_regs *regs)
243 struct sigctx_irix5 __user *context, *magic;
244 unsigned long umask, mask;
245 u64 *fregs;
246 u32 usedfp;
247 int error, sig, i, base = 0;
248 sigset_t blocked;
250 /* Always make any pending restarted system calls return -EINTR */
251 current_thread_info()->restart_block.fn = do_no_restart_syscall;
253 if (regs->regs[2] == 1000)
254 base = 1;
256 context = (struct sigctx_irix5 __user *) regs->regs[base + 4];
257 magic = (struct sigctx_irix5 __user *) regs->regs[base + 5];
258 sig = (int) regs->regs[base + 6];
259 #ifdef DEBUG_SIG
260 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
261 current->comm, current->pid, context, magic, sig);
262 #endif
263 if (!context)
264 context = magic;
265 if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
266 goto badframe;
268 #ifdef DEBUG_SIG
269 dump_irix5_sigctx(context);
270 #endif
272 error = __get_user(regs->cp0_epc, &context->pc);
273 error |= __get_user(umask, &context->rmask);
275 mask = 2;
276 for (i = 1; i < 32; i++, mask <<= 1) {
277 if (umask & mask)
278 error |= __get_user(regs->regs[i], &context->regs[i]);
280 error |= __get_user(regs->hi, &context->hi);
281 error |= __get_user(regs->lo, &context->lo);
283 error |= __get_user(usedfp, &context->usedfp);
284 if ((umask & 1) && usedfp) {
285 fregs = (u64 *) &current->thread.fpu;
287 for(i = 0; i < 32; i++)
288 error |= __get_user(fregs[i], &context->fpregs[i]);
289 error |= __get_user(current->thread.fpu.fcr31, &context->fpcsr);
292 /* XXX do sigstack crapola here... XXX */
294 error |= __copy_from_user(&blocked, &context->sigset, sizeof(blocked)) ? -EFAULT : 0;
296 if (error)
297 goto badframe;
299 sigdelsetmask(&blocked, ~_BLOCKABLE);
300 spin_lock_irq(&current->sighand->siglock);
301 current->blocked = blocked;
302 recalc_sigpending();
303 spin_unlock_irq(&current->sighand->siglock);
306 * Don't let your children do this ...
308 __asm__ __volatile__(
309 "move\t$29,%0\n\t"
310 "j\tsyscall_exit"
311 :/* no outputs */
312 :"r" (&regs));
313 /* Unreached */
315 badframe:
316 force_sig(SIGSEGV, current);
319 struct sigact_irix5 {
320 int flags;
321 void (*handler)(int);
322 u32 sigset[4];
323 int _unused0[2];
326 #define SIG_SETMASK32 256 /* Goodie from SGI for BSD compatibility:
327 set only the low 32 bit of the sigset. */
329 #ifdef DEBUG_SIG
330 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
332 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
333 (unsigned long) p->handler,
334 (unsigned long) p->sigset[0]);
336 #endif
338 asmlinkage int
339 irix_sigaction(int sig, const struct sigaction __user *act,
340 struct sigaction __user *oact, void __user *trampoline)
342 struct k_sigaction new_ka, old_ka;
343 int ret;
345 #ifdef DEBUG_SIG
346 printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
347 (!old ? "0" : "OLD"), trampoline);
348 if(new) {
349 dump_sigact_irix5(new); printk(" ");
351 #endif
352 if (act) {
353 sigset_t mask;
354 int err;
356 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
357 return -EFAULT;
358 err = __get_user(new_ka.sa.sa_handler, &act->sa_handler);
359 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
361 err |= __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t)) ? -EFAULT : 0;
362 if (err)
363 return err;
366 * Hmmm... methinks IRIX libc always passes a valid trampoline
367 * value for all invocations of sigaction. Will have to
368 * investigate. POSIX POSIX, die die die...
370 new_ka.sa_restorer = trampoline;
373 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
374 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
376 if (!ret && oact) {
377 int err;
379 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
380 return -EFAULT;
382 err = __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
383 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
384 err |= __copy_to_user(&oact->sa_mask, &old_ka.sa.sa_mask,
385 sizeof(sigset_t)) ? -EFAULT : 0;
386 if (err)
387 return -EFAULT;
390 return ret;
393 asmlinkage int irix_sigpending(irix_sigset_t __user *set)
395 return do_sigpending(set, sizeof(*set));
398 asmlinkage int irix_sigprocmask(int how, irix_sigset_t __user *new,
399 irix_sigset_t __user *old)
401 sigset_t oldbits, newbits;
403 if (new) {
404 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
405 return -EFAULT;
406 if (__copy_from_user(&newbits, new, sizeof(unsigned long)*4))
407 return -EFAULT;
408 sigdelsetmask(&newbits, ~_BLOCKABLE);
410 spin_lock_irq(&current->sighand->siglock);
411 oldbits = current->blocked;
413 switch(how) {
414 case 1:
415 sigorsets(&newbits, &oldbits, &newbits);
416 break;
418 case 2:
419 sigandsets(&newbits, &oldbits, &newbits);
420 break;
422 case 3:
423 break;
425 case 256:
426 siginitset(&newbits, newbits.sig[0]);
427 break;
429 default:
430 return -EINVAL;
432 recalc_sigpending();
433 spin_unlock_irq(&current->sighand->siglock);
435 if (old)
436 return copy_to_user(old, &current->blocked,
437 sizeof(unsigned long)*4) ? -EFAULT : 0;
439 return 0;
442 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
444 sigset_t newset;
445 sigset_t __user *uset;
447 uset = (sigset_t __user *) regs->regs[4];
448 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
449 return -EFAULT;
450 sigdelsetmask(&newset, ~_BLOCKABLE);
452 spin_lock_irq(&current->sighand->siglock);
453 current->saved_sigmask = current->blocked;
454 current->blocked = newset;
455 recalc_sigpending();
456 spin_unlock_irq(&current->sighand->siglock);
458 current->state = TASK_INTERRUPTIBLE;
459 schedule();
460 set_thread_flag(TIF_RESTORE_SIGMASK);
461 return -ERESTARTNOHAND;
464 /* hate hate hate... */
465 struct irix5_siginfo {
466 int sig, code, error;
467 union {
468 char unused[128 - (3 * 4)]; /* Safety net. */
469 struct {
470 int pid;
471 union {
472 int uid;
473 struct {
474 int utime, status, stime;
475 } child;
476 } procdata;
477 } procinfo;
479 unsigned long fault_addr;
481 struct {
482 int fd;
483 long band;
484 } fileinfo;
486 unsigned long sigval;
487 } stuff;
490 asmlinkage int irix_sigpoll_sys(unsigned long __user *set,
491 struct irix5_siginfo __user *info, struct timespec __user *tp)
493 long expire = MAX_SCHEDULE_TIMEOUT;
494 sigset_t kset;
495 int i, sig, error, timeo = 0;
496 struct timespec ktp;
498 #ifdef DEBUG_SIG
499 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
500 current->comm, current->pid, set, info, tp);
501 #endif
503 /* Must always specify the signal set. */
504 if (!set)
505 return -EINVAL;
507 if (copy_from_user(&kset, set, sizeof(set)))
508 return -EFAULT;
510 if (info && clear_user(info, sizeof(*info))) {
511 error = -EFAULT;
512 goto out;
515 if (tp) {
516 if (copy_from_user(&ktp, tp, sizeof(*tp)))
517 return -EFAULT;
519 if (!ktp.tv_sec && !ktp.tv_nsec)
520 return -EINVAL;
522 expire = timespec_to_jiffies(&ktp) +
523 (ktp.tv_sec || ktp.tv_nsec);
526 while(1) {
527 long tmp = 0;
529 expire = schedule_timeout_interruptible(expire);
531 for (i=0; i<=4; i++)
532 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
534 if (tmp)
535 break;
536 if (!expire) {
537 timeo = 1;
538 break;
540 if (signal_pending(current))
541 return -EINTR;
543 if (timeo)
544 return -EAGAIN;
546 for (sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
547 if (sigismember (&kset, sig))
548 continue;
549 if (sigismember (&current->pending.signal, sig)) {
550 /* XXX need more than this... */
551 if (info)
552 return copy_to_user(&info->sig, &sig, sizeof(sig));
553 return 0;
557 /* Should not get here, but do something sane if we do. */
558 error = -EINTR;
560 out:
561 return error;
564 /* This is here because of irix5_siginfo definition. */
565 #define IRIX_P_PID 0
566 #define IRIX_P_PGID 2
567 #define IRIX_P_ALL 7
569 #define W_EXITED 1
570 #define W_TRAPPED 2
571 #define W_STOPPED 4
572 #define W_CONT 8
573 #define W_NOHANG 64
575 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
577 asmlinkage int irix_waitsys(int type, int pid,
578 struct irix5_siginfo __user *info, int options,
579 struct rusage __user *ru)
581 int flag, retval;
582 DECLARE_WAITQUEUE(wait, current);
583 struct task_struct *tsk;
584 struct task_struct *p;
585 struct list_head *_p;
587 if (!info)
588 return -EINVAL;
590 if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
591 return -EFAULT;
593 if (ru)
594 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)))
595 return -EFAULT;
597 if (options & ~W_MASK)
598 return -EINVAL;
600 if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL)
601 return -EINVAL;
603 add_wait_queue(&current->signal->wait_chldexit, &wait);
604 repeat:
605 flag = 0;
606 current->state = TASK_INTERRUPTIBLE;
607 read_lock(&tasklist_lock);
608 tsk = current;
609 list_for_each(_p,&tsk->children) {
610 p = list_entry(_p,struct task_struct,sibling);
611 if ((type == IRIX_P_PID) && p->pid != pid)
612 continue;
613 if ((type == IRIX_P_PGID) && process_group(p) != pid)
614 continue;
615 if ((p->exit_signal != SIGCHLD))
616 continue;
617 flag = 1;
618 switch (p->state) {
619 case TASK_STOPPED:
620 if (!p->exit_code)
621 continue;
622 if (!(options & (W_TRAPPED|W_STOPPED)) &&
623 !(p->ptrace & PT_PTRACED))
624 continue;
625 read_unlock(&tasklist_lock);
627 /* move to end of parent's list to avoid starvation */
628 write_lock_irq(&tasklist_lock);
629 remove_parent(p);
630 add_parent(p);
631 write_unlock_irq(&tasklist_lock);
632 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
633 if (retval)
634 goto end_waitsys;
636 retval = __put_user(SIGCHLD, &info->sig);
637 retval |= __put_user(0, &info->code);
638 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
639 retval |= __put_user((p->exit_code >> 8) & 0xff,
640 &info->stuff.procinfo.procdata.child.status);
641 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
642 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
643 if (retval)
644 goto end_waitsys;
646 p->exit_code = 0;
647 goto end_waitsys;
649 case EXIT_ZOMBIE:
650 current->signal->cutime += p->utime + p->signal->cutime;
651 current->signal->cstime += p->stime + p->signal->cstime;
652 if (ru != NULL)
653 getrusage(p, RUSAGE_BOTH, ru);
654 retval = __put_user(SIGCHLD, &info->sig);
655 retval |= __put_user(1, &info->code); /* CLD_EXITED */
656 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
657 retval |= __put_user((p->exit_code >> 8) & 0xff,
658 &info->stuff.procinfo.procdata.child.status);
659 retval |= __put_user(p->utime,
660 &info->stuff.procinfo.procdata.child.utime);
661 retval |= __put_user(p->stime,
662 &info->stuff.procinfo.procdata.child.stime);
663 if (retval)
664 return retval;
666 if (p->real_parent != p->parent) {
667 write_lock_irq(&tasklist_lock);
668 remove_parent(p);
669 p->parent = p->real_parent;
670 add_parent(p);
671 do_notify_parent(p, SIGCHLD);
672 write_unlock_irq(&tasklist_lock);
673 } else
674 release_task(p);
675 goto end_waitsys;
676 default:
677 continue;
679 tsk = next_thread(tsk);
681 read_unlock(&tasklist_lock);
682 if (flag) {
683 retval = 0;
684 if (options & W_NOHANG)
685 goto end_waitsys;
686 retval = -ERESTARTSYS;
687 if (signal_pending(current))
688 goto end_waitsys;
689 current->state = TASK_INTERRUPTIBLE;
690 schedule();
691 goto repeat;
693 retval = -ECHILD;
694 end_waitsys:
695 current->state = TASK_RUNNING;
696 remove_wait_queue(&current->signal->wait_chldexit, &wait);
698 return retval;
701 struct irix5_context {
702 u32 flags;
703 u32 link;
704 u32 sigmask[4];
705 struct { u32 sp, size, flags; } stack;
706 int regs[36];
707 u32 fpregs[32];
708 u32 fpcsr;
709 u32 _unused0;
710 u32 _unused1[47];
711 u32 weird_graphics_thing;
714 asmlinkage int irix_getcontext(struct pt_regs *regs)
716 int error, i, base = 0;
717 struct irix5_context __user *ctx;
718 unsigned long flags;
720 if (regs->regs[2] == 1000)
721 base = 1;
722 ctx = (struct irix5_context __user *) regs->regs[base + 4];
724 #ifdef DEBUG_SIG
725 printk("[%s:%d] irix_getcontext(%p)\n",
726 current->comm, current->pid, ctx);
727 #endif
729 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)));
730 return -EFAULT;
732 error = __put_user(current->thread.irix_oldctx, &ctx->link);
734 error |= __copy_to_user(&ctx->sigmask, &current->blocked, sizeof(irix_sigset_t)) ? -EFAULT : 0;
736 /* XXX Do sigstack stuff someday... */
737 error |= __put_user(0, &ctx->stack.sp);
738 error |= __put_user(0, &ctx->stack.size);
739 error |= __put_user(0, &ctx->stack.flags);
741 error |= __put_user(0, &ctx->weird_graphics_thing);
742 error |= __put_user(0, &ctx->regs[0]);
743 for (i = 1; i < 32; i++)
744 error |= __put_user(regs->regs[i], &ctx->regs[i]);
745 error |= __put_user(regs->lo, &ctx->regs[32]);
746 error |= __put_user(regs->hi, &ctx->regs[33]);
747 error |= __put_user(regs->cp0_cause, &ctx->regs[34]);
748 error |= __put_user(regs->cp0_epc, &ctx->regs[35]);
750 flags = 0x0f;
751 if (!used_math()) {
752 flags &= ~(0x08);
753 } else {
754 /* XXX wheee... */
755 printk("Wheee, no code for saving IRIX FPU context yet.\n");
757 error |= __put_user(flags, &ctx->flags);
759 return error;
762 asmlinkage void irix_setcontext(struct pt_regs *regs)
764 struct irix5_context __user *ctx;
765 int err, base = 0;
766 u32 flags;
768 if (regs->regs[2] == 1000)
769 base = 1;
770 ctx = (struct irix5_context __user *) regs->regs[base + 4];
772 #ifdef DEBUG_SIG
773 printk("[%s:%d] irix_setcontext(%p)\n",
774 current->comm, current->pid, ctx);
775 #endif
777 if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)))
778 goto segv_and_exit;
780 err = __get_user(flags, &ctx->flags);
781 if (flags & 0x02) {
782 /* XXX sigstack garbage, todo... */
783 printk("Wheee, cannot do sigstack stuff in setcontext\n");
786 if (flags & 0x04) {
787 int i;
789 /* XXX extra control block stuff... todo... */
790 for (i = 1; i < 32; i++)
791 err |= __get_user(regs->regs[i], &ctx->regs[i]);
792 err |= __get_user(regs->lo, &ctx->regs[32]);
793 err |= __get_user(regs->hi, &ctx->regs[33]);
794 err |= __get_user(regs->cp0_epc, &ctx->regs[35]);
797 if (flags & 0x08)
798 /* XXX fpu context, blah... */
799 printk(KERN_ERR "Wheee, cannot restore FPU context yet...\n");
801 err |= __get_user(current->thread.irix_oldctx, &ctx->link);
802 if (err)
803 goto segv_and_exit;
806 * Don't let your children do this ...
808 __asm__ __volatile__(
809 "move\t$29,%0\n\t"
810 "j\tsyscall_exit"
811 :/* no outputs */
812 :"r" (&regs));
813 /* Unreached */
815 segv_and_exit:
816 force_sigsegv(SIGSEGV, current);
819 struct irix_sigstack {
820 unsigned long sp;
821 int status;
824 asmlinkage int irix_sigstack(struct irix_sigstack __user *new,
825 struct irix_sigstack __user *old)
827 #ifdef DEBUG_SIG
828 printk("[%s:%d] irix_sigstack(%p,%p)\n",
829 current->comm, current->pid, new, old);
830 #endif
831 if (new) {
832 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
833 return -EFAULT;
836 if (old) {
837 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
838 return -EFAULT;
841 return 0;
844 struct irix_sigaltstack { unsigned long sp; int size; int status; };
846 asmlinkage int irix_sigaltstack(struct irix_sigaltstack __user *new,
847 struct irix_sigaltstack __user *old)
849 #ifdef DEBUG_SIG
850 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
851 current->comm, current->pid, new, old);
852 #endif
853 if (new)
854 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
855 return -EFAULT;
857 if (old) {
858 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
859 return -EFAULT;
862 return 0;
865 struct irix_procset {
866 int cmd, ltype, lid, rtype, rid;
869 asmlinkage int irix_sigsendset(struct irix_procset __user *pset, int sig)
871 if (!access_ok(VERIFY_READ, pset, sizeof(*pset)))
872 return -EFAULT;
873 #ifdef DEBUG_SIG
874 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
875 current->comm, current->pid,
876 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,
877 sig);
878 #endif
879 return -EINVAL;