1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/sparc/mm/extable.c
6 #include <linux/module.h>
7 #include <linux/extable.h>
8 #include <linux/uaccess.h>
10 void sort_extable(struct exception_table_entry
*start
,
11 struct exception_table_entry
*finish
)
15 /* Caller knows they are in a range if ret->fixup == 0 */
16 const struct exception_table_entry
*
17 search_extable(const struct exception_table_entry
*base
,
23 /* Single insn entries are encoded as:
24 * word 1: insn address
25 * word 2: fixup code address
27 * Range entries are encoded as:
28 * word 1: first insn address
30 * word 3: last insn address + 4 bytes
31 * word 4: fixup code address
33 * Deleted entries are encoded as:
37 * See asm/uaccess.h for more details.
40 /* 1. Try to find an exact match. */
41 for (i
= 0; i
< num
; i
++) {
42 if (base
[i
].fixup
== 0) {
43 /* A range entry, skip both parts. */
48 /* A deleted entry; see trim_init_extable */
49 if (base
[i
].fixup
== -1)
52 if (base
[i
].insn
== value
)
56 /* 2. Try to find a range match. */
57 for (i
= 0; i
< (num
- 1); i
++) {
61 if (base
[i
].insn
<= value
&& base
[i
+ 1].insn
> value
)
71 /* We could memmove them around; easier to mark the trimmed ones. */
72 void trim_init_extable(struct module
*m
)
77 for (i
= 0; i
< m
->num_exentries
; i
+= range
? 2 : 1) {
78 range
= m
->extable
[i
].fixup
== 0;
80 if (within_module_init(m
->extable
[i
].insn
, m
)) {
81 m
->extable
[i
].fixup
= -1;
83 m
->extable
[i
+1].fixup
= -1;
89 #endif /* CONFIG_MODULES */
91 /* Special extable search, which handles ranges. Returns fixup */
92 unsigned long search_extables_range(unsigned long addr
, unsigned long *g2
)
94 const struct exception_table_entry
*entry
;
96 entry
= search_exception_tables(addr
);
100 /* Inside range? Fix g2 and return correct fixup */
102 *g2
= (addr
- entry
->insn
) / 4;
103 return (entry
+ 1)->fixup
;