blob: a2e6e05637729298d7ed2b04d16d6cca135a38b8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * arch/sh64/mm/extable.c
7 *
8 * Copyright (C) 2003 Richard Curnow
9 * Copyright (C) 2003, 2004 Paul Mundt
10 *
11 * Cloned from the 2.5 SH version..
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/rwsem.h>
14#include <linux/module.h>
15#include <asm/uaccess.h>
16
17extern unsigned long copy_user_memcpy, copy_user_memcpy_end;
18extern void __copy_user_fixup(void);
19
20static const struct exception_table_entry __copy_user_fixup_ex = {
21 .fixup = (unsigned long)&__copy_user_fixup,
22};
23
24/* Some functions that may trap due to a bad user-mode address have too many loads
25 and stores in them to make it at all practical to label each one and put them all in
26 the main exception table.
27
28 In particular, the fast memcpy routine is like this. It's fix-up is just to fall back
29 to a slow byte-at-a-time copy, which is handled the conventional way. So it's functionally
30 OK to just handle any trap occurring in the fast memcpy with that fixup. */
31static const struct exception_table_entry *check_exception_ranges(unsigned long addr)
32{
33 if ((addr >= (unsigned long)&copy_user_memcpy) &&
34 (addr <= (unsigned long)&copy_user_memcpy_end))
35 return &__copy_user_fixup_ex;
36
37 return NULL;
38}
39
40/* Simple binary search */
41const struct exception_table_entry *
42search_extable(const struct exception_table_entry *first,
43 const struct exception_table_entry *last,
44 unsigned long value)
45{
46 const struct exception_table_entry *mid;
47
48 mid = check_exception_ranges(value);
49 if (mid)
50 return mid;
51
52 while (first <= last) {
53 long diff;
54
55 mid = (last - first) / 2 + first;
56 diff = mid->insn - value;
57 if (diff == 0)
58 return mid;
59 else if (diff < 0)
60 first = mid+1;
61 else
62 last = mid-1;
63 }
64
65 return NULL;
66}
67
68int fixup_exception(struct pt_regs *regs)
69{
70 const struct exception_table_entry *fixup;
71
72 fixup = search_exception_tables(regs->pc);
73 if (fixup) {
74 regs->pc = fixup->fixup;
75 return 1;
76 }
77
78 return 0;
79}
80