extable.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. const struct exception_table_entry *extab;
  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. 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. extab = search_exception_tables(pc);
  62. if (extab)
  63. return extab->fixup;
  64. return 0;
  65. } /* end search_exception_table() */