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