signal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. // TODO coprocessor stuff
  2. /*
  3. * linux/arch/xtensa/kernel/signal.c
  4. *
  5. * Copyright (C) 1991, 1992 Linus Torvalds
  6. * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
  7. *
  8. * Joe Taylor <joe@tensilica.com>
  9. * Chris Zankel <chris@zankel.net>
  10. *
  11. *
  12. *
  13. */
  14. #include <asm/variant/core.h>
  15. #include <asm/coprocessor.h>
  16. #include <linux/sched.h>
  17. #include <linux/mm.h>
  18. #include <linux/smp.h>
  19. #include <linux/kernel.h>
  20. #include <linux/signal.h>
  21. #include <linux/errno.h>
  22. #include <linux/wait.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/unistd.h>
  25. #include <linux/stddef.h>
  26. #include <linux/personality.h>
  27. #include <asm/ucontext.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/cacheflush.h>
  31. #define DEBUG_SIG 0
  32. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  33. asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options,
  34. struct rusage * ru);
  35. asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
  36. extern struct task_struct *coproc_owners[];
  37. /*
  38. * Atomically swap in the new signal mask, and wait for a signal.
  39. */
  40. int xtensa_sigsuspend(struct pt_regs *regs)
  41. {
  42. old_sigset_t mask = (old_sigset_t) regs->areg[3];
  43. sigset_t saveset;
  44. mask &= _BLOCKABLE;
  45. spin_lock_irq(&current->sighand->siglock);
  46. saveset = current->blocked;
  47. siginitset(&current->blocked, mask);
  48. recalc_sigpending();
  49. spin_unlock_irq(&current->sighand->siglock);
  50. regs->areg[2] = -EINTR;
  51. while (1) {
  52. current->state = TASK_INTERRUPTIBLE;
  53. schedule();
  54. if (do_signal(regs, &saveset))
  55. return -EINTR;
  56. }
  57. }
  58. asmlinkage int
  59. xtensa_rt_sigsuspend(struct pt_regs *regs)
  60. {
  61. sigset_t *unewset = (sigset_t *) regs->areg[4];
  62. size_t sigsetsize = (size_t) regs->areg[3];
  63. sigset_t saveset, newset;
  64. /* XXX: Don't preclude handling different sized sigset_t's. */
  65. if (sigsetsize != sizeof(sigset_t))
  66. return -EINVAL;
  67. if (copy_from_user(&newset, unewset, sizeof(newset)))
  68. return -EFAULT;
  69. sigdelsetmask(&newset, ~_BLOCKABLE);
  70. spin_lock_irq(&current->sighand->siglock);
  71. saveset = current->blocked;
  72. current->blocked = newset;
  73. recalc_sigpending();
  74. spin_unlock_irq(&current->sighand->siglock);
  75. regs->areg[2] = -EINTR;
  76. while (1) {
  77. current->state = TASK_INTERRUPTIBLE;
  78. schedule();
  79. if (do_signal(regs, &saveset))
  80. return -EINTR;
  81. }
  82. }
  83. asmlinkage int
  84. xtensa_sigaction(int sig, const struct old_sigaction *act,
  85. struct old_sigaction *oact)
  86. {
  87. struct k_sigaction new_ka, old_ka;
  88. int ret;
  89. if (act) {
  90. old_sigset_t mask;
  91. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  92. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  93. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  94. return -EFAULT;
  95. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  96. __get_user(mask, &act->sa_mask);
  97. siginitset(&new_ka.sa.sa_mask, mask);
  98. }
  99. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  100. if (!ret && oact) {
  101. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  102. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  103. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  104. return -EFAULT;
  105. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  106. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  107. }
  108. return ret;
  109. }
  110. asmlinkage int
  111. xtensa_sigaltstack(struct pt_regs *regs)
  112. {
  113. const stack_t *uss = (stack_t *) regs->areg[4];
  114. stack_t *uoss = (stack_t *) regs->areg[3];
  115. if (regs->depc > 64)
  116. panic ("Double exception sys_sigreturn\n");
  117. return do_sigaltstack(uss, uoss, regs->areg[1]);
  118. }
  119. /*
  120. * Do a signal return; undo the signal stack.
  121. */
  122. struct sigframe
  123. {
  124. struct sigcontext sc;
  125. struct _cpstate cpstate;
  126. unsigned long extramask[_NSIG_WORDS-1];
  127. unsigned char retcode[6];
  128. unsigned int reserved[4]; /* Reserved area for chaining */
  129. unsigned int window[4]; /* Window of 4 registers for initial context */
  130. };
  131. struct rt_sigframe
  132. {
  133. struct siginfo info;
  134. struct ucontext uc;
  135. struct _cpstate cpstate;
  136. unsigned char retcode[6];
  137. unsigned int reserved[4]; /* Reserved area for chaining */
  138. unsigned int window[4]; /* Window of 4 registers for initial context */
  139. };
  140. extern void release_all_cp (struct task_struct *);
  141. // FIXME restore_cpextra
  142. static inline int
  143. restore_cpextra (struct _cpstate *buf)
  144. {
  145. #if 0
  146. /* The signal handler may have used coprocessors in which
  147. * case they are still enabled. We disable them to force a
  148. * reloading of the original task's CP state by the lazy
  149. * context-switching mechanisms of CP exception handling.
  150. * Also, we essentially discard any coprocessor state that the
  151. * signal handler created. */
  152. struct task_struct *tsk = current;
  153. release_all_cp(tsk);
  154. return __copy_from_user(tsk->thread.cpextra, buf, XTENSA_CP_EXTRA_SIZE);
  155. #endif
  156. return 0;
  157. }
  158. /* Note: We don't copy double exception 'tregs', we have to finish double exc. first before we return to signal handler! This dbl.exc.handler might cause another double exception, but I think we are fine as the situation is the same as if we had returned to the signal handerl and got an interrupt immediately...
  159. */
  160. static int
  161. restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
  162. {
  163. struct thread_struct *thread;
  164. unsigned int err = 0;
  165. unsigned long ps;
  166. struct _cpstate *buf;
  167. #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
  168. COPY(pc);
  169. COPY(depc);
  170. COPY(wmask);
  171. COPY(lbeg);
  172. COPY(lend);
  173. COPY(lcount);
  174. COPY(sar);
  175. COPY(windowbase);
  176. COPY(windowstart);
  177. #undef COPY
  178. /* For PS, restore only PS.CALLINC.
  179. * Assume that all other bits are either the same as for the signal
  180. * handler, or the user mode value doesn't matter (e.g. PS.OWB).
  181. */
  182. err |= __get_user(ps, &sc->sc_ps);
  183. regs->ps = (regs->ps & ~PS_CALLINC_MASK)
  184. | (ps & PS_CALLINC_MASK);
  185. /* Additional corruption checks */
  186. if ((regs->windowbase >= (XCHAL_NUM_AREGS/4))
  187. || ((regs->windowstart & ~((1<<(XCHAL_NUM_AREGS/4)) - 1)) != 0) )
  188. err = 1;
  189. if ((regs->lcount > 0)
  190. && ((regs->lbeg > TASK_SIZE) || (regs->lend > TASK_SIZE)) )
  191. err = 1;
  192. /* Restore extended register state.
  193. * See struct thread_struct in processor.h.
  194. */
  195. thread = &current->thread;
  196. err |= __copy_from_user (regs->areg, sc->sc_areg, XCHAL_NUM_AREGS*4);
  197. err |= __get_user(buf, &sc->sc_cpstate);
  198. if (buf) {
  199. if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
  200. goto badframe;
  201. err |= restore_cpextra(buf);
  202. }
  203. regs->syscall = -1; /* disable syscall checks */
  204. return err;
  205. badframe:
  206. return 1;
  207. }
  208. static inline void
  209. flush_my_cpstate(struct task_struct *tsk)
  210. {
  211. unsigned long flags;
  212. local_irq_save(flags);
  213. #if 0 // FIXME
  214. for (i = 0; i < XCHAL_CP_NUM; i++) {
  215. if (tsk == coproc_owners[i]) {
  216. xthal_validate_cp(i);
  217. xthal_save_cpregs(tsk->thread.cpregs_ptr[i], i);
  218. /* Invalidate and "disown" the cp to allow
  219. * callers the chance to reset cp state in the
  220. * task_struct. */
  221. xthal_invalidate_cp(i);
  222. coproc_owners[i] = 0;
  223. }
  224. }
  225. #endif
  226. local_irq_restore(flags);
  227. }
  228. /* Return codes:
  229. 0: nothing saved
  230. 1: stuff to save, successful
  231. -1: stuff to save, error happened
  232. */
  233. static int
  234. save_cpextra (struct _cpstate *buf)
  235. {
  236. #if XCHAL_CP_NUM == 0
  237. return 0;
  238. #else
  239. /* FIXME: If a task has never used a coprocessor, there is
  240. * no need to save and restore anything. Tracking this
  241. * information would allow us to optimize this section.
  242. * Perhaps we can use current->used_math or (current->flags &
  243. * PF_USEDFPU) or define a new field in the thread
  244. * structure. */
  245. /* We flush any live, task-owned cp state to the task_struct,
  246. * then copy it all to the sigframe. Then we clear all
  247. * cp/extra state in the task_struct, effectively
  248. * clearing/resetting all cp/extra state for the signal
  249. * handler (cp-exception handling will load these new values
  250. * into the cp/extra registers.) This step is important for
  251. * things like a floating-point cp, where the OS must reset
  252. * the FCR to the default rounding mode. */
  253. int err = 0;
  254. struct task_struct *tsk = current;
  255. flush_my_cpstate(tsk);
  256. /* Note that we just copy everything: 'extra' and 'cp' state together.*/
  257. err |= __copy_to_user(buf, tsk->thread.cp_save, XTENSA_CP_EXTRA_SIZE);
  258. memset(tsk->thread.cp_save, 0, XTENSA_CP_EXTRA_SIZE);
  259. #if (XTENSA_CP_EXTRA_SIZE == 0)
  260. #error Sanity check on memset above, cpextra_size should not be zero.
  261. #endif
  262. return err ? -1 : 1;
  263. #endif
  264. }
  265. static int
  266. setup_sigcontext(struct sigcontext *sc, struct _cpstate *cpstate,
  267. struct pt_regs *regs, unsigned long mask)
  268. {
  269. struct thread_struct *thread;
  270. int err = 0;
  271. //printk("setup_sigcontext\n");
  272. #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
  273. COPY(pc);
  274. COPY(ps);
  275. COPY(depc);
  276. COPY(wmask);
  277. COPY(lbeg);
  278. COPY(lend);
  279. COPY(lcount);
  280. COPY(sar);
  281. COPY(windowbase);
  282. COPY(windowstart);
  283. #undef COPY
  284. /* Save extended register state.
  285. * See struct thread_struct in processor.h.
  286. */
  287. thread = &current->thread;
  288. err |= __copy_to_user (sc->sc_areg, regs->areg, XCHAL_NUM_AREGS * 4);
  289. err |= save_cpextra(cpstate);
  290. err |= __put_user(err ? NULL : cpstate, &sc->sc_cpstate);
  291. /* non-iBCS2 extensions.. */
  292. err |= __put_user(mask, &sc->oldmask);
  293. return err;
  294. }
  295. asmlinkage int xtensa_sigreturn(struct pt_regs *regs)
  296. {
  297. struct sigframe *frame = (struct sigframe *)regs->areg[1];
  298. sigset_t set;
  299. if (regs->depc > 64)
  300. panic ("Double exception sys_sigreturn\n");
  301. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  302. goto badframe;
  303. if (__get_user(set.sig[0], &frame->sc.oldmask)
  304. || (_NSIG_WORDS > 1
  305. && __copy_from_user(&set.sig[1], &frame->extramask,
  306. sizeof(frame->extramask))))
  307. goto badframe;
  308. sigdelsetmask(&set, ~_BLOCKABLE);
  309. spin_lock_irq(&current->sighand->siglock);
  310. current->blocked = set;
  311. recalc_sigpending();
  312. spin_unlock_irq(&current->sighand->siglock);
  313. if (restore_sigcontext(regs, &frame->sc))
  314. goto badframe;
  315. return regs->areg[2];
  316. badframe:
  317. force_sig(SIGSEGV, current);
  318. return 0;
  319. }
  320. asmlinkage int xtensa_rt_sigreturn(struct pt_regs *regs)
  321. {
  322. struct rt_sigframe *frame = (struct rt_sigframe *)regs->areg[1];
  323. sigset_t set;
  324. stack_t st;
  325. int ret;
  326. if (regs->depc > 64)
  327. {
  328. printk("!!!!!!! DEPC !!!!!!!\n");
  329. return 0;
  330. }
  331. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  332. goto badframe;
  333. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  334. goto badframe;
  335. sigdelsetmask(&set, ~_BLOCKABLE);
  336. spin_lock_irq(&current->sighand->siglock);
  337. current->blocked = set;
  338. recalc_sigpending();
  339. spin_unlock_irq(&current->sighand->siglock);
  340. if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
  341. goto badframe;
  342. ret = regs->areg[2];
  343. if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
  344. goto badframe;
  345. /* It is more difficult to avoid calling this function than to
  346. call it and ignore errors. */
  347. do_sigaltstack(&st, NULL, regs->areg[1]);
  348. return ret;
  349. badframe:
  350. force_sig(SIGSEGV, current);
  351. return 0;
  352. }
  353. /*
  354. * Set up a signal frame.
  355. */
  356. /*
  357. * Determine which stack to use..
  358. */
  359. static inline void *
  360. get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
  361. {
  362. if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
  363. sp = current->sas_ss_sp + current->sas_ss_size;
  364. return (void *)((sp - frame_size) & -16ul);
  365. }
  366. #define USE_SIGRETURN 0
  367. #define USE_RT_SIGRETURN 1
  368. static int
  369. gen_return_code(unsigned char *codemem, unsigned int use_rt_sigreturn)
  370. {
  371. unsigned int retcall;
  372. int err = 0;
  373. #if 0
  374. /* Ignoring SA_RESTORER for now; it's supposed to be obsolete,
  375. * and the xtensa glibc doesn't use it.
  376. */
  377. if (ka->sa.sa_flags & SA_RESTORER) {
  378. regs->pr = (unsigned long) ka->sa.sa_restorer;
  379. } else
  380. #endif /* 0 */
  381. {
  382. #if (__NR_sigreturn > 255) || (__NR_rt_sigreturn > 255)
  383. /* The 12-bit immediate is really split up within the 24-bit MOVI
  384. * instruction. As long as the above system call numbers fit within
  385. * 8-bits, the following code works fine. See the Xtensa ISA for
  386. * details.
  387. */
  388. #error Generating the MOVI instruction below breaks!
  389. #endif
  390. retcall = use_rt_sigreturn ? __NR_rt_sigreturn : __NR_sigreturn;
  391. #ifdef __XTENSA_EB__ /* Big Endian version */
  392. /* Generate instruction: MOVI a2, retcall */
  393. err |= __put_user(0x22, &codemem[0]);
  394. err |= __put_user(0x0a, &codemem[1]);
  395. err |= __put_user(retcall, &codemem[2]);
  396. /* Generate instruction: SYSCALL */
  397. err |= __put_user(0x00, &codemem[3]);
  398. err |= __put_user(0x05, &codemem[4]);
  399. err |= __put_user(0x00, &codemem[5]);
  400. #elif defined __XTENSA_EL__ /* Little Endian version */
  401. /* Generate instruction: MOVI a2, retcall */
  402. err |= __put_user(0x22, &codemem[0]);
  403. err |= __put_user(0xa0, &codemem[1]);
  404. err |= __put_user(retcall, &codemem[2]);
  405. /* Generate instruction: SYSCALL */
  406. err |= __put_user(0x00, &codemem[3]);
  407. err |= __put_user(0x50, &codemem[4]);
  408. err |= __put_user(0x00, &codemem[5]);
  409. #else
  410. #error Must use compiler for Xtensa processors.
  411. #endif
  412. }
  413. /* Flush generated code out of the data cache */
  414. if (err == 0) {
  415. __invalidate_icache_range((unsigned long)codemem, 6UL);
  416. __flush_invalidate_dcache_range((unsigned long)codemem, 6UL);
  417. }
  418. return err;
  419. }
  420. static void
  421. set_thread_state(struct pt_regs *regs, void *stack, unsigned char *retaddr,
  422. void *handler, unsigned long arg1, void *arg2, void *arg3)
  423. {
  424. /* Set up registers for signal handler */
  425. start_thread(regs, (unsigned long) handler, (unsigned long) stack);
  426. /* Set up a stack frame for a call4
  427. * Note: PS.CALLINC is set to one by start_thread
  428. */
  429. regs->areg[4] = (((unsigned long) retaddr) & 0x3fffffff) | 0x40000000;
  430. regs->areg[6] = arg1;
  431. regs->areg[7] = (unsigned long) arg2;
  432. regs->areg[8] = (unsigned long) arg3;
  433. }
  434. static void setup_frame(int sig, struct k_sigaction *ka,
  435. sigset_t *set, struct pt_regs *regs)
  436. {
  437. struct sigframe *frame;
  438. int err = 0;
  439. int signal;
  440. frame = get_sigframe(ka, regs->areg[1], sizeof(*frame));
  441. if (regs->depc > 64)
  442. {
  443. printk("!!!!!!! DEPC !!!!!!!\n");
  444. return;
  445. }
  446. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  447. goto give_sigsegv;
  448. signal = current_thread_info()->exec_domain
  449. && current_thread_info()->exec_domain->signal_invmap
  450. && sig < 32
  451. ? current_thread_info()->exec_domain->signal_invmap[sig]
  452. : sig;
  453. err |= setup_sigcontext(&frame->sc, &frame->cpstate, regs, set->sig[0]);
  454. if (_NSIG_WORDS > 1) {
  455. err |= __copy_to_user(frame->extramask, &set->sig[1],
  456. sizeof(frame->extramask));
  457. }
  458. /* Create sys_sigreturn syscall in stack frame */
  459. err |= gen_return_code(frame->retcode, USE_SIGRETURN);
  460. if (err)
  461. goto give_sigsegv;
  462. /* Create signal handler execution context.
  463. * Return context not modified until this point.
  464. */
  465. set_thread_state(regs, frame, frame->retcode,
  466. ka->sa.sa_handler, signal, &frame->sc, NULL);
  467. /* Set access mode to USER_DS. Nomenclature is outdated, but
  468. * functionality is used in uaccess.h
  469. */
  470. set_fs(USER_DS);
  471. #if DEBUG_SIG
  472. printk("SIG deliver (%s:%d): signal=%d sp=%p pc=%08x\n",
  473. current->comm, current->pid, signal, frame, regs->pc);
  474. #endif
  475. return;
  476. give_sigsegv:
  477. if (sig == SIGSEGV)
  478. ka->sa.sa_handler = SIG_DFL;
  479. force_sig(SIGSEGV, current);
  480. }
  481. static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  482. sigset_t *set, struct pt_regs *regs)
  483. {
  484. struct rt_sigframe *frame;
  485. int err = 0;
  486. int signal;
  487. frame = get_sigframe(ka, regs->areg[1], sizeof(*frame));
  488. if (regs->depc > 64)
  489. panic ("Double exception sys_sigreturn\n");
  490. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  491. goto give_sigsegv;
  492. signal = current_thread_info()->exec_domain
  493. && current_thread_info()->exec_domain->signal_invmap
  494. && sig < 32
  495. ? current_thread_info()->exec_domain->signal_invmap[sig]
  496. : sig;
  497. err |= copy_siginfo_to_user(&frame->info, info);
  498. /* Create the ucontext. */
  499. err |= __put_user(0, &frame->uc.uc_flags);
  500. err |= __put_user(0, &frame->uc.uc_link);
  501. err |= __put_user((void *)current->sas_ss_sp,
  502. &frame->uc.uc_stack.ss_sp);
  503. err |= __put_user(sas_ss_flags(regs->areg[1]),
  504. &frame->uc.uc_stack.ss_flags);
  505. err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  506. err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->cpstate,
  507. regs, set->sig[0]);
  508. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  509. /* Create sys_rt_sigreturn syscall in stack frame */
  510. err |= gen_return_code(frame->retcode, USE_RT_SIGRETURN);
  511. if (err)
  512. goto give_sigsegv;
  513. /* Create signal handler execution context.
  514. * Return context not modified until this point.
  515. */
  516. set_thread_state(regs, frame, frame->retcode,
  517. ka->sa.sa_handler, signal, &frame->info, &frame->uc);
  518. /* Set access mode to USER_DS. Nomenclature is outdated, but
  519. * functionality is used in uaccess.h
  520. */
  521. set_fs(USER_DS);
  522. #if DEBUG_SIG
  523. printk("SIG rt deliver (%s:%d): signal=%d sp=%p pc=%08x\n",
  524. current->comm, current->pid, signal, frame, regs->pc);
  525. #endif
  526. return;
  527. give_sigsegv:
  528. if (sig == SIGSEGV)
  529. ka->sa.sa_handler = SIG_DFL;
  530. force_sig(SIGSEGV, current);
  531. }
  532. /*
  533. * Note that 'init' is a special process: it doesn't get signals it doesn't
  534. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  535. * mistake.
  536. *
  537. * Note that we go through the signals twice: once to check the signals that
  538. * the kernel can handle, and then we build all the user-level signal handling
  539. * stack-frames in one go after that.
  540. */
  541. int do_signal(struct pt_regs *regs, sigset_t *oldset)
  542. {
  543. siginfo_t info;
  544. int signr;
  545. struct k_sigaction ka;
  546. if (!oldset)
  547. oldset = &current->blocked;
  548. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  549. /* Are we from a system call? */
  550. if (regs->syscall >= 0) {
  551. /* If so, check system call restarting.. */
  552. switch (regs->areg[2]) {
  553. case ERESTARTNOHAND:
  554. case ERESTART_RESTARTBLOCK:
  555. regs->areg[2] = -EINTR;
  556. break;
  557. case ERESTARTSYS:
  558. if (!(ka.sa.sa_flags & SA_RESTART)) {
  559. regs->areg[2] = -EINTR;
  560. break;
  561. }
  562. /* fallthrough */
  563. case ERESTARTNOINTR:
  564. regs->areg[2] = regs->syscall;
  565. regs->pc -= 3;
  566. }
  567. }
  568. if (signr == 0)
  569. return 0; /* no signals delivered */
  570. /* Whee! Actually deliver the signal. */
  571. /* Set up the stack frame */
  572. if (ka.sa.sa_flags & SA_SIGINFO)
  573. setup_rt_frame(signr, &ka, &info, oldset, regs);
  574. else
  575. setup_frame(signr, &ka, oldset, regs);
  576. if (ka.sa.sa_flags & SA_ONESHOT)
  577. ka.sa.sa_handler = SIG_DFL;
  578. spin_lock_irq(&current->sighand->siglock);
  579. sigorsets(&current->blocked, &current->blocked, &ka.sa.sa_mask);
  580. if (!(ka.sa.sa_flags & SA_NODEFER))
  581. sigaddset(&current->blocked, signr);
  582. recalc_sigpending();
  583. spin_unlock_irq(&current->sighand->siglock);
  584. return 1;
  585. }