extable.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * linux/arch/frv/mm/extable.c
  3. */
  4. #include <linux/module.h>
  5. #include <linux/spinlock.h>
  6. #include <asm/uaccess.h>
  7. extern const void __memset_end, __memset_user_error_lr, __memset_user_error_handler;
  8. extern const void __memcpy_end, __memcpy_user_error_lr, __memcpy_user_error_handler;
  9. extern spinlock_t modlist_lock;
  10. /*****************************************************************************/
  11. /*
  12. *
  13. */
  14. static inline unsigned long search_one_table(const struct exception_table_entry *first,
  15. const struct exception_table_entry *last,
  16. unsigned long value)
  17. {
  18. while (first <= last) {
  19. const struct exception_table_entry __attribute__((aligned(8))) *mid;
  20. long diff;
  21. mid = (last - first) / 2 + first;
  22. diff = mid->insn - value;
  23. if (diff == 0)
  24. return mid->fixup;
  25. else if (diff < 0)
  26. first = mid + 1;
  27. else
  28. last = mid - 1;
  29. }
  30. return 0;
  31. } /* end search_one_table() */
  32. /*****************************************************************************/
  33. /*
  34. * see if there's a fixup handler available to deal with a kernel fault
  35. */
  36. unsigned long search_exception_table(unsigned long pc)
  37. {
  38. const struct exception_table_entry *extab;
  39. /* determine if the fault lay during a memcpy_user or a memset_user */
  40. if (__frame->lr == (unsigned long) &__memset_user_error_lr &&
  41. (unsigned long) &memset <= pc && pc < (unsigned long) &__memset_end
  42. ) {
  43. /* the fault occurred in a protected memset
  44. * - we search for the return address (in LR) instead of the program counter
  45. * - it was probably during a clear_user()
  46. */
  47. return (unsigned long) &__memset_user_error_handler;
  48. }
  49. if (__frame->lr == (unsigned long) &__memcpy_user_error_lr &&
  50. (unsigned long) &memcpy <= pc && pc < (unsigned long) &__memcpy_end
  51. ) {
  52. /* the fault occurred in a protected memset
  53. * - we search for the return address (in LR) instead of the program counter
  54. * - it was probably during a copy_to/from_user()
  55. */
  56. return (unsigned long) &__memcpy_user_error_handler;
  57. }
  58. extab = search_exception_tables(pc);
  59. if (extab)
  60. return extab->fixup;
  61. return 0;
  62. } /* end search_exception_table() */