signal.c 18 KB

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