extable.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * linux/arch/frv/mm/extable.c
  3. */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/spinlock.h>
  7. #include <asm/uaccess.h>
  8. extern const struct exception_table_entry __attribute__((aligned(8))) __start___ex_table[];
  9. extern const struct exception_table_entry __attribute__((aligned(8))) __stop___ex_table[];
  10. extern const void __memset_end, __memset_user_error_lr, __memset_user_error_handler;
  11. extern const void __memcpy_end, __memcpy_user_error_lr, __memcpy_user_error_handler;
  12. extern spinlock_t modlist_lock;
  13. /*****************************************************************************/
  14. /*
  15. *
  16. */
  17. static inline unsigned long search_one_table(const struct exception_table_entry *first,
  18. const struct exception_table_entry *last,
  19. unsigned long value)
  20. {
  21. while (first <= last) {
  22. const struct exception_table_entry __attribute__((aligned(8))) *mid;
  23. long diff;
  24. mid = (last - first) / 2 + first;
  25. diff = mid->insn - value;
  26. if (diff == 0)
  27. return mid->fixup;
  28. else if (diff < 0)
  29. first = mid + 1;
  30. else
  31. last = mid - 1;
  32. }
  33. return 0;
  34. } /* end search_one_table() */
  35. /*****************************************************************************/
  36. /*
  37. * see if there's a fixup handler available to deal with a kernel fault
  38. */
  39. unsigned long search_exception_table(unsigned long pc)
  40. {
  41. unsigned long ret = 0;
  42. /* determine if the fault lay during a memcpy_user or a memset_user */
  43. if (__frame->lr == (unsigned long) &__memset_user_error_lr &&
  44. (unsigned long) &memset <= pc && pc < (unsigned long) &__memset_end
  45. ) {
  46. /* the fault occurred in a protected memset
  47. * - we search for the return address (in LR) instead of the program counter
  48. * - it was probably during a clear_user()
  49. */
  50. return (unsigned long) &__memset_user_error_handler;
  51. }
  52. else if (__frame->lr == (unsigned long) &__memcpy_user_error_lr &&
  53. (unsigned long) &memcpy <= pc && pc < (unsigned long) &__memcpy_end
  54. ) {
  55. /* the fault occurred in a protected memset
  56. * - we search for the return address (in LR) instead of the program counter
  57. * - it was probably during a copy_to/from_user()
  58. */
  59. return (unsigned long) &__memcpy_user_error_handler;
  60. }
  61. #ifndef CONFIG_MODULES
  62. /* there is only the kernel to search. */
  63. ret = search_one_table(__start___ex_table, __stop___ex_table - 1, pc);
  64. return ret;
  65. #else
  66. /* the kernel is the last "module" -- no need to treat it special */
  67. unsigned long flags;
  68. struct module *mp;
  69. spin_lock_irqsave(&modlist_lock, flags);
  70. for (mp = module_list; mp != NULL; mp = mp->next) {
  71. if (mp->ex_table_start == NULL || !(mp->flags & (MOD_RUNNING | MOD_INITIALIZING)))
  72. continue;
  73. ret = search_one_table(mp->ex_table_start, mp->ex_table_end - 1, pc);
  74. if (ret)
  75. break;
  76. }
  77. spin_unlock_irqrestore(&modlist_lock, flags);
  78. return ret;
  79. #endif
  80. } /* end search_exception_table() */