traps.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*
  2. * linux/arch/arm/kernel/traps.c
  3. *
  4. * Copyright (C) 1995-2002 Russell King
  5. * Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * 'traps.c' handles hardware exceptions after we have saved some state in
  12. * 'linux/arch/arm/lib/traps.S'. Mostly a debugging aid, but will probably
  13. * kill the offending process.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/signal.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/personality.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/kallsyms.h>
  21. #include <linux/delay.h>
  22. #include <linux/init.h>
  23. #include <asm/atomic.h>
  24. #include <asm/cacheflush.h>
  25. #include <asm/system.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/unistd.h>
  28. #include <asm/traps.h>
  29. #include <asm/io.h>
  30. #include "ptrace.h"
  31. #include "signal.h"
  32. static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };
  33. #ifdef CONFIG_DEBUG_USER
  34. unsigned int user_debug;
  35. static int __init user_debug_setup(char *str)
  36. {
  37. get_option(&str, &user_debug);
  38. return 1;
  39. }
  40. __setup("user_debug=", user_debug_setup);
  41. #endif
  42. void dump_backtrace_entry(unsigned long where, unsigned long from)
  43. {
  44. #ifdef CONFIG_KALLSYMS
  45. printk("[<%08lx>] ", where);
  46. print_symbol("(%s) ", where);
  47. printk("from [<%08lx>] ", from);
  48. print_symbol("(%s)\n", from);
  49. #else
  50. printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
  51. #endif
  52. }
  53. /*
  54. * Stack pointers should always be within the kernels view of
  55. * physical memory. If it is not there, then we can't dump
  56. * out any information relating to the stack.
  57. */
  58. static int verify_stack(unsigned long sp)
  59. {
  60. if (sp < PAGE_OFFSET || (sp > (unsigned long)high_memory && high_memory != 0))
  61. return -EFAULT;
  62. return 0;
  63. }
  64. /*
  65. * Dump out the contents of some memory nicely...
  66. */
  67. static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
  68. {
  69. unsigned long p = bottom & ~31;
  70. mm_segment_t fs;
  71. int i;
  72. /*
  73. * We need to switch to kernel mode so that we can use __get_user
  74. * to safely read from kernel space. Note that we now dump the
  75. * code first, just in case the backtrace kills us.
  76. */
  77. fs = get_fs();
  78. set_fs(KERNEL_DS);
  79. printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
  80. for (p = bottom & ~31; p < top;) {
  81. printk("%04lx: ", p & 0xffff);
  82. for (i = 0; i < 8; i++, p += 4) {
  83. unsigned int val;
  84. if (p < bottom || p >= top)
  85. printk(" ");
  86. else {
  87. __get_user(val, (unsigned long *)p);
  88. printk("%08x ", val);
  89. }
  90. }
  91. printk ("\n");
  92. }
  93. set_fs(fs);
  94. }
  95. static void dump_instr(struct pt_regs *regs)
  96. {
  97. unsigned long addr = instruction_pointer(regs);
  98. const int thumb = thumb_mode(regs);
  99. const int width = thumb ? 4 : 8;
  100. mm_segment_t fs;
  101. int i;
  102. /*
  103. * We need to switch to kernel mode so that we can use __get_user
  104. * to safely read from kernel space. Note that we now dump the
  105. * code first, just in case the backtrace kills us.
  106. */
  107. fs = get_fs();
  108. set_fs(KERNEL_DS);
  109. printk("Code: ");
  110. for (i = -4; i < 1; i++) {
  111. unsigned int val, bad;
  112. if (thumb)
  113. bad = __get_user(val, &((u16 *)addr)[i]);
  114. else
  115. bad = __get_user(val, &((u32 *)addr)[i]);
  116. if (!bad)
  117. printk(i == 0 ? "(%0*x) " : "%0*x ", width, val);
  118. else {
  119. printk("bad PC value.");
  120. break;
  121. }
  122. }
  123. printk("\n");
  124. set_fs(fs);
  125. }
  126. static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
  127. {
  128. unsigned int fp;
  129. int ok = 1;
  130. printk("Backtrace: ");
  131. fp = regs->ARM_fp;
  132. if (!fp) {
  133. printk("no frame pointer");
  134. ok = 0;
  135. } else if (verify_stack(fp)) {
  136. printk("invalid frame pointer 0x%08x", fp);
  137. ok = 0;
  138. } else if (fp < (unsigned long)end_of_stack(tsk))
  139. printk("frame pointer underflow");
  140. printk("\n");
  141. if (ok)
  142. c_backtrace(fp, processor_mode(regs));
  143. }
  144. void dump_stack(void)
  145. {
  146. #ifdef CONFIG_DEBUG_ERRORS
  147. __backtrace();
  148. #endif
  149. }
  150. EXPORT_SYMBOL(dump_stack);
  151. void show_stack(struct task_struct *tsk, unsigned long *sp)
  152. {
  153. unsigned long fp;
  154. if (!tsk)
  155. tsk = current;
  156. if (tsk != current)
  157. fp = thread_saved_fp(tsk);
  158. else
  159. asm("mov %0, fp" : "=r" (fp) : : "cc");
  160. c_backtrace(fp, 0x10);
  161. barrier();
  162. }
  163. static void __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs)
  164. {
  165. struct task_struct *tsk = thread->task;
  166. static int die_counter;
  167. printk("Internal error: %s: %x [#%d]\n", str, err, ++die_counter);
  168. print_modules();
  169. __show_regs(regs);
  170. printk("Process %s (pid: %d, stack limit = 0x%p)\n",
  171. tsk->comm, tsk->pid, thread + 1);
  172. if (!user_mode(regs) || in_interrupt()) {
  173. dump_mem("Stack: ", regs->ARM_sp,
  174. THREAD_SIZE + (unsigned long)task_stack_page(tsk));
  175. dump_backtrace(regs, tsk);
  176. dump_instr(regs);
  177. }
  178. }
  179. DEFINE_SPINLOCK(die_lock);
  180. /*
  181. * This function is protected against re-entrancy.
  182. */
  183. NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
  184. {
  185. struct thread_info *thread = current_thread_info();
  186. console_verbose();
  187. spin_lock_irq(&die_lock);
  188. bust_spinlocks(1);
  189. __die(str, err, thread, regs);
  190. bust_spinlocks(0);
  191. spin_unlock_irq(&die_lock);
  192. if (panic_on_oops)
  193. panic("Fatal exception");
  194. do_exit(SIGSEGV);
  195. }
  196. void notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
  197. unsigned long err, unsigned long trap)
  198. {
  199. if (user_mode(regs)) {
  200. current->thread.error_code = err;
  201. current->thread.trap_no = trap;
  202. force_sig_info(info->si_signo, info, current);
  203. } else {
  204. die(str, regs, err);
  205. }
  206. }
  207. static LIST_HEAD(undef_hook);
  208. static DEFINE_SPINLOCK(undef_lock);
  209. void register_undef_hook(struct undef_hook *hook)
  210. {
  211. unsigned long flags;
  212. spin_lock_irqsave(&undef_lock, flags);
  213. list_add(&hook->node, &undef_hook);
  214. spin_unlock_irqrestore(&undef_lock, flags);
  215. }
  216. void unregister_undef_hook(struct undef_hook *hook)
  217. {
  218. unsigned long flags;
  219. spin_lock_irqsave(&undef_lock, flags);
  220. list_del(&hook->node);
  221. spin_unlock_irqrestore(&undef_lock, flags);
  222. }
  223. asmlinkage void do_undefinstr(struct pt_regs *regs)
  224. {
  225. unsigned int correction = thumb_mode(regs) ? 2 : 4;
  226. unsigned int instr;
  227. struct undef_hook *hook;
  228. siginfo_t info;
  229. void __user *pc;
  230. unsigned long flags;
  231. /*
  232. * According to the ARM ARM, PC is 2 or 4 bytes ahead,
  233. * depending whether we're in Thumb mode or not.
  234. * Correct this offset.
  235. */
  236. regs->ARM_pc -= correction;
  237. pc = (void __user *)instruction_pointer(regs);
  238. if (processor_mode(regs) == SVC_MODE) {
  239. instr = *(u32 *) pc;
  240. } else if (thumb_mode(regs)) {
  241. get_user(instr, (u16 __user *)pc);
  242. } else {
  243. get_user(instr, (u32 __user *)pc);
  244. }
  245. spin_lock_irqsave(&undef_lock, flags);
  246. list_for_each_entry(hook, &undef_hook, node) {
  247. if ((instr & hook->instr_mask) == hook->instr_val &&
  248. (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val) {
  249. if (hook->fn(regs, instr) == 0) {
  250. spin_unlock_irq(&undef_lock);
  251. return;
  252. }
  253. }
  254. }
  255. spin_unlock_irqrestore(&undef_lock, flags);
  256. #ifdef CONFIG_DEBUG_USER
  257. if (user_debug & UDBG_UNDEFINED) {
  258. printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",
  259. current->comm, current->pid, pc);
  260. dump_instr(regs);
  261. }
  262. #endif
  263. info.si_signo = SIGILL;
  264. info.si_errno = 0;
  265. info.si_code = ILL_ILLOPC;
  266. info.si_addr = pc;
  267. notify_die("Oops - undefined instruction", regs, &info, 0, 6);
  268. }
  269. asmlinkage void do_unexp_fiq (struct pt_regs *regs)
  270. {
  271. #ifndef CONFIG_IGNORE_FIQ
  272. printk("Hmm. Unexpected FIQ received, but trying to continue\n");
  273. printk("You may have a hardware problem...\n");
  274. #endif
  275. }
  276. /*
  277. * bad_mode handles the impossible case in the vectors. If you see one of
  278. * these, then it's extremely serious, and could mean you have buggy hardware.
  279. * It never returns, and never tries to sync. We hope that we can at least
  280. * dump out some state information...
  281. */
  282. asmlinkage void bad_mode(struct pt_regs *regs, int reason)
  283. {
  284. console_verbose();
  285. printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);
  286. die("Oops - bad mode", regs, 0);
  287. local_irq_disable();
  288. panic("bad mode");
  289. }
  290. static int bad_syscall(int n, struct pt_regs *regs)
  291. {
  292. struct thread_info *thread = current_thread_info();
  293. siginfo_t info;
  294. if (current->personality != PER_LINUX &&
  295. current->personality != PER_LINUX_32BIT &&
  296. thread->exec_domain->handler) {
  297. thread->exec_domain->handler(n, regs);
  298. return regs->ARM_r0;
  299. }
  300. #ifdef CONFIG_DEBUG_USER
  301. if (user_debug & UDBG_SYSCALL) {
  302. printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",
  303. current->pid, current->comm, n);
  304. dump_instr(regs);
  305. }
  306. #endif
  307. info.si_signo = SIGILL;
  308. info.si_errno = 0;
  309. info.si_code = ILL_ILLTRP;
  310. info.si_addr = (void __user *)instruction_pointer(regs) -
  311. (thumb_mode(regs) ? 2 : 4);
  312. notify_die("Oops - bad syscall", regs, &info, n, 0);
  313. return regs->ARM_r0;
  314. }
  315. static inline void
  316. do_cache_op(unsigned long start, unsigned long end, int flags)
  317. {
  318. struct vm_area_struct *vma;
  319. if (end < start || flags)
  320. return;
  321. vma = find_vma(current->active_mm, start);
  322. if (vma && vma->vm_start < end) {
  323. if (start < vma->vm_start)
  324. start = vma->vm_start;
  325. if (end > vma->vm_end)
  326. end = vma->vm_end;
  327. flush_cache_user_range(vma, start, end);
  328. }
  329. }
  330. /*
  331. * Handle all unrecognised system calls.
  332. * 0x9f0000 - 0x9fffff are some more esoteric system calls
  333. */
  334. #define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)
  335. asmlinkage int arm_syscall(int no, struct pt_regs *regs)
  336. {
  337. struct thread_info *thread = current_thread_info();
  338. siginfo_t info;
  339. if ((no >> 16) != (__ARM_NR_BASE>> 16))
  340. return bad_syscall(no, regs);
  341. switch (no & 0xffff) {
  342. case 0: /* branch through 0 */
  343. info.si_signo = SIGSEGV;
  344. info.si_errno = 0;
  345. info.si_code = SEGV_MAPERR;
  346. info.si_addr = NULL;
  347. notify_die("branch through zero", regs, &info, 0, 0);
  348. return 0;
  349. case NR(breakpoint): /* SWI BREAK_POINT */
  350. regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
  351. ptrace_break(current, regs);
  352. return regs->ARM_r0;
  353. /*
  354. * Flush a region from virtual address 'r0' to virtual address 'r1'
  355. * _exclusive_. There is no alignment requirement on either address;
  356. * user space does not need to know the hardware cache layout.
  357. *
  358. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  359. * is defined to be something else. For now we ignore it, but may
  360. * the fires of hell burn in your belly if you break this rule. ;)
  361. *
  362. * (at a later date, we may want to allow this call to not flush
  363. * various aspects of the cache. Passing '0' will guarantee that
  364. * everything necessary gets flushed to maintain consistency in
  365. * the specified region).
  366. */
  367. case NR(cacheflush):
  368. do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);
  369. return 0;
  370. case NR(usr26):
  371. if (!(elf_hwcap & HWCAP_26BIT))
  372. break;
  373. regs->ARM_cpsr &= ~MODE32_BIT;
  374. return regs->ARM_r0;
  375. case NR(usr32):
  376. if (!(elf_hwcap & HWCAP_26BIT))
  377. break;
  378. regs->ARM_cpsr |= MODE32_BIT;
  379. return regs->ARM_r0;
  380. case NR(set_tls):
  381. thread->tp_value = regs->ARM_r0;
  382. #if defined(CONFIG_HAS_TLS_REG)
  383. asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
  384. #elif !defined(CONFIG_TLS_REG_EMUL)
  385. /*
  386. * User space must never try to access this directly.
  387. * Expect your app to break eventually if you do so.
  388. * The user helper at 0xffff0fe0 must be used instead.
  389. * (see entry-armv.S for details)
  390. */
  391. *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
  392. #endif
  393. return 0;
  394. #ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
  395. /*
  396. * Atomically store r1 in *r2 if *r2 is equal to r0 for user space.
  397. * Return zero in r0 if *MEM was changed or non-zero if no exchange
  398. * happened. Also set the user C flag accordingly.
  399. * If access permissions have to be fixed up then non-zero is
  400. * returned and the operation has to be re-attempted.
  401. *
  402. * *NOTE*: This is a ghost syscall private to the kernel. Only the
  403. * __kuser_cmpxchg code in entry-armv.S should be aware of its
  404. * existence. Don't ever use this from user code.
  405. */
  406. case 0xfff0:
  407. {
  408. extern void do_DataAbort(unsigned long addr, unsigned int fsr,
  409. struct pt_regs *regs);
  410. unsigned long val;
  411. unsigned long addr = regs->ARM_r2;
  412. struct mm_struct *mm = current->mm;
  413. pgd_t *pgd; pmd_t *pmd; pte_t *pte;
  414. spinlock_t *ptl;
  415. regs->ARM_cpsr &= ~PSR_C_BIT;
  416. down_read(&mm->mmap_sem);
  417. pgd = pgd_offset(mm, addr);
  418. if (!pgd_present(*pgd))
  419. goto bad_access;
  420. pmd = pmd_offset(pgd, addr);
  421. if (!pmd_present(*pmd))
  422. goto bad_access;
  423. pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
  424. if (!pte_present(*pte) || !pte_dirty(*pte)) {
  425. pte_unmap_unlock(pte, ptl);
  426. goto bad_access;
  427. }
  428. val = *(unsigned long *)addr;
  429. val -= regs->ARM_r0;
  430. if (val == 0) {
  431. *(unsigned long *)addr = regs->ARM_r1;
  432. regs->ARM_cpsr |= PSR_C_BIT;
  433. }
  434. pte_unmap_unlock(pte, ptl);
  435. up_read(&mm->mmap_sem);
  436. return val;
  437. bad_access:
  438. up_read(&mm->mmap_sem);
  439. /* simulate a write access fault */
  440. do_DataAbort(addr, 15 + (1 << 11), regs);
  441. return -1;
  442. }
  443. #endif
  444. default:
  445. /* Calls 9f00xx..9f07ff are defined to return -ENOSYS
  446. if not implemented, rather than raising SIGILL. This
  447. way the calling program can gracefully determine whether
  448. a feature is supported. */
  449. if (no <= 0x7ff)
  450. return -ENOSYS;
  451. break;
  452. }
  453. #ifdef CONFIG_DEBUG_USER
  454. /*
  455. * experience shows that these seem to indicate that
  456. * something catastrophic has happened
  457. */
  458. if (user_debug & UDBG_SYSCALL) {
  459. printk("[%d] %s: arm syscall %d\n",
  460. current->pid, current->comm, no);
  461. dump_instr(regs);
  462. if (user_mode(regs)) {
  463. __show_regs(regs);
  464. c_backtrace(regs->ARM_fp, processor_mode(regs));
  465. }
  466. }
  467. #endif
  468. info.si_signo = SIGILL;
  469. info.si_errno = 0;
  470. info.si_code = ILL_ILLTRP;
  471. info.si_addr = (void __user *)instruction_pointer(regs) -
  472. (thumb_mode(regs) ? 2 : 4);
  473. notify_die("Oops - bad syscall(2)", regs, &info, no, 0);
  474. return 0;
  475. }
  476. #ifdef CONFIG_TLS_REG_EMUL
  477. /*
  478. * We might be running on an ARMv6+ processor which should have the TLS
  479. * register but for some reason we can't use it, or maybe an SMP system
  480. * using a pre-ARMv6 processor (there are apparently a few prototypes like
  481. * that in existence) and therefore access to that register must be
  482. * emulated.
  483. */
  484. static int get_tp_trap(struct pt_regs *regs, unsigned int instr)
  485. {
  486. int reg = (instr >> 12) & 15;
  487. if (reg == 15)
  488. return 1;
  489. regs->uregs[reg] = current_thread_info()->tp_value;
  490. regs->ARM_pc += 4;
  491. return 0;
  492. }
  493. static struct undef_hook arm_mrc_hook = {
  494. .instr_mask = 0x0fff0fff,
  495. .instr_val = 0x0e1d0f70,
  496. .cpsr_mask = PSR_T_BIT,
  497. .cpsr_val = 0,
  498. .fn = get_tp_trap,
  499. };
  500. static int __init arm_mrc_hook_init(void)
  501. {
  502. register_undef_hook(&arm_mrc_hook);
  503. return 0;
  504. }
  505. late_initcall(arm_mrc_hook_init);
  506. #endif
  507. void __bad_xchg(volatile void *ptr, int size)
  508. {
  509. printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",
  510. __builtin_return_address(0), ptr, size);
  511. BUG();
  512. }
  513. EXPORT_SYMBOL(__bad_xchg);
  514. /*
  515. * A data abort trap was taken, but we did not handle the instruction.
  516. * Try to abort the user program, or panic if it was the kernel.
  517. */
  518. asmlinkage void
  519. baddataabort(int code, unsigned long instr, struct pt_regs *regs)
  520. {
  521. unsigned long addr = instruction_pointer(regs);
  522. siginfo_t info;
  523. #ifdef CONFIG_DEBUG_USER
  524. if (user_debug & UDBG_BADABORT) {
  525. printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",
  526. current->pid, current->comm, code, instr);
  527. dump_instr(regs);
  528. show_pte(current->mm, addr);
  529. }
  530. #endif
  531. info.si_signo = SIGILL;
  532. info.si_errno = 0;
  533. info.si_code = ILL_ILLOPC;
  534. info.si_addr = (void __user *)addr;
  535. notify_die("unknown data abort code", regs, &info, instr, 0);
  536. }
  537. void __attribute__((noreturn)) __bug(const char *file, int line)
  538. {
  539. printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line);
  540. *(int *)0 = 0;
  541. /* Avoid "noreturn function does return" */
  542. for (;;);
  543. }
  544. EXPORT_SYMBOL(__bug);
  545. void __readwrite_bug(const char *fn)
  546. {
  547. printk("%s called, but not implemented\n", fn);
  548. BUG();
  549. }
  550. EXPORT_SYMBOL(__readwrite_bug);
  551. void __pte_error(const char *file, int line, unsigned long val)
  552. {
  553. printk("%s:%d: bad pte %08lx.\n", file, line, val);
  554. }
  555. void __pmd_error(const char *file, int line, unsigned long val)
  556. {
  557. printk("%s:%d: bad pmd %08lx.\n", file, line, val);
  558. }
  559. void __pgd_error(const char *file, int line, unsigned long val)
  560. {
  561. printk("%s:%d: bad pgd %08lx.\n", file, line, val);
  562. }
  563. asmlinkage void __div0(void)
  564. {
  565. printk("Division by zero in kernel.\n");
  566. dump_stack();
  567. }
  568. EXPORT_SYMBOL(__div0);
  569. void abort(void)
  570. {
  571. BUG();
  572. /* if that doesn't kill us, halt */
  573. panic("Oops failed to kill thread");
  574. }
  575. EXPORT_SYMBOL(abort);
  576. void __init trap_init(void)
  577. {
  578. unsigned long vectors = CONFIG_VECTORS_BASE;
  579. extern char __stubs_start[], __stubs_end[];
  580. extern char __vectors_start[], __vectors_end[];
  581. extern char __kuser_helper_start[], __kuser_helper_end[];
  582. int kuser_sz = __kuser_helper_end - __kuser_helper_start;
  583. /*
  584. * Copy the vectors, stubs and kuser helpers (in entry-armv.S)
  585. * into the vector page, mapped at 0xffff0000, and ensure these
  586. * are visible to the instruction stream.
  587. */
  588. memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
  589. memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
  590. memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
  591. /*
  592. * Copy signal return handlers into the vector page, and
  593. * set sigreturn to be a pointer to these.
  594. */
  595. memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,
  596. sizeof(sigreturn_codes));
  597. flush_icache_range(vectors, vectors + PAGE_SIZE);
  598. modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
  599. }