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