This source file includes following definitions.
- check_exception_ranges
- cmp_ex_search
- search_extable
- fixup_exception
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/bsearch.h>
14 #include <linux/rwsem.h>
15 #include <linux/extable.h>
16 #include <linux/uaccess.h>
17
18 extern unsigned long copy_user_memcpy, copy_user_memcpy_end;
19 extern void __copy_user_fixup(void);
20
21 static const struct exception_table_entry __copy_user_fixup_ex = {
22 .fixup = (unsigned long)&__copy_user_fixup,
23 };
24
25
26
27
28
29
30
31
32
33
34
35 static const struct exception_table_entry *check_exception_ranges(unsigned long addr)
36 {
37 if ((addr >= (unsigned long)©_user_memcpy) &&
38 (addr <= (unsigned long)©_user_memcpy_end))
39 return &__copy_user_fixup_ex;
40
41 return NULL;
42 }
43
44 static int cmp_ex_search(const void *key, const void *elt)
45 {
46 const struct exception_table_entry *_elt = elt;
47 unsigned long _key = *(unsigned long *)key;
48
49
50 if (_key > _elt->insn)
51 return 1;
52 if (_key < _elt->insn)
53 return -1;
54 return 0;
55 }
56
57
58 const struct exception_table_entry *
59 search_extable(const struct exception_table_entry *base,
60 const size_t num,
61 unsigned long value)
62 {
63 const struct exception_table_entry *mid;
64
65 mid = check_exception_ranges(value);
66 if (mid)
67 return mid;
68
69 return bsearch(&value, base, num,
70 sizeof(struct exception_table_entry), cmp_ex_search);
71 }
72
73 int fixup_exception(struct pt_regs *regs)
74 {
75 const struct exception_table_entry *fixup;
76
77 fixup = search_exception_tables(regs->pc);
78 if (fixup) {
79 regs->pc = fixup->fixup;
80 return 1;
81 }
82
83 return 0;
84 }