]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/mips/kernel/irixsig.c
2 * irixsig.c: WHEEE, IRIX signals! YOW, am I compatible or what?!?!
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 * Copyright (C) 1997 - 2000 Ralf Baechle (ralf@gnu.org)
6 * Copyright (C) 2000 Silicon Graphics, Inc.
8 #include <linux/kernel.h>
9 #include <linux/sched.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>
17 #include <asm/ptrace.h>
18 #include <asm/uaccess.h>
22 #define _S(nr) (1<<((nr)-1))
24 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
31 u32 rmask
, cp0_status
;
35 u32 usedfp
, fpcsr
, fpeir
, sstk_flags
;
37 u64 cp0_cause
, cp0_badvaddr
, _unused0
;
45 static inline void dump_irix5_sigctx(struct sigctx_irix5
*c
)
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
);
54 for(i
= 0; i
< 16; i
++)
55 printk("[%d]<%08lx> ", i
, (unsigned long) c
->regs
[i
]);
57 for(i
= 16; i
< 32; i
++)
58 printk("[%d]<%08lx> ", i
, (unsigned long) c
->regs
[i
]);
60 for(i
= 0; i
< 16; i
++)
61 printk("[%d]<%08lx> ", i
, (unsigned long) c
->fpregs
[i
]);
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]);
79 static void setup_irix_frame(struct k_sigaction
*ka
, struct pt_regs
*regs
,
80 int signr
, sigset_t
*oldmask
)
83 struct sigctx_irix5
*ctx
;
87 sp
-= sizeof(struct sigctx_irix5
);
89 ctx
= (struct sigctx_irix5
*) sp
;
90 if (!access_ok(VERIFY_WRITE
, ctx
, sizeof(*ctx
)))
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
]);
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
);
106 __put_user(0, &ctx
->sstk_flags
); /* XXX sigstack unimp... todo... */
108 __copy_to_user(&ctx
->sigset
, oldmask
, sizeof(irix_sigset_t
));
111 dump_irix5_sigctx(ctx
);
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
;
123 force_sigsegv(signr
, current
);
127 setup_irix_rt_frame(struct k_sigaction
* ka
, struct pt_regs
*regs
,
128 int signr
, sigset_t
*oldmask
, siginfo_t
*info
)
130 printk("Aiee: setup_tr_frame wants to be written");
134 static inline void handle_signal(unsigned long sig
, siginfo_t
*info
,
135 struct k_sigaction
*ka
, sigset_t
*oldset
, struct pt_regs
* regs
)
137 switch(regs
->regs
[0]) {
139 regs
->regs
[2] = EINTR
;
142 if(!(ka
->sa
.sa_flags
& SA_RESTART
)) {
143 regs
->regs
[2] = EINTR
;
147 case ERESTARTNOINTR
: /* Userland will reload $v0. */
151 regs
->regs
[0] = 0; /* Don't deal with this again. */
153 if (ka
->sa
.sa_flags
& SA_SIGINFO
)
154 setup_irix_rt_frame(ka
, regs
, sig
, oldset
, info
);
156 setup_irix_frame(ka
, regs
, sig
, oldset
);
158 spin_lock_irq(¤t
->sighand
->siglock
);
159 sigorsets(¤t
->blocked
,¤t
->blocked
,&ka
->sa
.sa_mask
);
160 if (!(ka
->sa
.sa_flags
& SA_NODEFER
))
161 sigaddset(¤t
->blocked
,sig
);
163 spin_unlock_irq(¤t
->sighand
->siglock
);
166 asmlinkage
int do_irix_signal(sigset_t
*oldset
, struct pt_regs
*regs
)
168 struct k_sigaction ka
;
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
177 if (!user_mode(regs
))
184 oldset
= ¤t
->blocked
;
186 signr
= get_signal_to_deliver(&info
, &ka
, regs
, NULL
);
188 handle_signal(signr
, &info
, &ka
, oldset
, regs
);
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.
199 if (regs
->regs
[2] == ERESTARTNOHAND
||
200 regs
->regs
[2] == ERESTARTSYS
||
201 regs
->regs
[2] == ERESTARTNOINTR
) {
209 irix_sigreturn(struct pt_regs
*regs
)
211 struct sigctx_irix5
*context
, *magic
;
212 unsigned long umask
, mask
;
214 int sig
, i
, base
= 0;
217 /* Always make any pending restarted system calls return -EINTR */
218 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
220 if (regs
->regs
[2] == 1000)
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];
227 printk("[%s:%d] IRIX sigreturn(scp[%p],ucp[%p],sig[%d])\n",
228 current
->comm
, current
->pid
, context
, magic
, sig
);
232 if (!access_ok(VERIFY_READ
, context
, sizeof(struct sigctx_irix5
)))
236 dump_irix5_sigctx(context
);
239 __get_user(regs
->cp0_epc
, &context
->pc
);
240 umask
= context
->rmask
; mask
= 2;
241 for (i
= 1; i
< 32; i
++, mask
<<= 1) {
243 __get_user(regs
->regs
[i
], &context
->regs
[i
]);
245 __get_user(regs
->hi
, &context
->hi
);
246 __get_user(regs
->lo
, &context
->lo
);
248 if ((umask
& 1) && context
->usedfp
) {
249 fregs
= (u64
*) ¤t
->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
);
255 /* XXX do sigstack crapola here... XXX */
257 if (__copy_from_user(&blocked
, &context
->sigset
, sizeof(blocked
)))
260 sigdelsetmask(&blocked
, ~_BLOCKABLE
);
261 spin_lock_irq(¤t
->sighand
->siglock
);
262 current
->blocked
= blocked
;
264 spin_unlock_irq(¤t
->sighand
->siglock
);
267 * Don't let your children do this ...
269 if (current_thread_info()->flags
& TIF_SYSCALL_TRACE
)
270 do_syscall_trace(regs
, 1);
271 __asm__
__volatile__(
279 force_sig(SIGSEGV
, current
);
282 struct sigact_irix5
{
284 void (*handler
)(int);
290 static inline void dump_sigact_irix5(struct sigact_irix5
*p
)
292 printk("<f[%d] hndlr[%08lx] msk[%08lx]>", p
->flags
,
293 (unsigned long) p
->handler
,
294 (unsigned long) p
->sigset
[0]);
299 irix_sigaction(int sig
, const struct sigaction
*act
,
300 struct sigaction
*oact
, void *trampoline
)
302 struct k_sigaction new_ka
, old_ka
;
306 printk(" (%d,%s,%s,%08lx) ", sig
, (!new ? "0" : "NEW"),
307 (!old
? "0" : "OLD"), trampoline
);
309 dump_sigact_irix5(new); printk(" ");
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
))
319 __copy_from_user(&mask
, &act
->sa_mask
, sizeof(sigset_t
));
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...
326 new_ka
.sa_restorer
= trampoline
;
329 /* XXX Implement SIG_SETMASK32 for IRIX compatibility */
330 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
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
))
337 __copy_to_user(&old_ka
.sa
.sa_mask
, &oact
->sa_mask
,
344 asmlinkage
int irix_sigpending(irix_sigset_t
*set
)
346 return do_sigpending(set
, sizeof(*set
));
349 asmlinkage
int irix_sigprocmask(int how
, irix_sigset_t
*new, irix_sigset_t
*old
)
351 sigset_t oldbits
, newbits
;
354 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
356 __copy_from_user(&newbits
, new, sizeof(unsigned long)*4);
357 sigdelsetmask(&newbits
, ~_BLOCKABLE
);
359 spin_lock_irq(¤t
->sighand
->siglock
);
360 oldbits
= current
->blocked
;
364 sigorsets(&newbits
, &oldbits
, &newbits
);
368 sigandsets(&newbits
, &oldbits
, &newbits
);
375 siginitset(&newbits
, newbits
.sig
[0]);
382 spin_unlock_irq(¤t
->sighand
->siglock
);
385 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
387 __copy_to_user(old
, ¤t
->blocked
, sizeof(unsigned long)*4);
393 asmlinkage
int irix_sigsuspend(struct pt_regs
*regs
)
395 sigset_t
*uset
, saveset
, newset
;
397 uset
= (sigset_t
*) regs
->regs
[4];
398 if (copy_from_user(&newset
, uset
, sizeof(sigset_t
)))
400 sigdelsetmask(&newset
, ~_BLOCKABLE
);
402 spin_lock_irq(¤t
->sighand
->siglock
);
403 saveset
= current
->blocked
;
404 current
->blocked
= newset
;
406 spin_unlock_irq(¤t
->sighand
->siglock
);
408 regs
->regs
[2] = -EINTR
;
410 current
->state
= TASK_INTERRUPTIBLE
;
412 if (do_irix_signal(&saveset
, regs
))
417 /* hate hate hate... */
418 struct irix5_siginfo
{
419 int sig
, code
, error
;
421 char unused
[128 - (3 * 4)]; /* Safety net. */
427 int utime
, status
, stime
;
432 unsigned long fault_addr
;
439 unsigned long sigval
;
443 static inline unsigned long timespectojiffies(struct timespec
*value
)
445 unsigned long sec
= (unsigned) value
->tv_sec
;
446 long nsec
= value
->tv_nsec
;
448 if (sec
> (LONG_MAX
/ HZ
))
450 nsec
+= 1000000000L / HZ
- 1;
451 nsec
/= 1000000000L / HZ
;
452 return HZ
* sec
+ nsec
;
455 asmlinkage
int irix_sigpoll_sys(unsigned long *set
, struct irix5_siginfo
*info
,
458 long expire
= MAX_SCHEDULE_TIMEOUT
;
460 int i
, sig
, error
, timeo
= 0;
463 printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
464 current
->comm
, current
->pid
, set
, info
, tp
);
467 /* Must always specify the signal set. */
471 if (!access_ok(VERIFY_READ
, set
, sizeof(kset
))) {
476 __copy_from_user(&kset
, set
, sizeof(set
));
480 if (info
&& clear_user(info
, sizeof(*info
))) {
486 if (!access_ok(VERIFY_READ
, tp
, sizeof(*tp
)))
488 if (!tp
->tv_sec
&& !tp
->tv_nsec
) {
492 expire
= timespectojiffies(tp
)+(tp
->tv_sec
||tp
->tv_nsec
);
498 current
->state
= TASK_INTERRUPTIBLE
;
499 expire
= schedule_timeout(expire
);
502 tmp
|= (current
->pending
.signal
.sig
[i
] & kset
.sig
[i
]);
510 if (signal_pending(current
))
516 for(sig
= 1; i
<= 65 /* IRIX_NSIG */; sig
++) {
517 if (sigismember (&kset
, sig
))
519 if (sigismember (¤t
->pending
.signal
, sig
)) {
520 /* XXX need more than this... */
528 /* Should not get here, but do something sane if we do. */
535 /* This is here because of irix5_siginfo definition. */
537 #define IRIX_P_PGID 2
540 extern int getrusage(struct task_struct
*, int, struct rusage __user
*);
548 #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
550 asmlinkage
int irix_waitsys(int type
, int pid
, struct irix5_siginfo
*info
,
551 int options
, struct rusage
*ru
)
554 DECLARE_WAITQUEUE(wait
, current
);
555 struct task_struct
*tsk
;
556 struct task_struct
*p
;
557 struct list_head
*_p
;
563 if (!access_ok(VERIFY_WRITE
, info
, sizeof(*info
))) {
568 if (!access_ok(VERIFY_WRITE
, ru
, sizeof(*ru
))) {
573 if (options
& ~(W_MASK
)) {
577 if (type
!= IRIX_P_PID
&& type
!= IRIX_P_PGID
&& type
!= IRIX_P_ALL
) {
581 add_wait_queue(¤t
->signal
->wait_chldexit
, &wait
);
584 current
->state
= TASK_INTERRUPTIBLE
;
585 read_lock(&tasklist_lock
);
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
)
591 if ((type
== IRIX_P_PGID
) && process_group(p
) != pid
)
593 if ((p
->exit_signal
!= SIGCHLD
))
600 if (!(options
& (W_TRAPPED
|W_STOPPED
)) &&
601 !(p
->ptrace
& PT_PTRACED
))
603 read_unlock(&tasklist_lock
);
605 /* move to end of parent's list to avoid starvation */
606 write_lock_irq(&tasklist_lock
);
608 add_parent(p
, p
->parent
);
609 write_unlock_irq(&tasklist_lock
);
610 retval
= ru
? getrusage(p
, RUSAGE_BOTH
, ru
) : 0;
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
);
626 current
->signal
->cutime
+= p
->utime
+ p
->signal
->cutime
;
627 current
->signal
->cstime
+= p
->stime
+ p
->signal
->cstime
;
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
);
636 &info
->stuff
.procinfo
.procdata
.child
.utime
);
638 &info
->stuff
.procinfo
.procdata
.child
.stime
);
640 if (p
->real_parent
!= p
->parent
) {
641 write_lock_irq(&tasklist_lock
);
643 p
->parent
= p
->real_parent
;
644 add_parent(p
, p
->parent
);
645 do_notify_parent(p
, SIGCHLD
);
646 write_unlock_irq(&tasklist_lock
);
653 tsk
= next_thread(tsk
);
655 read_unlock(&tasklist_lock
);
658 if (options
& W_NOHANG
)
660 retval
= -ERESTARTSYS
;
661 if (signal_pending(current
))
663 current
->state
= TASK_INTERRUPTIBLE
;
669 current
->state
= TASK_RUNNING
;
670 remove_wait_queue(¤t
->signal
->wait_chldexit
, &wait
);
676 struct irix5_context
{
680 struct { u32 sp
, size
, flags
; } stack
;
686 u32 weird_graphics_thing
;
689 asmlinkage
int irix_getcontext(struct pt_regs
*regs
)
692 struct irix5_context
*ctx
;
695 if (regs
->regs
[2] == 1000)
697 ctx
= (struct irix5_context
*) regs
->regs
[base
+ 4];
700 printk("[%s:%d] irix_getcontext(%p)\n",
701 current
->comm
, current
->pid
, ctx
);
704 if (!access_ok(VERIFY_WRITE
, ctx
, sizeof(*ctx
)))
707 __put_user(current
->thread
.irix_oldctx
, &ctx
->link
);
709 __copy_to_user(&ctx
->sigmask
, ¤t
->blocked
, sizeof(irix_sigset_t
));
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
);
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]);
730 printk("Wheee, no code for saving IRIX FPU context yet.\n");
732 __put_user(flags
, &ctx
->flags
);
737 asmlinkage
unsigned long irix_setcontext(struct pt_regs
*regs
)
740 struct irix5_context
*ctx
;
742 if(regs
->regs
[2] == 1000)
744 ctx
= (struct irix5_context
*) regs
->regs
[base
+ 4];
747 printk("[%s:%d] irix_setcontext(%p)\n",
748 current
->comm
, current
->pid
, ctx
);
751 if (!access_ok(VERIFY_READ
, ctx
, sizeof(*ctx
))) {
756 if (ctx
->flags
& 0x02) {
757 /* XXX sigstack garbage, todo... */
758 printk("Wheee, cannot do sigstack stuff in setcontext\n");
761 if (ctx
->flags
& 0x04) {
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];
772 if (ctx
->flags
& 0x08) {
773 /* XXX fpu context, blah... */
774 printk("Wheee, cannot restore FPU context yet...\n");
776 current
->thread
.irix_oldctx
= ctx
->link
;
777 error
= regs
->regs
[2];
783 struct irix_sigstack
{ unsigned long sp
; int status
; };
785 asmlinkage
int irix_sigstack(struct irix_sigstack
*new, struct irix_sigstack
*old
)
790 printk("[%s:%d] irix_sigstack(%p,%p)\n",
791 current
->comm
, current
->pid
, new, old
);
794 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
799 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
808 struct irix_sigaltstack
{ unsigned long sp
; int size
; int status
; };
810 asmlinkage
int irix_sigaltstack(struct irix_sigaltstack
*new,
811 struct irix_sigaltstack
*old
)
816 printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
817 current
->comm
, current
->pid
, new, old
);
820 if (!access_ok(VERIFY_READ
, new, sizeof(*new)))
825 if (!access_ok(VERIFY_WRITE
, old
, sizeof(*old
)))
836 struct irix_procset
{
837 int cmd
, ltype
, lid
, rtype
, rid
;
840 asmlinkage
int irix_sigsendset(struct irix_procset
*pset
, int sig
)
842 if (!access_ok(VERIFY_READ
, pset
, sizeof(*pset
)))
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
,