irixsig.c 20 KB

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