extable.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/alpha/mm/extable.c
  3.  */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <asm/uaccess.h>
  7. extern const struct exception_table_entry __start___ex_table[];
  8. extern const struct exception_table_entry __stop___ex_table[];
  9. static inline unsigned
  10. search_one_table(const struct exception_table_entry *first,
  11.  const struct exception_table_entry *last,
  12.  signed long value)
  13. {
  14. /* Abort early if the search value is out of range.  */
  15. if (value != (signed int)value)
  16. return 0;
  17.         while (first <= last) {
  18. const struct exception_table_entry *mid;
  19. long diff;
  20. mid = (last - first) / 2 + first;
  21. diff = mid->insn - value;
  22.                 if (diff == 0)
  23.                         return mid->fixup.unit;
  24.                 else if (diff < 0)
  25.                         first = mid+1;
  26.                 else
  27.                         last = mid-1;
  28.         }
  29.         return 0;
  30. }
  31. register unsigned long gp __asm__("$29");
  32. static unsigned
  33. search_exception_table_without_gp(unsigned long addr)
  34. {
  35. unsigned ret;
  36. #ifndef CONFIG_MODULES
  37. /* There is only the kernel to search.  */
  38. ret = search_one_table(__start___ex_table, __stop___ex_table - 1,
  39.        addr - gp);
  40. #else
  41. extern spinlock_t modlist_lock;
  42. unsigned long flags;
  43. /* The kernel is the last "module" -- no need to treat it special. */
  44. struct module *mp;
  45. ret = 0;
  46. spin_lock_irqsave(&modlist_lock, flags);
  47. for (mp = module_list; mp ; mp = mp->next) {
  48. if (!mp->ex_table_start || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
  49. continue;
  50. ret = search_one_table(mp->ex_table_start,
  51.        mp->ex_table_end - 1, addr - mp->gp);
  52. if (ret)
  53. break;
  54. }
  55. spin_unlock_irqrestore(&modlist_lock, flags);
  56. #endif
  57. return ret;
  58. }
  59. unsigned
  60. search_exception_table(unsigned long addr, unsigned long exc_gp)
  61. {
  62. unsigned ret;
  63. #ifndef CONFIG_MODULES
  64. ret = search_one_table(__start___ex_table, __stop___ex_table - 1,
  65.        addr - exc_gp);
  66. if (ret) return ret;
  67. #else
  68. extern spinlock_t modlist_lock;
  69. unsigned long flags;
  70. /* The kernel is the last "module" -- no need to treat it special. */
  71. struct module *mp;
  72. ret = 0;
  73. spin_lock_irqsave(&modlist_lock, flags);
  74. for (mp = module_list; mp ; mp = mp->next) {
  75. if (!mp->ex_table_start || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
  76. continue;
  77. ret = search_one_table(mp->ex_table_start,
  78.        mp->ex_table_end - 1, addr - exc_gp);
  79. if (ret)
  80. break;
  81. }
  82. spin_unlock_irqrestore(&modlist_lock, flags);
  83. if (ret) return ret;
  84. #endif
  85. /*
  86.  * The search failed with the exception gp. To be safe, try the
  87.  * old method before giving up.
  88.  */
  89. ret = search_exception_table_without_gp(addr);
  90. if (ret) {
  91. printk(KERN_ALERT "%s: [%lx] EX_TABLE search fail with"
  92.        "exc frame GP, success with raw GPn",
  93.        current->comm, addr);
  94. return ret;
  95. }
  96. return 0;
  97. }