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