blob: 2fb9b3ab57b9d624883fb5dd8d53944b12bb1556 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/frv/mm/extable.c
3 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/module.h>
6#include <linux/spinlock.h>
7#include <asm/uaccess.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009extern const void __memset_end, __memset_user_error_lr, __memset_user_error_handler;
10extern const void __memcpy_end, __memcpy_user_error_lr, __memcpy_user_error_handler;
11extern spinlock_t modlist_lock;
12
13/*****************************************************************************/
14/*
15 *
16 */
17static 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 */
41unsigned long search_exception_table(unsigned long pc)
42{
David Howells018b8d12006-01-08 01:01:19 -080043 const struct exception_table_entry *extab;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
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 }
David Howells018b8d12006-01-08 01:01:19 -080055
56 if (__frame->lr == (unsigned long) &__memcpy_user_error_lr &&
57 (unsigned long) &memcpy <= pc && pc < (unsigned long) &__memcpy_end
58 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /* 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
David Howells018b8d12006-01-08 01:01:19 -080066 extab = search_exception_tables(pc);
67 if (extab)
68 return extab->fixup;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howells018b8d12006-01-08 01:01:19 -080070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} /* end search_exception_table() */