Import 2.3.16
[davej-history.git] / arch / sh / mm / extable.c
blob35c4451ebcdfde67f9a92cbbedd8c7c25bf76fcf
1 /*
2 * linux/arch/sh/mm/extable.c
3 * Taken from:
4 * linux/arch/i386/mm/extable.c
5 */
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <asm/uaccess.h>
11 extern const struct exception_table_entry __start___ex_table[];
12 extern const struct exception_table_entry __stop___ex_table[];
14 static inline unsigned long
15 search_one_table(const struct exception_table_entry *first,
16 const struct exception_table_entry *last,
17 unsigned long value)
19 while (first <= last) {
20 const struct exception_table_entry *mid;
21 long diff;
23 mid = (last - first) / 2 + first;
24 diff = mid->insn - value;
25 if (diff == 0)
26 return mid->fixup;
27 else if (diff < 0)
28 first = mid+1;
29 else
30 last = mid-1;
32 return 0;
35 unsigned long
36 search_exception_table(unsigned long addr)
38 unsigned long ret;
40 #ifndef CONFIG_MODULES
41 /* There is only the kernel to search. */
42 ret = search_one_table(__start___ex_table, __stop___ex_table-1, addr);
43 if (ret) return ret;
44 #else
45 /* The kernel is the last "module" -- no need to treat it special. */
46 struct module *mp;
47 for (mp = module_list; mp != NULL; mp = mp->next) {
48 if (mp->ex_table_start == NULL)
49 continue;
50 ret = search_one_table(mp->ex_table_start,
51 mp->ex_table_end - 1, addr);
52 if (ret) return ret;
54 #endif
56 return 0;