extable.c 2.2 KB

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