irixsig.c 20 KB

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