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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  arch/s390/mm/extable.c
  3.  *
  4.  *  S390 version
  5.  *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6.  *    Author(s): Hartmut Penner (hp@de.ibm.com)
  7.  *
  8.  *  Derived from "arch/i386/mm/extable.c"
  9.  */
  10. #include <linux/config.h>
  11. #include <linux/module.h>
  12. #include <linux/spinlock.h>
  13. #include <asm/uaccess.h>
  14. extern const struct exception_table_entry __start___ex_table[];
  15. extern const struct exception_table_entry __stop___ex_table[];
  16. static inline unsigned long
  17. search_one_table(const struct exception_table_entry *first,
  18.  const struct exception_table_entry *last,
  19.  unsigned long value)
  20. {
  21.         while (first <= last) {
  22. const struct exception_table_entry *mid;
  23. long diff;
  24. mid = (last - first) / 2 + first;
  25. diff = mid->insn - value;
  26.                 if (diff == 0)
  27.                         return mid->fixup;
  28.                 else if (diff < 0)
  29.                         first = mid+1;
  30.                 else
  31.                         last = mid-1;
  32.         }
  33.         return 0;
  34. }
  35. extern spinlock_t modlist_lock;
  36. unsigned long
  37. search_exception_table(unsigned long addr)
  38. {
  39. unsigned long ret = 0;
  40. unsigned long flags;
  41. #ifndef CONFIG_MODULES
  42.         addr &= 0x7fffffff;  /* remove amode bit from address */
  43. /* There is only the kernel to search.  */
  44. ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
  45. if (ret) ret = FIX_PSW(ret);
  46. return ret;
  47. #else
  48. /* The kernel is the last "module" -- no need to treat it special.  */
  49. struct module *mp;
  50.         addr &= 0x7fffffff;  /* remove amode bit from address */
  51. spin_lock_irqsave(&modlist_lock, flags);
  52. for (mp = module_list; mp != NULL; mp = mp->next) {
  53. if (mp->ex_table_start == NULL || !(mp->flags&(MOD_RUNNING|MOD_INITIALIZING)))
  54. continue;
  55. ret = search_one_table(mp->ex_table_start,
  56.        mp->ex_table_end - 1, addr);
  57. if (ret) {
  58. ret = FIX_PSW(ret);
  59. break;
  60. }
  61. }
  62. spin_unlock_irqrestore(&modlist_lock, flags);
  63. return ret;
  64. #endif
  65. }