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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/mips/mm/extable.c
  3.  */
  4. #include <linux/config.h>
  5. #include <linux/module.h>
  6. #include <linux/spinlock.h>
  7. #include <asm/uaccess.h>
  8. extern const struct exception_table_entry __start___ex_table[];
  9. extern const struct exception_table_entry __stop___ex_table[];
  10. static inline unsigned long
  11. search_one_table(const struct exception_table_entry *first,
  12.                  const struct exception_table_entry *last,
  13.                  unsigned long value)
  14. {
  15. while (first <= last) {
  16. const struct exception_table_entry *mid;
  17. long diff;
  18. mid = (last - first) / 2 + first;
  19. diff = mid->insn - value;
  20. if (diff == 0)
  21. return mid->nextinsn;
  22. else if (diff < 0)
  23. first = mid+1;
  24. else
  25. last = mid-1;
  26. }
  27. return 0;
  28. }
  29. extern spinlock_t modlist_lock;
  30. unsigned long
  31. search_exception_table(unsigned long addr)
  32. {
  33. unsigned long ret = 0;
  34. #ifndef CONFIG_MODULES
  35. /* There is only the kernel to search.  */
  36. ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
  37. return ret;
  38. #else
  39. unsigned long flags;
  40. /* The kernel is the last "module" -- no need to treat it special.  */
  41. struct module *mp;
  42. spin_lock_irqsave(&modlist_lock, flags);
  43. for (mp = module_list; mp != NULL; mp = mp->next) {
  44. if (mp->ex_table_start == NULL || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
  45. continue;
  46. ret = search_one_table(mp->ex_table_start,
  47.        mp->ex_table_end - 1, addr);
  48. if (ret)
  49. break;
  50. }
  51. spin_unlock_irqrestore(&modlist_lock, flags);
  52. return ret;
  53. #endif
  54. }