irixsig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. static inline unsigned long timespectojiffies(struct timespec *value)
  375. {
  376. unsigned long sec = (unsigned) value->tv_sec;
  377. long nsec = value->tv_nsec;
  378. if (sec > (LONG_MAX / HZ))
  379. return LONG_MAX;
  380. nsec += 1000000000L / HZ - 1;
  381. nsec /= 1000000000L / HZ;
  382. return HZ * sec + nsec;
  383. }
  384. asmlinkage int irix_sigpoll_sys(unsigned long *set, struct irix5_siginfo *info,
  385. struct timespec *tp)
  386. {
  387. long expire = MAX_SCHEDULE_TIMEOUT;
  388. sigset_t kset;
  389. int i, sig, error, timeo = 0;
  390. #ifdef DEBUG_SIG
  391. printk("[%s:%d] irix_sigpoll_sys(%p,%p,%p)\n",
  392. current->comm, current->pid, set, info, tp);
  393. #endif
  394. /* Must always specify the signal set. */
  395. if (!set)
  396. return -EINVAL;
  397. if (!access_ok(VERIFY_READ, set, sizeof(kset))) {
  398. error = -EFAULT;
  399. goto out;
  400. }
  401. __copy_from_user(&kset, set, sizeof(set));
  402. if (error)
  403. goto out;
  404. if (info && clear_user(info, sizeof(*info))) {
  405. error = -EFAULT;
  406. goto out;
  407. }
  408. if (tp) {
  409. if (!access_ok(VERIFY_READ, tp, sizeof(*tp)))
  410. return -EFAULT;
  411. if (!tp->tv_sec && !tp->tv_nsec) {
  412. error = -EINVAL;
  413. goto out;
  414. }
  415. expire = timespectojiffies(tp)+(tp->tv_sec||tp->tv_nsec);
  416. }
  417. while(1) {
  418. long tmp = 0;
  419. current->state = TASK_INTERRUPTIBLE;
  420. expire = schedule_timeout(expire);
  421. for (i=0; i<=4; i++)
  422. tmp |= (current->pending.signal.sig[i] & kset.sig[i]);
  423. if (tmp)
  424. break;
  425. if (!expire) {
  426. timeo = 1;
  427. break;
  428. }
  429. if (signal_pending(current))
  430. return -EINTR;
  431. }
  432. if (timeo)
  433. return -EAGAIN;
  434. for(sig = 1; i <= 65 /* IRIX_NSIG */; sig++) {
  435. if (sigismember (&kset, sig))
  436. continue;
  437. if (sigismember (&current->pending.signal, sig)) {
  438. /* XXX need more than this... */
  439. if (info)
  440. info->sig = sig;
  441. error = 0;
  442. goto out;
  443. }
  444. }
  445. /* Should not get here, but do something sane if we do. */
  446. error = -EINTR;
  447. out:
  448. return error;
  449. }
  450. /* This is here because of irix5_siginfo definition. */
  451. #define IRIX_P_PID 0
  452. #define IRIX_P_PGID 2
  453. #define IRIX_P_ALL 7
  454. extern int getrusage(struct task_struct *, int, struct rusage __user *);
  455. #define W_EXITED 1
  456. #define W_TRAPPED 2
  457. #define W_STOPPED 4
  458. #define W_CONT 8
  459. #define W_NOHANG 64
  460. #define W_MASK (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
  461. asmlinkage int irix_waitsys(int type, int pid, struct irix5_siginfo *info,
  462. int options, struct rusage *ru)
  463. {
  464. int flag, retval;
  465. DECLARE_WAITQUEUE(wait, current);
  466. struct task_struct *tsk;
  467. struct task_struct *p;
  468. struct list_head *_p;
  469. if (!info) {
  470. retval = -EINVAL;
  471. goto out;
  472. }
  473. if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) {
  474. retval = -EFAULT;
  475. goto out;
  476. }
  477. if (ru) {
  478. if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru))) {
  479. retval = -EFAULT;
  480. goto out;
  481. }
  482. }
  483. if (options & ~(W_MASK)) {
  484. retval = -EINVAL;
  485. goto out;
  486. }
  487. if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL) {
  488. retval = -EINVAL;
  489. goto out;
  490. }
  491. add_wait_queue(&current->signal->wait_chldexit, &wait);
  492. repeat:
  493. flag = 0;
  494. current->state = TASK_INTERRUPTIBLE;
  495. read_lock(&tasklist_lock);
  496. tsk = current;
  497. list_for_each(_p,&tsk->children) {
  498. p = list_entry(_p,struct task_struct,sibling);
  499. if ((type == IRIX_P_PID) && p->pid != pid)
  500. continue;
  501. if ((type == IRIX_P_PGID) && process_group(p) != pid)
  502. continue;
  503. if ((p->exit_signal != SIGCHLD))
  504. continue;
  505. flag = 1;
  506. switch (p->state) {
  507. case TASK_STOPPED:
  508. if (!p->exit_code)
  509. continue;
  510. if (!(options & (W_TRAPPED|W_STOPPED)) &&
  511. !(p->ptrace & PT_PTRACED))
  512. continue;
  513. read_unlock(&tasklist_lock);
  514. /* move to end of parent's list to avoid starvation */
  515. write_lock_irq(&tasklist_lock);
  516. remove_parent(p);
  517. add_parent(p, p->parent);
  518. write_unlock_irq(&tasklist_lock);
  519. retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
  520. if (!retval && ru) {
  521. retval |= __put_user(SIGCHLD, &info->sig);
  522. retval |= __put_user(0, &info->code);
  523. retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
  524. retval |= __put_user((p->exit_code >> 8) & 0xff,
  525. &info->stuff.procinfo.procdata.child.status);
  526. retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
  527. retval |= __put_user(p->stime, &info->stuff.procinfo.procdata.child.stime);
  528. }
  529. if (!retval) {
  530. p->exit_code = 0;
  531. }
  532. goto end_waitsys;
  533. case EXIT_ZOMBIE:
  534. current->signal->cutime += p->utime + p->signal->cutime;
  535. current->signal->cstime += p->stime + p->signal->cstime;
  536. if (ru != NULL)
  537. getrusage(p, RUSAGE_BOTH, ru);
  538. __put_user(SIGCHLD, &info->sig);
  539. __put_user(1, &info->code); /* CLD_EXITED */
  540. __put_user(p->pid, &info->stuff.procinfo.pid);
  541. __put_user((p->exit_code >> 8) & 0xff,
  542. &info->stuff.procinfo.procdata.child.status);
  543. __put_user(p->utime,
  544. &info->stuff.procinfo.procdata.child.utime);
  545. __put_user(p->stime,
  546. &info->stuff.procinfo.procdata.child.stime);
  547. retval = 0;
  548. if (p->real_parent != p->parent) {
  549. write_lock_irq(&tasklist_lock);
  550. remove_parent(p);
  551. p->parent = p->real_parent;
  552. add_parent(p, p->parent);
  553. do_notify_parent(p, SIGCHLD);
  554. write_unlock_irq(&tasklist_lock);
  555. } else
  556. release_task(p);
  557. goto end_waitsys;
  558. default:
  559. continue;
  560. }
  561. tsk = next_thread(tsk);
  562. }
  563. read_unlock(&tasklist_lock);
  564. if (flag) {
  565. retval = 0;
  566. if (options & W_NOHANG)
  567. goto end_waitsys;
  568. retval = -ERESTARTSYS;
  569. if (signal_pending(current))
  570. goto end_waitsys;
  571. current->state = TASK_INTERRUPTIBLE;
  572. schedule();
  573. goto repeat;
  574. }
  575. retval = -ECHILD;
  576. end_waitsys:
  577. current->state = TASK_RUNNING;
  578. remove_wait_queue(&current->signal->wait_chldexit, &wait);
  579. out:
  580. return retval;
  581. }
  582. struct irix5_context {
  583. u32 flags;
  584. u32 link;
  585. u32 sigmask[4];
  586. struct { u32 sp, size, flags; } stack;
  587. int regs[36];
  588. u32 fpregs[32];
  589. u32 fpcsr;
  590. u32 _unused0;
  591. u32 _unused1[47];
  592. u32 weird_graphics_thing;
  593. };
  594. asmlinkage int irix_getcontext(struct pt_regs *regs)
  595. {
  596. int i, base = 0;
  597. struct irix5_context *ctx;
  598. unsigned long flags;
  599. if (regs->regs[2] == 1000)
  600. base = 1;
  601. ctx = (struct irix5_context *) regs->regs[base + 4];
  602. #ifdef DEBUG_SIG
  603. printk("[%s:%d] irix_getcontext(%p)\n",
  604. current->comm, current->pid, ctx);
  605. #endif
  606. if (!access_ok(VERIFY_WRITE, ctx, sizeof(*ctx)))
  607. return -EFAULT;
  608. __put_user(current->thread.irix_oldctx, &ctx->link);
  609. __copy_to_user(&ctx->sigmask, &current->blocked, sizeof(irix_sigset_t));
  610. /* XXX Do sigstack stuff someday... */
  611. __put_user(0, &ctx->stack.sp);
  612. __put_user(0, &ctx->stack.size);
  613. __put_user(0, &ctx->stack.flags);
  614. __put_user(0, &ctx->weird_graphics_thing);
  615. __put_user(0, &ctx->regs[0]);
  616. for (i = 1; i < 32; i++)
  617. __put_user(regs->regs[i], &ctx->regs[i]);
  618. __put_user(regs->lo, &ctx->regs[32]);
  619. __put_user(regs->hi, &ctx->regs[33]);
  620. __put_user(regs->cp0_cause, &ctx->regs[34]);
  621. __put_user(regs->cp0_epc, &ctx->regs[35]);
  622. flags = 0x0f;
  623. if (!used_math()) {
  624. flags &= ~(0x08);
  625. } else {
  626. /* XXX wheee... */
  627. printk("Wheee, no code for saving IRIX FPU context yet.\n");
  628. }
  629. __put_user(flags, &ctx->flags);
  630. return 0;
  631. }
  632. asmlinkage unsigned long irix_setcontext(struct pt_regs *regs)
  633. {
  634. int error, base = 0;
  635. struct irix5_context *ctx;
  636. if(regs->regs[2] == 1000)
  637. base = 1;
  638. ctx = (struct irix5_context *) regs->regs[base + 4];
  639. #ifdef DEBUG_SIG
  640. printk("[%s:%d] irix_setcontext(%p)\n",
  641. current->comm, current->pid, ctx);
  642. #endif
  643. if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))) {
  644. error = -EFAULT;
  645. goto out;
  646. }
  647. if (ctx->flags & 0x02) {
  648. /* XXX sigstack garbage, todo... */
  649. printk("Wheee, cannot do sigstack stuff in setcontext\n");
  650. }
  651. if (ctx->flags & 0x04) {
  652. int i;
  653. /* XXX extra control block stuff... todo... */
  654. for(i = 1; i < 32; i++)
  655. regs->regs[i] = ctx->regs[i];
  656. regs->lo = ctx->regs[32];
  657. regs->hi = ctx->regs[33];
  658. regs->cp0_epc = ctx->regs[35];
  659. }
  660. if (ctx->flags & 0x08) {
  661. /* XXX fpu context, blah... */
  662. printk("Wheee, cannot restore FPU context yet...\n");
  663. }
  664. current->thread.irix_oldctx = ctx->link;
  665. error = regs->regs[2];
  666. out:
  667. return error;
  668. }
  669. struct irix_sigstack { unsigned long sp; int status; };
  670. asmlinkage int irix_sigstack(struct irix_sigstack *new, struct irix_sigstack *old)
  671. {
  672. int error = -EFAULT;
  673. #ifdef DEBUG_SIG
  674. printk("[%s:%d] irix_sigstack(%p,%p)\n",
  675. current->comm, current->pid, new, old);
  676. #endif
  677. if(new) {
  678. if (!access_ok(VERIFY_READ, new, sizeof(*new)))
  679. goto out;
  680. }
  681. if(old) {
  682. if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
  683. goto out;
  684. }
  685. error = 0;
  686. out:
  687. return error;
  688. }
  689. struct irix_sigaltstack { unsigned long sp; int size; int status; };
  690. asmlinkage int irix_sigaltstack(struct irix_sigaltstack *new,
  691. struct irix_sigaltstack *old)
  692. {
  693. int error = -EFAULT;
  694. #ifdef DEBUG_SIG
  695. printk("[%s:%d] irix_sigaltstack(%p,%p)\n",
  696. current->comm, current->pid, new, old);
  697. #endif
  698. if (new) {
  699. if (!access_ok(VERIFY_READ, new, sizeof(*new)))
  700. goto out;
  701. }
  702. if (old) {
  703. if (!access_ok(VERIFY_WRITE, old, sizeof(*old)))
  704. goto out;
  705. }
  706. error = 0;
  707. out:
  708. error = 0;
  709. return error;
  710. }
  711. struct irix_procset {
  712. int cmd, ltype, lid, rtype, rid;
  713. };
  714. asmlinkage int irix_sigsendset(struct irix_procset *pset, int sig)
  715. {
  716. if (!access_ok(VERIFY_READ, pset, sizeof(*pset)))
  717. return -EFAULT;
  718. #ifdef DEBUG_SIG
  719. printk("[%s:%d] irix_sigsendset([%d,%d,%d,%d,%d],%d)\n",
  720. current->comm, current->pid,
  721. pset->cmd, pset->ltype, pset->lid, pset->rtype, pset->rid,
  722. sig);
  723. #endif
  724. return -EINVAL;
  725. }