File: /usr/src/linux/arch/sparc64/mm/extable.c

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