Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[firefly-linux-kernel-4.4.55.git] / arch / frv / mm / extable.c
1 /*
2  * linux/arch/frv/mm/extable.c
3  */
4
5 #include <linux/module.h>
6 #include <linux/spinlock.h>
7 #include <asm/uaccess.h>
8
9 extern const void __memset_end, __memset_user_error_lr, __memset_user_error_handler;
10 extern const void __memcpy_end, __memcpy_user_error_lr, __memcpy_user_error_handler;
11 extern spinlock_t modlist_lock;
12
13 /*****************************************************************************/
14 /*
15  *
16  */
17 static inline unsigned long 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 __attribute__((aligned(8))) *mid;
23                 long diff;
24
25                 mid = (last - first) / 2 + first;
26                 diff = mid->insn - value;
27                 if (diff == 0)
28                         return mid->fixup;
29                 else if (diff < 0)
30                         first = mid + 1;
31                 else
32                         last = mid - 1;
33         }
34         return 0;
35 } /* end search_one_table() */
36
37 /*****************************************************************************/
38 /*
39  * see if there's a fixup handler available to deal with a kernel fault
40  */
41 unsigned long search_exception_table(unsigned long pc)
42 {
43         const struct exception_table_entry *extab;
44
45         /* determine if the fault lay during a memcpy_user or a memset_user */
46         if (__frame->lr == (unsigned long) &__memset_user_error_lr &&
47             (unsigned long) &memset <= pc && pc < (unsigned long) &__memset_end
48             ) {
49                 /* the fault occurred in a protected memset
50                  * - we search for the return address (in LR) instead of the program counter
51                  * - it was probably during a clear_user()
52                  */
53                 return (unsigned long) &__memset_user_error_handler;
54         }
55
56         if (__frame->lr == (unsigned long) &__memcpy_user_error_lr &&
57             (unsigned long) &memcpy <= pc && pc < (unsigned long) &__memcpy_end
58             ) {
59                 /* the fault occurred in a protected memset
60                  * - we search for the return address (in LR) instead of the program counter
61                  * - it was probably during a copy_to/from_user()
62                  */
63                 return (unsigned long) &__memcpy_user_error_handler;
64         }
65
66         extab = search_exception_tables(pc);
67         if (extab)
68                 return extab->fixup;
69
70         return 0;
71
72 } /* end search_exception_table() */