Pull sn-features into release branch
[sfrench/cifs-2.6.git] / arch / mips / kernel / irixsig.c
1 /*
2  * irixsig.c: WHEEE, IRIX signals!  YOW, am I compatible or what?!?!
3  *
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
17 #include <asm/ptrace.h>
18 #include <asm/uaccess.h>
19
20 #undef DEBUG_SIG
21
22 #define _S(nr) (1<<((nr)-1))
23
24 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
25
26 typedef struct {
27         unsigned long sig[4];
28 } irix_sigset_t;
29
30 struct sigctx_irix5 {
31         u32 rmask, cp0_status;
32         u64 pc;
33         u64 regs[32];
34         u64 fpregs[32];
35         u32 usedfp, fpcsr, fpeir, sstk_flags;
36         u64 hi, lo;
37         u64 cp0_cause, cp0_badvaddr, _unused0;
38         irix_sigset_t sigset;
39         u64 weird_fpu_thing;
40         u64 _unused1[31];
41 };
42
43 #ifdef DEBUG_SIG
44 /* Debugging */
45 static inline void dump_irix5_sigctx(struct sigctx_irix5 *c)
46 {
47         int i;
48
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);
53         printk("regs: ");
54         for(i = 0; i < 16; i++)
55                 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
56         printk("\nregs: ");
57         for(i = 16; i < 32; i++)
58                 printk("[%d]<%08lx> ", i, (unsigned long) c->regs[i]);
59         printk("\nfpregs: ");
60         for(i = 0; i < 16; i++)
61                 printk("[%d]<%08lx> ", i, (unsigned long) c->fpregs[i]);
62         printk("\nfpregs: ");
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]);
76 }
77 #endif
78
79 static void setup_irix_frame(struct k_sigaction *ka, struct pt_regs *regs,
80                              int signr, sigset_t *oldmask)
81 {
82         unsigned long sp;
83         struct sigctx_irix5 *ctx;
84         int i;
85
86         sp = regs->regs[29];
87         sp -= sizeof(struct sigctx_irix5);
88         sp &= ~(0xf);
89         ctx = (struct sigctx_irix5 *) sp;
90         if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
91                 goto segv_and_exit;
92
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]);
98
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);
105
106         __put_user(0, &ctx->sstk_flags); /* XXX sigstack unimp... todo... */
107
108         __copy_to_user(&ctx->sigset, oldmask, sizeof(irix_sigset_t));
109
110 #ifdef DEBUG_SIG
111         dump_irix5_sigctx(ctx);
112 #endif
113
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;
119
120         return;
121
122 segv_and_exit:
123         force_sigsegv(signr, current);
124 }
125
126 static void inline
127 setup_irix_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
128                int signr, sigset_t *oldmask, siginfo_t *info)
129 {
130         printk("Aiee: setup_tr_frame wants to be written");
131         do_exit(SIGSEGV);
132 }
133
134 static inline void handle_signal(unsigned long sig, siginfo_t *info,
135         struct k_sigaction *ka, sigset_t *oldset, struct pt_regs * regs)
136 {
137         switch(regs->regs[0]) {
138         case ERESTARTNOHAND:
139                 regs->regs[2] = EINTR;
140                 break;
141         case ERESTARTSYS:
142                 if(!(ka->sa.sa_flags & SA_RESTART)) {
143                         regs->regs[2] = EINTR;
144                         break;
145                 }
146         /* fallthrough */
147         case ERESTARTNOINTR:            /* Userland will reload $v0.  */
148                 regs->cp0_epc -= 8;
149         }
150
151         regs->regs[0] = 0;              /* Don't deal with this again.  */
152
153         if (ka->sa.sa_flags & SA_SIGINFO)
154                 setup_irix_rt_frame(ka, regs, sig, oldset, info);
155         else
156                 setup_irix_frame(ka, regs, sig, oldset);
157
158         spin_lock_irq(&current->sighand->siglock);
159         sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
160         if (!(ka->sa.sa_flags & SA_NODEFER))
161                 sigaddset(&current->blocked,sig);
162         recalc_sigpending();
163         spin_unlock_irq(&current->sighand->siglock);
164 }
165
166 asmlinkage int do_irix_signal(sigset_t *oldset, struct pt_regs *regs)
167 {
168         struct k_sigaction ka;
169         siginfo_t info;
170         int signr;
171
172         /*
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
175          * if so.
176          */
177         if (!user_mode(regs))
178                 return 1;
179
180         if (try_to_freeze())
181                 goto no_signal;
182
183         if (!oldset)
184                 oldset = &current->blocked;
185
186         signr = get_signal_to_deliver(&info, &ka, regs, NULL);
187         if (signr > 0) {
188                 handle_signal(signr, &info, &ka, oldset, regs);
189                 return 1;
190         }
191
192 no_signal:
193         /*
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.
197          */
198         if (regs->regs[0]) {
199                 if (regs->regs[2] == ERESTARTNOHAND ||
200                     regs->regs[2] == ERESTARTSYS ||
201                     regs->regs[2] == ERESTARTNOINTR) {
202                         regs->cp0_epc -= 8;
203                 }
204         }
205         return 0;
206 }
207
208 asmlinkage void
209 irix_sigreturn(struct pt_regs *regs)
210 {
211         struct sigctx_irix5 *context, *magic;
212         unsigned long umask, mask;
213         u64 *fregs;
214         int sig, i, base = 0;
215         sigset_t blocked;
216
217         /* Always make any pending restarted system calls return -EINTR */
218         current_thread_info()->restart_block.fn = do_no_restart_syscall;
219
220         if (regs->regs[2] == 1000)
221                 base = 1;
222
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];
226 #ifdef DEBUG_SIG
227         printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
228                current->comm, current->pid, context, magic, sig);
229 #endif
230         if (!context)
231                 context = magic;
232         if (!access_ok(VERIFY_READ, context, sizeof(struct sigctx_irix5)))
233                 goto badframe;
234
235 #ifdef DEBUG_SIG
236         dump_irix5_sigctx(context);
237 #endif
238
239         __get_user(regs->cp0_epc, &context->pc);
240         umask = context->rmask; mask = 2;
241         for (i = 1; i < 32; i++, mask <<= 1) {
242                 if(umask & mask)
243                         __get_user(regs->regs[i], &context->regs[i]);
244         }
245         __get_user(regs->hi, &context->hi);
246         __get_user(regs->lo, &context->lo);
247
248         if ((umask & 1) && context->usedfp) {
249                 fregs = (u64 *) &current->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);
253         }
254
255         /* XXX do sigstack crapola here... XXX */
256
257         if (__copy_from_user(&blocked, &context->sigset, sizeof(blocked)))
258                 goto badframe;
259
260         sigdelsetmask(&blocked, ~_BLOCKABLE);
261         spin_lock_irq(&current->sighand->siglock);
262         current->blocked = blocked;
263         recalc_sigpending();
264         spin_unlock_irq(&current->sighand->siglock);
265
266         /*
267          * Don't let your children do this ...
268          */
269         if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
270                 do_syscall_trace(regs, 1);
271         __asm__ __volatile__(
272                 "move\t$29,%0\n\t"
273                 "j\tsyscall_exit"
274                 :/* no outputs */
275                 :"r" (&regs));
276                 /* Unreached */
277
278 badframe:
279         force_sig(SIGSEGV, current);
280 }
281
282 struct sigact_irix5 {
283         int flags;
284         void (*handler)(int);
285         u32 sigset[4];
286         int _unused0[2];
287 };
288
289 #ifdef DEBUG_SIG
290 static inline void dump_sigact_irix5(struct sigact_irix5 *p)
291 {
292         printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p->flags,
293                (unsigned long) p->handler,
294                (unsigned long) p->sigset[0]);
295 }
296 #endif
297
298 asmlinkage int
299 irix_sigaction(int sig, const struct sigaction *act,
300               struct sigaction *oact, void *trampoline)
301 {
302         struct k_sigaction new_ka, old_ka;
303         int ret;
304
305 #ifdef DEBUG_SIG
306         printk(" (%d,%s,%s,%08lx) ", sig, (!new ? "0" : "NEW"),
307                (!old ? "0" : "OLD"), trampoline);
308         if(new) {
309                 dump_sigact_irix5(new); printk(" ");
310         }
311 #endif
312         if (act) {
313                 sigset_t mask;
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))
317                         return -EFAULT;
318
319                 __copy_from_user(&mask, &act->sa_mask, sizeof(sigset_t));
320
321                 /*
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...
325                  */
326                 new_ka.sa_restorer = trampoline;
327         }
328
329 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
330         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
331
332         if (!ret && oact) {
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))
336                         return -EFAULT;
337                 __copy_to_user(&old_ka.sa.sa_mask, &oact->sa_mask,
338                                sizeof(sigset_t));
339         }
340
341         return ret;
342 }
343
344 asmlinkage int irix_sigpending(irix_sigset_t *set)
345 {
346         return do_sigpending(set, sizeof(*set));
347 }
348
349 asmlinkage int irix_sigprocmask(int how, irix_sigset_t *new, irix_sigset_t *old)
350 {
351         sigset_t oldbits, newbits;
352
353         if (new) {
354                 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
355                         return -EFAULT;
356                 __copy_from_user(&newbits, new, sizeof(unsigned long)*4);
357                 sigdelsetmask(&newbits, ~_BLOCKABLE);
358
359                 spin_lock_irq(&current->sighand->siglock);
360                 oldbits = current->blocked;
361
362                 switch(how) {
363                 case 1:
364                         sigorsets(&newbits, &oldbits, &newbits);
365                         break;
366
367                 case 2:
368                         sigandsets(&newbits, &oldbits, &newbits);
369                         break;
370
371                 case 3:
372                         break;
373
374                 case 256:
375                         siginitset(&newbits, newbits.sig[0]);
376                         break;
377
378                 default:
379                         return -EINVAL;
380                 }
381                 recalc_sigpending();
382                 spin_unlock_irq(&current->sighand->siglock);
383         }
384         if(old) {
385                 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
386                         return -EFAULT;
387                 __copy_to_user(old, &current->blocked, sizeof(unsigned long)*4);
388         }
389
390         return 0;
391 }
392
393 asmlinkage int irix_sigsuspend(struct pt_regs *regs)
394 {
395         sigset_t *uset, saveset, newset;
396
397         uset = (sigset_t *) regs->regs[4];
398         if (copy_from_user(&newset, uset, sizeof(sigset_t)))
399                 return -EFAULT;
400         sigdelsetmask(&newset, ~_BLOCKABLE);
401
402         spin_lock_irq(&current->sighand->siglock);
403         saveset = current->blocked;
404         current->blocked = newset;
405         recalc_sigpending();
406         spin_unlock_irq(&current->sighand->siglock);
407
408         regs->regs[2] = -EINTR;
409         while (1) {
410                 current->state = TASK_INTERRUPTIBLE;
411                 schedule();
412                 if (do_irix_signal(&saveset, regs))
413                         return -EINTR;
414         }
415 }
416
417 /* hate hate hate... */
418 struct irix5_siginfo {
419         int sig, code, error;
420         union {
421                 char unused[128 - (3 * 4)]; /* Safety net. */
422                 struct {
423                         int pid;
424                         union {
425                                 int uid;
426                                 struct {
427                                         int utime, status, stime;
428                                 } child;
429                         } procdata;
430                 } procinfo;
431
432                 unsigned long fault_addr;
433
434                 struct {
435                         int fd;
436                         long band;
437                 } fileinfo;
438
439                 unsigned long sigval;
440         } stuff;
441 };
442
443 asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
444                                 struct timespec *tp)
445 {
446         long expire = MAX_SCHEDULE_TIMEOUT;
447         sigset_t kset;
448         int i, sig, error, timeo = 0;
449
450 #ifdef DEBUG_SIG
451         printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
452                current->comm, current->pid, set, info, tp);
453 #endif
454
455         /* Must always specify the signal set. */
456         if (!set)
457                 return -EINVAL;
458
459         if (!access_ok(VERIFY_READ, set, sizeof(kset))) {
460                 error = -EFAULT;
461                 goto out;
462         }
463
464         __copy_from_user(&kset, set, sizeof(set));
465         if (error)
466                 goto out;
467
468         if (info && clear_user(info, sizeof(*info))) {
469                 error = -EFAULT;
470                 goto out;
471         }
472
473         if (tp) {
474                 if (!access_ok(VERIFY_READ, tp, sizeof(*tp)))
475                         return -EFAULT;
476                 if (!tp->tv_sec && !tp->tv_nsec) {
477                         error = -EINVAL;
478                         goto out;
479                 }
480                 expire = timespec_to_jiffies(tp) + (tp->tv_sec||tp->tv_nsec);
481         }
482
483         while(1) {
484                 long tmp = 0;
485
486                 expire = schedule_timeout_interruptible(expire);
487
488                 for (i=0; i<=4; i++)
489                         tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
490
491                 if (tmp)
492                         break;
493                 if (!expire) {
494                         timeo = 1;
495                         break;
496                 }
497                 if (signal_pending(current))
498                         return -EINTR;
499         }
500         if (timeo)
501                 return -EAGAIN;
502
503         for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
504                 if (sigismember (&kset, sig))
505                         continue;
506                 if (sigismember (&current->pending.signal, sig)) {
507                         /* XXX need more than this... */
508                         if (info)
509                                 info->sig = sig;
510                         error = 0;
511                         goto out;
512                 }
513         }
514
515         /* Should not get here, but do something sane if we do. */
516         error = -EINTR;
517
518 out:
519         return error;
520 }
521
522 /* This is here because of irix5_siginfo definition. */
523 #define IRIX_P_PID    0
524 #define IRIX_P_PGID   2
525 #define IRIX_P_ALL    7
526
527 extern int getrusage(struct task_struct *, int, struct rusage __user *);
528
529 #define W_EXITED     1
530 #define W_TRAPPED    2
531 #define W_STOPPED    4
532 #define W_CONT       8
533 #define W_NOHANG    64
534
535 #define W_MASK      (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
536
537 asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
538                             int options, struct rusage *ru)
539 {
540         int flag, retval;
541         DECLARE_WAITQUEUE(wait, current);
542         struct task_struct *tsk;
543         struct task_struct *p;
544         struct list_head *_p;
545
546         if (!info) {
547                 retval = -EINVAL;
548                 goto out;
549         }
550         if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) {
551                 retval = -EFAULT;
552                 goto out;
553         }
554         if (ru) {
555                 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru))) {
556                         retval = -EFAULT;
557                         goto out;
558                 }
559         }
560         if (options & ~(W_MASK)) {
561                 retval = -EINVAL;
562                 goto out;
563         }
564         if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
565                 retval = -EINVAL;
566                 goto out;
567         }
568         add_wait_queue(&current->signal->wait_chldexit, &wait);
569 repeat:
570         flag = 0;
571         current->state = TASK_INTERRUPTIBLE;
572         read_lock(&tasklist_lock);
573         tsk = current;
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)
577                         continue;
578                 if ((type == IRIX_P_PGID) && process_group(p) != pid)
579                         continue;
580                 if ((p->exit_signal != SIGCHLD))
581                         continue;
582                 flag = 1;
583                 switch (p->state) {
584                 case TASK_STOPPED:
585                         if (!p->exit_code)
586                                 continue;
587                         if (!(options & (W_TRAPPED|W_STOPPED)) &&
588                             !(p->ptrace & PT_PTRACED))
589                                 continue;
590                         read_unlock(&tasklist_lock);
591
592                         /* move to end of parent's list to avoid starvation */
593                         write_lock_irq(&tasklist_lock);
594                         remove_parent(p);
595                         add_parent(p, p->parent);
596                         write_unlock_irq(&tasklist_lock);
597                         retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
598                         if (!retval && ru) {
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);
606                         }
607                         if (!retval) {
608                                 p->exit_code = 0;
609                         }
610                         goto end_waitsys;
611
612                 case EXIT_ZOMBIE:
613                         current->signal->cutime += p->utime + p->signal->cutime;
614                         current->signal->cstime += p->stime + p->signal->cstime;
615                         if (ru != NULL)
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);
622                         __put_user(p->utime,
623                                    &info->stuff.procinfo.procdata.child.utime);
624                         __put_user(p->stime,
625                                    &info->stuff.procinfo.procdata.child.stime);
626                         retval = 0;
627                         if (p->real_parent != p->parent) {
628                                 write_lock_irq(&tasklist_lock);
629                                 remove_parent(p);
630                                 p->parent = p->real_parent;
631                                 add_parent(p, p->parent);
632                                 do_notify_parent(p, SIGCHLD);
633                                 write_unlock_irq(&tasklist_lock);
634                         } else
635                                 release_task(p);
636                         goto end_waitsys;
637                 default:
638                         continue;
639                 }
640                 tsk = next_thread(tsk);
641         }
642         read_unlock(&tasklist_lock);
643         if (flag) {
644                 retval = 0;
645                 if (options & W_NOHANG)
646                         goto end_waitsys;
647                 retval = -ERESTARTSYS;
648                 if (signal_pending(current))
649                         goto end_waitsys;
650                 current->state = TASK_INTERRUPTIBLE;
651                 schedule();
652                 goto repeat;
653         }
654         retval = -ECHILD;
655 end_waitsys:
656         current->state = TASK_RUNNING;
657         remove_wait_queue(&current->signal->wait_chldexit, &wait);
658
659 out:
660         return retval;
661 }
662
663 struct irix5_context {
664         u32 flags;
665         u32 link;
666         u32 sigmask[4];
667         struct { u32 sp, size, flags; } stack;
668         int regs[36];
669         u32 fpregs[32];
670         u32 fpcsr;
671         u32 _unused0;
672         u32 _unused1[47];
673         u32 weird_graphics_thing;
674 };
675
676 asmlinkage int irix_getcontext(struct pt_regs *regs)
677 {
678         int i, base = 0;
679         struct irix5_context *ctx;
680         unsigned long flags;
681
682         if (regs->regs[2] == 1000)
683                 base = 1;
684         ctx = (struct irix5_context *) regs->regs[base + 4];
685
686 #ifdef DEBUG_SIG
687         printk("[%s:%d] irix_getcontext(%p)\n",
688                current->comm, current->pid, ctx);
689 #endif
690
691         if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
692                 return -EFAULT;
693
694         __put_user(current->thread.irix_oldctx, &ctx->link);
695
696         __copy_to_user(&ctx->sigmask, &current->blocked, sizeof(irix_sigset_t));
697
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);
702
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]);
711
712         flags = 0x0f;
713         if (!used_math()) {
714                 flags &= ~(0x08);
715         } else {
716                 /* XXX wheee... */
717                 printk("Wheee, no code for saving IRIX FPU context yet.\n");
718         }
719         __put_user(flags, &ctx->flags);
720
721         return 0;
722 }
723
724 asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
725 {
726         int error, base = 0;
727         struct irix5_context *ctx;
728
729         if(regs->regs[2] == 1000)
730                 base = 1;
731         ctx = (struct irix5_context *) regs->regs[base + 4];
732
733 #ifdef DEBUG_SIG
734         printk("[%s:%d] irix_setcontext(%p)\n",
735                current->comm, current->pid, ctx);
736 #endif
737
738         if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))) {
739                 error = -EFAULT;
740                 goto out;
741         }
742
743         if (ctx->flags & 0x02) {
744                 /* XXX sigstack garbage, todo... */
745                 printk("Wheee, cannot do sigstack stuff in setcontext\n");
746         }
747
748         if (ctx->flags & 0x04) {
749                 int i;
750
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];
757         }
758
759         if (ctx->flags & 0x08) {
760                 /* XXX fpu context, blah... */
761                 printk("Wheee, cannot restore FPU context yet...\n");
762         }
763         current->thread.irix_oldctx = ctx->link;
764         error = regs->regs[2];
765
766 out:
767         return error;
768 }
769
770 struct irix_sigstack { unsigned long sp; int status; };
771
772 asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
773 {
774         int error = -EFAULT;
775
776 #ifdef DEBUG_SIG
777         printk("[%s:%d] irix_sigstack(%p,%p)\n",
778                current->comm, current->pid, new, old);
779 #endif
780         if(new) {
781                 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
782                         goto out;
783         }
784
785         if(old) {
786                 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
787                         goto out;
788         }
789         error = 0;
790
791 out:
792         return error;
793 }
794
795 struct irix_sigaltstack { unsigned long sp; int size; int status; };
796
797 asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
798                                 struct irix_sigaltstack *old)
799 {
800         int error = -EFAULT;
801
802 #ifdef DEBUG_SIG
803         printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
804                current->comm, current->pid, new, old);
805 #endif
806         if (new) {
807                 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
808                         goto out;
809         }
810
811         if (old) {
812                 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
813                         goto out;
814         }
815         error = 0;
816
817 out:
818         error = 0;
819
820         return error;
821 }
822
823 struct irix_procset {
824         int cmd, ltype, lid, rtype, rid;
825 };
826
827 asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
828 {
829         if (!access_ok(VERIFY_READ, pset, sizeof(*pset)))
830                 return -EFAULT;
831
832 #ifdef DEBUG_SIG
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,
836                sig);
837 #endif
838         return -EINVAL;
839 }