blob: caacf030ac753f438026d8c642458bba7c07518e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
10extern const struct exception_table_entry __attribute__((aligned(8))) __start___ex_table[];
11extern const struct exception_table_entry __attribute__((aligned(8))) __stop___ex_table[];
12extern const void __memset_end, __memset_user_error_lr, __memset_user_error_handler;
13extern const void __memcpy_end, __memcpy_user_error_lr, __memcpy_user_error_handler;
14extern spinlock_t modlist_lock;
15
16/*****************************************************************************/
17/*
18 *
19 */
20static 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 */
44unsigned long search_exception_table(unsigned long pc)
45{
David Howells018b8d12006-01-08 01:01:19 -080046 const struct exception_table_entry *extab;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
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 }
David Howells018b8d12006-01-08 01:01:19 -080058
59 if (__frame->lr == (unsigned long) &__memcpy_user_error_lr &&
60 (unsigned long) &memcpy <= pc && pc < (unsigned long) &__memcpy_end
61 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* 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
David Howells018b8d12006-01-08 01:01:19 -080069 extab = search_exception_tables(pc);
70 if (extab)
71 return extab->fixup;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
David Howells018b8d12006-01-08 01:01:19 -080073 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075} /* end search_exception_table() */