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