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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/m68k/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 long
  10. search_one_table(const struct exception_table_entry *first,
  11.  const struct exception_table_entry *last,
  12.  unsigned long value)
  13. {
  14.         while (first <= last) {
  15. const struct exception_table_entry *mid;
  16. long diff;
  17. mid = (last - first) / 2 + first;
  18. diff = value - mid->insn;
  19. if (diff >= 0 && diff <= 2)
  20. return mid->fixup;
  21. else if (diff > 0)
  22. first = mid+1;
  23. else
  24. last = mid-1;
  25. }
  26. return 0;
  27. }
  28. unsigned long
  29. search_exception_table(unsigned long addr)
  30. {
  31. unsigned long ret;
  32. #ifndef CONFIG_MODULES
  33. /* There is only the kernel to search.  */
  34. ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
  35. if (ret) return ret;
  36. #else
  37. /* The kernel is the last "module" -- no need to treat it special.  */
  38. struct module *mp;
  39. for (mp = module_list; mp != NULL; mp = mp->next) {
  40. if (mp->ex_table_start == NULL)
  41. continue;
  42. ret = search_one_table(mp->ex_table_start,
  43.        mp->ex_table_end-1, addr);
  44. if (ret) return ret;
  45. }
  46. #endif
  47. return 0;
  48. }