extable.c 2.2 KB

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