signal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * Copyright (C) 2003, Axis Communications AB.
  3. */
  4. #include <linux/sched.h>
  5. #include <linux/mm.h>
  6. #include <linux/kernel.h>
  7. #include <linux/signal.h>
  8. #include <linux/errno.h>
  9. #include <linux/wait.h>
  10. #include <linux/ptrace.h>
  11. #include <linux/unistd.h>
  12. #include <linux/stddef.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/vmalloc.h>
  15. #include <asm/io.h>
  16. #include <asm/processor.h>
  17. #include <asm/ucontext.h>
  18. #include <asm/uaccess.h>
  19. #include <asm/arch/ptrace.h>
  20. #include <asm/arch/hwregs/cpu_vect.h>
  21. extern unsigned long cris_signal_return_page;
  22. /* Flag to check if a signal is blockable. */
  23. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  24. /*
  25. * A syscall in CRIS is really a "break 13" instruction, which is 2
  26. * bytes. The registers is manipulated so upon return the instruction
  27. * will be executed again.
  28. *
  29. * This relies on that PC points to the instruction after the break call.
  30. */
  31. #define RESTART_CRIS_SYS(regs) regs->r10 = regs->orig_r10; regs->erp -= 2;
  32. /* Signal frames. */
  33. struct signal_frame {
  34. struct sigcontext sc;
  35. unsigned long extramask[_NSIG_WORDS - 1];
  36. unsigned char retcode[8]; /* Trampoline code. */
  37. };
  38. struct rt_signal_frame {
  39. struct siginfo *pinfo;
  40. void *puc;
  41. struct siginfo info;
  42. struct ucontext uc;
  43. unsigned char retcode[8]; /* Trampoline code. */
  44. };
  45. int do_signal(int restart, sigset_t *oldset, struct pt_regs *regs);
  46. void keep_debug_flags(unsigned long oldccs, unsigned long oldspc,
  47. struct pt_regs *regs);
  48. /*
  49. * Swap in the new signal mask, and wait for a signal. Define some
  50. * dummy arguments to be able to reach the regs argument.
  51. */
  52. int
  53. sys_sigsuspend(old_sigset_t mask, long r11, long r12, long r13, long mof,
  54. long srp, struct pt_regs *regs)
  55. {
  56. sigset_t saveset;
  57. mask &= _BLOCKABLE;
  58. spin_lock_irq(&current->sighand->siglock);
  59. saveset = current->blocked;
  60. siginitset(&current->blocked, mask);
  61. recalc_sigpending();
  62. spin_unlock_irq(&current->sighand->siglock);
  63. regs->r10 = -EINTR;
  64. while (1) {
  65. current->state = TASK_INTERRUPTIBLE;
  66. schedule();
  67. if (do_signal(0, &saveset, regs)) {
  68. /*
  69. * This point is reached twice: once to call
  70. * the signal handler, then again to return
  71. * from the sigsuspend system call. When
  72. * calling the signal handler, R10 hold the
  73. * signal number as set by do_signal(). The
  74. * sigsuspend call will always return with
  75. * the restored value above; -EINTR.
  76. */
  77. return regs->r10;
  78. }
  79. }
  80. }
  81. /* Define some dummy arguments to be able to reach the regs argument. */
  82. int
  83. sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, long r12, long r13,
  84. long mof, long srp, struct pt_regs *regs)
  85. {
  86. sigset_t saveset;
  87. sigset_t newset;
  88. if (sigsetsize != sizeof(sigset_t))
  89. return -EINVAL;
  90. if (copy_from_user(&newset, unewset, sizeof(newset)))
  91. return -EFAULT;
  92. sigdelsetmask(&newset, ~_BLOCKABLE);
  93. spin_lock_irq(&current->sighand->siglock);
  94. saveset = current->blocked;
  95. current->blocked = newset;
  96. recalc_sigpending();
  97. spin_unlock_irq(&current->sighand->siglock);
  98. regs->r10 = -EINTR;
  99. while (1) {
  100. current->state = TASK_INTERRUPTIBLE;
  101. schedule();
  102. if (do_signal(0, &saveset, regs)) {
  103. /* See comment in function above. */
  104. return regs->r10;
  105. }
  106. }
  107. }
  108. int
  109. sys_sigaction(int signal, const struct old_sigaction *act,
  110. struct old_sigaction *oact)
  111. {
  112. int retval;
  113. struct k_sigaction newk;
  114. struct k_sigaction oldk;
  115. if (act) {
  116. old_sigset_t mask;
  117. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  118. __get_user(newk.sa.sa_handler, &act->sa_handler) ||
  119. __get_user(newk.sa.sa_restorer, &act->sa_restorer))
  120. return -EFAULT;
  121. __get_user(newk.sa.sa_flags, &act->sa_flags);
  122. __get_user(mask, &act->sa_mask);
  123. siginitset(&newk.sa.sa_mask, mask);
  124. }
  125. retval = do_sigaction(signal, act ? &newk : NULL, oact ? &oldk : NULL);
  126. if (!retval && oact) {
  127. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  128. __put_user(oldk.sa.sa_handler, &oact->sa_handler) ||
  129. __put_user(oldk.sa.sa_restorer, &oact->sa_restorer))
  130. return -EFAULT;
  131. __put_user(oldk.sa.sa_flags, &oact->sa_flags);
  132. __put_user(oldk.sa.sa_mask.sig[0], &oact->sa_mask);
  133. }
  134. return retval;
  135. }
  136. int
  137. sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
  138. {
  139. return do_sigaltstack(uss, uoss, rdusp());
  140. }
  141. static int
  142. restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
  143. {
  144. unsigned int err = 0;
  145. unsigned long old_usp;
  146. /* Always make any pending restarted system calls return -EINTR */
  147. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  148. /*
  149. * Restore the registers from &sc->regs. sc is already checked
  150. * for VERIFY_READ since the signal_frame was previously
  151. * checked in sys_sigreturn().
  152. */
  153. if (__copy_from_user(regs, sc, sizeof(struct pt_regs)))
  154. goto badframe;
  155. /* Make that the user-mode flag is set. */
  156. regs->ccs |= (1 << (U_CCS_BITNR + CCS_SHIFT));
  157. /* Restore the old USP. */
  158. err |= __get_user(old_usp, &sc->usp);
  159. wrusp(old_usp);
  160. return err;
  161. badframe:
  162. return 1;
  163. }
  164. /* Define some dummy arguments to be able to reach the regs argument. */
  165. asmlinkage int
  166. sys_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
  167. struct pt_regs *regs)
  168. {
  169. sigset_t set;
  170. struct signal_frame __user *frame;
  171. unsigned long oldspc = regs->spc;
  172. unsigned long oldccs = regs->ccs;
  173. frame = (struct signal_frame *) rdusp();
  174. /*
  175. * Since the signal is stacked on a dword boundary, the frame
  176. * should be dword aligned here as well. It it's not, then the
  177. * user is trying some funny business.
  178. */
  179. if (((long)frame) & 3)
  180. goto badframe;
  181. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  182. goto badframe;
  183. if (__get_user(set.sig[0], &frame->sc.oldmask) ||
  184. (_NSIG_WORDS > 1 && __copy_from_user(&set.sig[1],
  185. frame->extramask,
  186. sizeof(frame->extramask))))
  187. goto badframe;
  188. sigdelsetmask(&set, ~_BLOCKABLE);
  189. spin_lock_irq(&current->sighand->siglock);
  190. current->blocked = set;
  191. recalc_sigpending();
  192. spin_unlock_irq(&current->sighand->siglock);
  193. if (restore_sigcontext(regs, &frame->sc))
  194. goto badframe;
  195. keep_debug_flags(oldccs, oldspc, regs);
  196. return regs->r10;
  197. badframe:
  198. force_sig(SIGSEGV, current);
  199. return 0;
  200. }
  201. /* Define some dummy variables to be able to reach the regs argument. */
  202. asmlinkage int
  203. sys_rt_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
  204. struct pt_regs *regs)
  205. {
  206. sigset_t set;
  207. struct rt_signal_frame __user *frame;
  208. unsigned long oldspc = regs->spc;
  209. unsigned long oldccs = regs->ccs;
  210. frame = (struct rt_signal_frame *) rdusp();
  211. /*
  212. * Since the signal is stacked on a dword boundary, the frame
  213. * should be dword aligned here as well. It it's not, then the
  214. * user is trying some funny business.
  215. */
  216. if (((long)frame) & 3)
  217. goto badframe;
  218. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  219. goto badframe;
  220. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  221. goto badframe;
  222. sigdelsetmask(&set, ~_BLOCKABLE);
  223. spin_lock_irq(&current->sighand->siglock);
  224. current->blocked = set;
  225. recalc_sigpending();
  226. spin_unlock_irq(&current->sighand->siglock);
  227. if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
  228. goto badframe;
  229. if (do_sigaltstack(&frame->uc.uc_stack, NULL, rdusp()) == -EFAULT)
  230. goto badframe;
  231. keep_debug_flags(oldccs, oldspc, regs);
  232. return regs->r10;
  233. badframe:
  234. force_sig(SIGSEGV, current);
  235. return 0;
  236. }
  237. /* Setup a signal frame. */
  238. static int
  239. setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
  240. unsigned long mask)
  241. {
  242. int err;
  243. unsigned long usp;
  244. err = 0;
  245. usp = rdusp();
  246. /*
  247. * Copy the registers. They are located first in sc, so it's
  248. * possible to use sc directly.
  249. */
  250. err |= __copy_to_user(sc, regs, sizeof(struct pt_regs));
  251. err |= __put_user(mask, &sc->oldmask);
  252. err |= __put_user(usp, &sc->usp);
  253. return err;
  254. }
  255. /* Figure out where to put the new signal frame - usually on the stack. */
  256. static inline void __user *
  257. get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
  258. {
  259. unsigned long sp;
  260. sp = rdusp();
  261. /* This is the X/Open sanctioned signal stack switching. */
  262. if (ka->sa.sa_flags & SA_ONSTACK) {
  263. if (!on_sig_stack(sp))
  264. sp = current->sas_ss_sp + current->sas_ss_size;
  265. }
  266. /* Make sure the frame is dword-aligned. */
  267. sp &= ~3;
  268. return (void __user *)(sp - frame_size);
  269. }
  270. /* Grab and setup a signal frame.
  271. *
  272. * Basically a lot of state-info is stacked, and arranged for the
  273. * user-mode program to return to the kernel using either a trampiline
  274. * which performs the syscall sigreturn(), or a provided user-mode
  275. * trampoline.
  276. */
  277. static void
  278. setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
  279. struct pt_regs * regs)
  280. {
  281. int err;
  282. unsigned long return_ip;
  283. struct signal_frame __user *frame;
  284. err = 0;
  285. frame = get_sigframe(ka, regs, sizeof(*frame));
  286. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  287. goto give_sigsegv;
  288. err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
  289. if (err)
  290. goto give_sigsegv;
  291. if (_NSIG_WORDS > 1) {
  292. err |= __copy_to_user(frame->extramask, &set->sig[1],
  293. sizeof(frame->extramask));
  294. }
  295. if (err)
  296. goto give_sigsegv;
  297. /*
  298. * Set up to return from user-space. If provided, use a stub
  299. * already located in user-space.
  300. */
  301. if (ka->sa.sa_flags & SA_RESTORER) {
  302. return_ip = (unsigned long)ka->sa.sa_restorer;
  303. } else {
  304. /* Trampoline - the desired return ip is in the signal return page. */
  305. return_ip = cris_signal_return_page;
  306. /*
  307. * This is movu.w __NR_sigreturn, r9; break 13;
  308. *
  309. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  310. * reasons and because gdb uses it as a signature to notice
  311. * signal handler stack frames.
  312. */
  313. err |= __put_user(0x9c5f, (short __user*)(frame->retcode+0));
  314. err |= __put_user(__NR_sigreturn, (short __user*)(frame->retcode+2));
  315. err |= __put_user(0xe93d, (short __user*)(frame->retcode+4));
  316. }
  317. if (err)
  318. goto give_sigsegv;
  319. /*
  320. * Set up registers for signal handler.
  321. *
  322. * Where the code enters now.
  323. * Where the code enter later.
  324. * First argument, signo.
  325. */
  326. regs->erp = (unsigned long) ka->sa.sa_handler;
  327. regs->srp = return_ip;
  328. regs->r10 = sig;
  329. /* Actually move the USP to reflect the stacked frame. */
  330. wrusp((unsigned long)frame);
  331. return;
  332. give_sigsegv:
  333. if (sig == SIGSEGV)
  334. ka->sa.sa_handler = SIG_DFL;
  335. force_sig(SIGSEGV, current);
  336. }
  337. static void
  338. setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  339. sigset_t *set, struct pt_regs * regs)
  340. {
  341. int err;
  342. unsigned long return_ip;
  343. struct rt_signal_frame __user *frame;
  344. err = 0;
  345. frame = get_sigframe(ka, regs, sizeof(*frame));
  346. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  347. goto give_sigsegv;
  348. /* TODO: what is the current->exec_domain stuff and invmap ? */
  349. err |= __put_user(&frame->info, &frame->pinfo);
  350. err |= __put_user(&frame->uc, &frame->puc);
  351. err |= copy_siginfo_to_user(&frame->info, info);
  352. if (err)
  353. goto give_sigsegv;
  354. /* Clear all the bits of the ucontext we don't use. */
  355. err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
  356. err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
  357. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  358. if (err)
  359. goto give_sigsegv;
  360. /*
  361. * Set up to return from user-space. If provided, use a stub
  362. * already located in user-space.
  363. */
  364. if (ka->sa.sa_flags & SA_RESTORER) {
  365. return_ip = (unsigned long) ka->sa.sa_restorer;
  366. } else {
  367. /* Trampoline - the desired return ip is in the signal return page. */
  368. return_ip = cris_signal_return_page + 6;
  369. /*
  370. * This is movu.w __NR_rt_sigreturn, r9; break 13;
  371. *
  372. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  373. * reasons and because gdb uses it as a signature to notice
  374. * signal handler stack frames.
  375. */
  376. err |= __put_user(0x9c5f, (short __user*)(frame->retcode+0));
  377. err |= __put_user(__NR_rt_sigreturn,
  378. (short __user*)(frame->retcode+2));
  379. err |= __put_user(0xe93d, (short __user*)(frame->retcode+4));
  380. }
  381. if (err)
  382. goto give_sigsegv;
  383. /*
  384. * Set up registers for signal handler.
  385. *
  386. * Where the code enters now.
  387. * Where the code enters later.
  388. * First argument is signo.
  389. * Second argument is (siginfo_t *).
  390. * Third argument is unused.
  391. */
  392. regs->erp = (unsigned long) ka->sa.sa_handler;
  393. regs->srp = return_ip;
  394. regs->r10 = sig;
  395. regs->r11 = (unsigned long) &frame->info;
  396. regs->r12 = 0;
  397. /* Actually move the usp to reflect the stacked frame. */
  398. wrusp((unsigned long)frame);
  399. return;
  400. give_sigsegv:
  401. if (sig == SIGSEGV)
  402. ka->sa.sa_handler = SIG_DFL;
  403. force_sig(SIGSEGV, current);
  404. }
  405. /* Invoke a singal handler to, well, handle the signal. */
  406. extern inline void
  407. handle_signal(int canrestart, unsigned long sig,
  408. siginfo_t *info, struct k_sigaction *ka,
  409. sigset_t *oldset, struct pt_regs * regs)
  410. {
  411. /* Check if this got called from a system call. */
  412. if (canrestart) {
  413. /* If so, check system call restarting. */
  414. switch (regs->r10) {
  415. case -ERESTART_RESTARTBLOCK:
  416. case -ERESTARTNOHAND:
  417. /*
  418. * This means that the syscall should
  419. * only be restarted if there was no
  420. * handler for the signal, and since
  421. * this point isn't reached unless
  422. * there is a handler, there's no need
  423. * to restart.
  424. */
  425. regs->r10 = -EINTR;
  426. break;
  427. case -ERESTARTSYS:
  428. /*
  429. * This means restart the syscall if
  430. * there is no handler, or the handler
  431. * was registered with SA_RESTART.
  432. */
  433. if (!(ka->sa.sa_flags & SA_RESTART)) {
  434. regs->r10 = -EINTR;
  435. break;
  436. }
  437. /* Fall through. */
  438. case -ERESTARTNOINTR:
  439. /*
  440. * This means that the syscall should
  441. * be called again after the signal
  442. * handler returns.
  443. */
  444. RESTART_CRIS_SYS(regs);
  445. break;
  446. }
  447. }
  448. /* Set up the stack frame. */
  449. if (ka->sa.sa_flags & SA_SIGINFO)
  450. setup_rt_frame(sig, ka, info, oldset, regs);
  451. else
  452. setup_frame(sig, ka, oldset, regs);
  453. if (ka->sa.sa_flags & SA_ONESHOT)
  454. ka->sa.sa_handler = SIG_DFL;
  455. spin_lock_irq(&current->sighand->siglock);
  456. sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
  457. if (!(ka->sa.sa_flags & SA_NODEFER))
  458. sigaddset(&current->blocked,sig);
  459. recalc_sigpending();
  460. spin_unlock_irq(&current->sighand->siglock);
  461. }
  462. /*
  463. * Note that 'init' is a special process: it doesn't get signals it doesn't
  464. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  465. * mistake.
  466. *
  467. * Also note that the regs structure given here as an argument, is the latest
  468. * pushed pt_regs. It may or may not be the same as the first pushed registers
  469. * when the initial usermode->kernelmode transition took place. Therefore
  470. * we can use user_mode(regs) to see if we came directly from kernel or user
  471. * mode below.
  472. */
  473. int
  474. do_signal(int canrestart, sigset_t *oldset, struct pt_regs *regs)
  475. {
  476. int signr;
  477. siginfo_t info;
  478. struct k_sigaction ka;
  479. /*
  480. * The common case should go fast, which is why this point is
  481. * reached from kernel-mode. If that's the case, just return
  482. * without doing anything.
  483. */
  484. if (!user_mode(regs))
  485. return 1;
  486. if (!oldset)
  487. oldset = &current->blocked;
  488. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  489. if (signr > 0) {
  490. /* Deliver the signal. */
  491. handle_signal(canrestart, signr, &info, &ka, oldset, regs);
  492. return 1;
  493. }
  494. /* Got here from a system call? */
  495. if (canrestart) {
  496. /* Restart the system call - no handlers present. */
  497. if (regs->r10 == -ERESTARTNOHAND ||
  498. regs->r10 == -ERESTARTSYS ||
  499. regs->r10 == -ERESTARTNOINTR) {
  500. RESTART_CRIS_SYS(regs);
  501. }
  502. if (regs->r10 == -ERESTART_RESTARTBLOCK){
  503. regs->r10 = __NR_restart_syscall;
  504. regs->erp -= 2;
  505. }
  506. }
  507. return 0;
  508. }
  509. asmlinkage void
  510. ugdb_trap_user(struct thread_info *ti, int sig)
  511. {
  512. if (((user_regs(ti)->exs & 0xff00) >> 8) != SINGLE_STEP_INTR_VECT) {
  513. /* Zero single-step PC if the reason we stopped wasn't a single
  514. step exception. This is to avoid relying on it when it isn't
  515. reliable. */
  516. user_regs(ti)->spc = 0;
  517. }
  518. /* FIXME: Filter out false h/w breakpoint hits (i.e. EDA
  519. not withing any configured h/w breakpoint range). Synchronize with
  520. what already exists for kernel debugging. */
  521. if (((user_regs(ti)->exs & 0xff00) >> 8) == BREAK_8_INTR_VECT) {
  522. /* Break 8: subtract 2 from ERP unless in a delay slot. */
  523. if (!(user_regs(ti)->erp & 0x1))
  524. user_regs(ti)->erp -= 2;
  525. }
  526. sys_kill(ti->task->pid, sig);
  527. }
  528. void
  529. keep_debug_flags(unsigned long oldccs, unsigned long oldspc,
  530. struct pt_regs *regs)
  531. {
  532. if (oldccs & (1 << Q_CCS_BITNR)) {
  533. /* Pending single step due to single-stepping the break 13
  534. in the signal trampoline: keep the Q flag. */
  535. regs->ccs |= (1 << Q_CCS_BITNR);
  536. /* S flag should be set - complain if it's not. */
  537. if (!(oldccs & (1 << (S_CCS_BITNR + CCS_SHIFT)))) {
  538. printk("Q flag but no S flag?");
  539. }
  540. regs->ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
  541. /* Assume the SPC is valid and interesting. */
  542. regs->spc = oldspc;
  543. } else if (oldccs & (1 << (S_CCS_BITNR + CCS_SHIFT))) {
  544. /* If a h/w bp was set in the signal handler we need
  545. to keep the S flag. */
  546. regs->ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
  547. /* Don't keep the old SPC though; if we got here due to
  548. a single-step, the Q flag should have been set. */
  549. } else if (regs->spc) {
  550. /* If we were single-stepping *before* the signal was taken,
  551. we don't want to restore that state now, because GDB will
  552. have forgotten all about it. */
  553. regs->spc = 0;
  554. regs->ccs &= ~(1 << (S_CCS_BITNR + CCS_SHIFT));
  555. }
  556. }
  557. /* Set up the trampolines on the signal return page. */
  558. int __init
  559. cris_init_signal(void)
  560. {
  561. u16* data = (u16*)kmalloc(PAGE_SIZE, GFP_KERNEL);
  562. /* This is movu.w __NR_sigreturn, r9; break 13; */
  563. data[0] = 0x9c5f;
  564. data[1] = __NR_sigreturn;
  565. data[2] = 0xe93d;
  566. /* This is movu.w __NR_rt_sigreturn, r9; break 13; */
  567. data[3] = 0x9c5f;
  568. data[4] = __NR_rt_sigreturn;
  569. data[5] = 0xe93d;
  570. /* Map to userspace with appropriate permissions (no write access...) */
  571. cris_signal_return_page = (unsigned long)
  572. __ioremap_prot(virt_to_phys(data), PAGE_SIZE, PAGE_SIGNAL_TRAMPOLINE);
  573. return 0;
  574. }
  575. __initcall(cris_init_signal);