extable.c 2.2 KB

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