Merge master.kernel.org:/home/rmk/linux-2.6-i2c manually
[deliverable/linux.git] / arch / mips / kernel / irixsig.c
CommitLineData
1da177e4
LT
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
26typedef struct {
27 unsigned long sig[4];
28} irix_sigset_t;
29
30struct 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 */
45static 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
79static 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
122segv_and_exit:
123 force_sigsegv(signr, current);
124}
125
126static void inline
127setup_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
134static 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
69be8f18
SR
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))
1da177e4 161 sigaddset(&current->blocked,sig);
69be8f18
SR
162 recalc_sigpending();
163 spin_unlock_irq(&current->sighand->siglock);
1da177e4
LT
164}
165
166asmlinkage 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
0e6c1f5f 180 if (try_to_freeze())
1da177e4
LT
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
192no_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
208asmlinkage void
209irix_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
278badframe:
279 force_sig(SIGSEGV, current);
280}
281
282struct sigact_irix5 {
283 int flags;
284 void (*handler)(int);
285 u32 sigset[4];
286 int _unused0[2];
287};
288
289#ifdef DEBUG_SIG
290static 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
298asmlinkage int
299irix_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
344asmlinkage int irix_sigpending(irix_sigset_t *set)
345{
346 return do_sigpending(set, sizeof(*set));
347}
348
349asmlinkage 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
393asmlinkage 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... */
418struct 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
443static inline unsigned long timespectojiffies(struct timespec *value)
444{
445 unsigned long sec = (unsigned) value->tv_sec;
446 long nsec = value->tv_nsec;
447
448 if (sec > (LONG_MAX / HZ))
449 return LONG_MAX;
450 nsec += 1000000000L / HZ - 1;
451 nsec /= 1000000000L / HZ;
452 return HZ * sec + nsec;
453}
454
455asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
456 struct timespec *tp)
457{
458 long expire = MAX_SCHEDULE_TIMEOUT;
459 sigset_t kset;
460 int i, sig, error, timeo = 0;
461
462#ifdef DEBUG_SIG
463 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
464 current->comm, current->pid, set, info, tp);
465#endif
466
467 /* Must always specify the signal set. */
468 if (!set)
469 return -EINVAL;
470
471 if (!access_ok(VERIFY_READ, set, sizeof(kset))) {
472 error = -EFAULT;
473 goto out;
474 }
475
476 __copy_from_user(&kset, set, sizeof(set));
477 if (error)
478 goto out;
479
480 if (info && clear_user(info, sizeof(*info))) {
481 error = -EFAULT;
482 goto out;
483 }
484
485 if (tp) {
486 if (!access_ok(VERIFY_READ, tp, sizeof(*tp)))
487 return -EFAULT;
488 if (!tp->tv_sec && !tp->tv_nsec) {
489 error = -EINVAL;
490 goto out;
491 }
492 expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
493 }
494
495 while(1) {
496 long tmp = 0;
497
498 current->state = TASK_INTERRUPTIBLE;
499 expire = schedule_timeout(expire);
500
501 for (i=0; i<=4; i++)
502 tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
503
504 if (tmp)
505 break;
506 if (!expire) {
507 timeo = 1;
508 break;
509 }
510 if (signal_pending(current))
511 return -EINTR;
512 }
513 if (timeo)
514 return -EAGAIN;
515
516 for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
517 if (sigismember (&kset, sig))
518 continue;
519 if (sigismember (&current->pending.signal, sig)) {
520 /* XXX need more than this... */
521 if (info)
522 info->sig = sig;
523 error = 0;
524 goto out;
525 }
526 }
527
528 /* Should not get here, but do something sane if we do. */
529 error = -EINTR;
530
531out:
532 return error;
533}
534
535/* This is here because of irix5_siginfo definition. */
536#define IRIX_P_PID 0
537#define IRIX_P_PGID 2
538#define IRIX_P_ALL 7
539
540extern int getrusage(struct task_struct *, int, struct rusage __user *);
541
542#define W_EXITED 1
543#define W_TRAPPED 2
544#define W_STOPPED 4
545#define W_CONT 8
546#define W_NOHANG 64
547
548#define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
549
550asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
551 int options, struct rusage *ru)
552{
553 int flag, retval;
554 DECLARE_WAITQUEUE(wait, current);
555 struct task_struct *tsk;
556 struct task_struct *p;
557 struct list_head *_p;
558
559 if (!info) {
560 retval = -EINVAL;
561 goto out;
562 }
563 if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) {
564 retval = -EFAULT;
565 goto out;
566 }
567 if (ru) {
568 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru))) {
569 retval = -EFAULT;
570 goto out;
571 }
572 }
573 if (options & ~(W_MASK)) {
574 retval = -EINVAL;
575 goto out;
576 }
577 if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
578 retval = -EINVAL;
579 goto out;
580 }
581 add_wait_queue(&current->signal->wait_chldexit, &wait);
582repeat:
583 flag = 0;
584 current->state = TASK_INTERRUPTIBLE;
585 read_lock(&tasklist_lock);
586 tsk = current;
587 list_for_each(_p,&tsk->children) {
588 p = list_entry(_p,struct task_struct,sibling);
589 if ((type == IRIX_P_PID) && p->pid != pid)
590 continue;
591 if ((type == IRIX_P_PGID) && process_group(p) != pid)
592 continue;
593 if ((p->exit_signal != SIGCHLD))
594 continue;
595 flag = 1;
596 switch (p->state) {
597 case TASK_STOPPED:
598 if (!p->exit_code)
599 continue;
600 if (!(options & (W_TRAPPED|W_STOPPED)) &&
601 !(p->ptrace & PT_PTRACED))
602 continue;
603 read_unlock(&tasklist_lock);
604
605 /* move to end of parent's list to avoid starvation */
606 write_lock_irq(&tasklist_lock);
607 remove_parent(p);
608 add_parent(p, p->parent);
609 write_unlock_irq(&tasklist_lock);
610 retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
611 if (!retval && ru) {
612 retval |= __put_user(SIGCHLD, &info->sig);
613 retval |= __put_user(0, &info->code);
614 retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
615 retval |= __put_user((p->exit_code >> 8) & 0xff,
616 &info->stuff.procinfo.procdata.child.status);
617 retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
618 retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
619 }
620 if (!retval) {
621 p->exit_code = 0;
622 }
623 goto end_waitsys;
624
625 case EXIT_ZOMBIE:
626 current->signal->cutime += p->utime + p->signal->cutime;
627 current->signal->cstime += p->stime + p->signal->cstime;
628 if (ru != NULL)
629 getrusage(p, RUSAGE_BOTH, ru);
630 __put_user(SIGCHLD, &info->sig);
631 __put_user(1, &info->code); /* CLD_EXITED */
632 __put_user(p->pid, &info->stuff.procinfo.pid);
633 __put_user((p->exit_code >> 8) & 0xff,
634 &info->stuff.procinfo.procdata.child.status);
635 __put_user(p->utime,
636 &info->stuff.procinfo.procdata.child.utime);
637 __put_user(p->stime,
638 &info->stuff.procinfo.procdata.child.stime);
639 retval = 0;
640 if (p->real_parent != p->parent) {
641 write_lock_irq(&tasklist_lock);
642 remove_parent(p);
643 p->parent = p->real_parent;
644 add_parent(p, p->parent);
645 do_notify_parent(p, SIGCHLD);
646 write_unlock_irq(&tasklist_lock);
647 } else
648 release_task(p);
649 goto end_waitsys;
650 default:
651 continue;
652 }
653 tsk = next_thread(tsk);
654 }
655 read_unlock(&tasklist_lock);
656 if (flag) {
657 retval = 0;
658 if (options & W_NOHANG)
659 goto end_waitsys;
660 retval = -ERESTARTSYS;
661 if (signal_pending(current))
662 goto end_waitsys;
663 current->state = TASK_INTERRUPTIBLE;
664 schedule();
665 goto repeat;
666 }
667 retval = -ECHILD;
668end_waitsys:
669 current->state = TASK_RUNNING;
670 remove_wait_queue(&current->signal->wait_chldexit, &wait);
671
672out:
673 return retval;
674}
675
676struct irix5_context {
677 u32 flags;
678 u32 link;
679 u32 sigmask[4];
680 struct { u32 sp, size, flags; } stack;
681 int regs[36];
682 u32 fpregs[32];
683 u32 fpcsr;
684 u32 _unused0;
685 u32 _unused1[47];
686 u32 weird_graphics_thing;
687};
688
689asmlinkage int irix_getcontext(struct pt_regs *regs)
690{
691 int i, base = 0;
692 struct irix5_context *ctx;
693 unsigned long flags;
694
695 if (regs->regs[2] == 1000)
696 base = 1;
697 ctx = (struct irix5_context *) regs->regs[base + 4];
698
699#ifdef DEBUG_SIG
700 printk("[%s:%d] irix_getcontext(%p)\n",
701 current->comm, current->pid, ctx);
702#endif
703
704 if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
705 return -EFAULT;
706
707 __put_user(current->thread.irix_oldctx, &ctx->link);
708
709 __copy_to_user(&ctx->sigmask, &current->blocked, sizeof(irix_sigset_t));
710
711 /* XXX Do sigstack stuff someday... */
712 __put_user(0, &ctx->stack.sp);
713 __put_user(0, &ctx->stack.size);
714 __put_user(0, &ctx->stack.flags);
715
716 __put_user(0, &ctx->weird_graphics_thing);
717 __put_user(0, &ctx->regs[0]);
718 for (i = 1; i < 32; i++)
719 __put_user(regs->regs[i], &ctx->regs[i]);
720 __put_user(regs->lo, &ctx->regs[32]);
721 __put_user(regs->hi, &ctx->regs[33]);
722 __put_user(regs->cp0_cause, &ctx->regs[34]);
723 __put_user(regs->cp0_epc, &ctx->regs[35]);
724
725 flags = 0x0f;
726 if (!used_math()) {
727 flags &= ~(0x08);
728 } else {
729 /* XXX wheee... */
730 printk("Wheee, no code for saving IRIX FPU context yet.\n");
731 }
732 __put_user(flags, &ctx->flags);
733
734 return 0;
735}
736
737asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
738{
739 int error, base = 0;
740 struct irix5_context *ctx;
741
742 if(regs->regs[2] == 1000)
743 base = 1;
744 ctx = (struct irix5_context *) regs->regs[base + 4];
745
746#ifdef DEBUG_SIG
747 printk("[%s:%d] irix_setcontext(%p)\n",
748 current->comm, current->pid, ctx);
749#endif
750
751 if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))) {
752 error = -EFAULT;
753 goto out;
754 }
755
756 if (ctx->flags & 0x02) {
757 /* XXX sigstack garbage, todo... */
758 printk("Wheee, cannot do sigstack stuff in setcontext\n");
759 }
760
761 if (ctx->flags & 0x04) {
762 int i;
763
764 /* XXX extra control block stuff... todo... */
765 for(i = 1; i < 32; i++)
766 regs->regs[i] = ctx->regs[i];
767 regs->lo = ctx->regs[32];
768 regs->hi = ctx->regs[33];
769 regs->cp0_epc = ctx->regs[35];
770 }
771
772 if (ctx->flags & 0x08) {
773 /* XXX fpu context, blah... */
774 printk("Wheee, cannot restore FPU context yet...\n");
775 }
776 current->thread.irix_oldctx = ctx->link;
777 error = regs->regs[2];
778
779out:
780 return error;
781}
782
783struct irix_sigstack { unsigned long sp; int status; };
784
785asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
786{
787 int error = -EFAULT;
788
789#ifdef DEBUG_SIG
790 printk("[%s:%d] irix_sigstack(%p,%p)\n",
791 current->comm, current->pid, new, old);
792#endif
793 if(new) {
794 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
795 goto out;
796 }
797
798 if(old) {
799 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
800 goto out;
801 }
802 error = 0;
803
804out:
805 return error;
806}
807
808struct irix_sigaltstack { unsigned long sp; int size; int status; };
809
810asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
811 struct irix_sigaltstack *old)
812{
813 int error = -EFAULT;
814
815#ifdef DEBUG_SIG
816 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
817 current->comm, current->pid, new, old);
818#endif
819 if (new) {
820 if (!access_ok(VERIFY_READ, new, sizeof(*new)))
821 goto out;
822 }
823
824 if (old) {
825 if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
826 goto out;
827 }
828 error = 0;
829
830out:
831 error = 0;
832
833 return error;
834}
835
836struct irix_procset {
837 int cmd, ltype, lid, rtype, rid;
838};
839
840asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
841{
842 if (!access_ok(VERIFY_READ, pset, sizeof(*pset)))
843 return -EFAULT;
844
845#ifdef DEBUG_SIG
846 printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
847 current->comm, current->pid,
848 pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,
849 sig);
850#endif
851 return -EINVAL;
852}
This page took 0.092355 seconds and 5 git commands to generate.