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