extable.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * linux/arch/sparc/mm/extable.c
  3. */
  4. #include <linux/module.h>
  5. #include <asm/uaccess.h>
  6. void sort_extable(struct exception_table_entry *start,
  7. struct exception_table_entry *finish)
  8. {
  9. }
  10. /* Caller knows they are in a range if ret->fixup == 0 */
  11. const struct exception_table_entry *
  12. search_extable(const struct exception_table_entry *start,
  13. const struct exception_table_entry *last,
  14. unsigned long value)
  15. {
  16. const struct exception_table_entry *walk;
  17. /* Single insn entries are encoded as:
  18. * word 1: insn address
  19. * word 2: fixup code address
  20. *
  21. * Range entries are encoded as:
  22. * word 1: first insn address
  23. * word 2: 0
  24. * word 3: last insn address + 4 bytes
  25. * word 4: fixup code address
  26. *
  27. * Deleted entries are encoded as:
  28. * word 1: unused
  29. * word 2: -1
  30. *
  31. * See asm/uaccess.h for more details.
  32. */
  33. /* 1. Try to find an exact match. */
  34. for (walk = start; walk <= last; walk++) {
  35. if (walk->fixup == 0) {
  36. /* A range entry, skip both parts. */
  37. walk++;
  38. continue;
  39. }
  40. /* A deleted entry; see trim_init_extable */
  41. if (walk->fixup == -1)
  42. continue;
  43. if (walk->insn == value)
  44. return walk;
  45. }
  46. /* 2. Try to find a range match. */
  47. for (walk = start; walk <= (last - 1); walk++) {
  48. if (walk->fixup)
  49. continue;
  50. if (walk[0].insn <= value && walk[1].insn > value)
  51. return walk;
  52. walk++;
  53. }
  54. return NULL;
  55. }
  56. #ifdef CONFIG_MODULES
  57. /* We could memmove them around; easier to mark the trimmed ones. */
  58. void trim_init_extable(struct module *m)
  59. {
  60. unsigned int i;
  61. bool range;
  62. for (i = 0; i < m->num_exentries; i += range ? 2 : 1) {
  63. range = m->extable[i].fixup == 0;
  64. if (within_module_init(m->extable[i].insn, m)) {
  65. m->extable[i].fixup = -1;
  66. if (range)
  67. m->extable[i+1].fixup = -1;
  68. }
  69. if (range)
  70. i++;
  71. }
  72. }
  73. #endif /* CONFIG_MODULES */
  74. /* Special extable search, which handles ranges. Returns fixup */
  75. unsigned long search_extables_range(unsigned long addr, unsigned long *g2)
  76. {
  77. const struct exception_table_entry *entry;
  78. entry = search_exception_tables(addr);
  79. if (!entry)
  80. return 0;
  81. /* Inside range? Fix g2 and return correct fixup */
  82. if (!entry->fixup) {
  83. *g2 = (addr - entry->insn) / 4;
  84. return (entry + 1)->fixup;
  85. }
  86. return entry->fixup;
  87. }