1 #include <linux/module.h>
2 #include <asm/uaccess.h>
5 typedef bool (*ex_handler_t)(const struct exception_table_entry *,
6 struct pt_regs *, int);
8 static inline unsigned long
9 ex_fixup_addr(const struct exception_table_entry *x)
11 return (unsigned long)&x->fixup + x->fixup;
13 static inline ex_handler_t
14 ex_fixup_handler(const struct exception_table_entry *x)
16 return (ex_handler_t)((unsigned long)&x->handler + x->handler);
19 bool ex_handler_default(const struct exception_table_entry *fixup,
20 struct pt_regs *regs, int trapnr)
22 regs->ip = ex_fixup_addr(fixup);
25 EXPORT_SYMBOL(ex_handler_default);
27 bool ex_handler_fault(const struct exception_table_entry *fixup,
28 struct pt_regs *regs, int trapnr)
30 regs->ip = ex_fixup_addr(fixup);
34 EXPORT_SYMBOL_GPL(ex_handler_fault);
36 bool ex_handler_ext(const struct exception_table_entry *fixup,
37 struct pt_regs *regs, int trapnr)
39 /* Special hack for uaccess_err */
40 current_thread_info()->uaccess_err = 1;
41 regs->ip = ex_fixup_addr(fixup);
44 EXPORT_SYMBOL(ex_handler_ext);
46 bool ex_has_fault_handler(unsigned long ip)
48 const struct exception_table_entry *e;
51 e = search_exception_tables(ip);
54 handler = ex_fixup_handler(e);
56 return handler == ex_handler_fault;
59 int fixup_exception(struct pt_regs *regs, int trapnr)
61 const struct exception_table_entry *e;
65 if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
66 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
67 extern u32 pnp_bios_is_utter_crap;
68 pnp_bios_is_utter_crap = 1;
69 printk(KERN_CRIT "PNPBIOS fault.. attempting recovery.\n");
73 : : "g" (pnp_bios_fault_esp), "g" (pnp_bios_fault_eip));
74 panic("do_trap: can't hit this");
78 e = search_exception_tables(regs->ip);
82 handler = ex_fixup_handler(e);
83 return handler(e, regs, trapnr);
86 extern unsigned int early_recursion_flag;
88 /* Restricted version used during very early boot */
89 void __init early_fixup_exception(struct pt_regs *regs, int trapnr)
91 const struct exception_table_entry *e;
95 /* Ignore early NMIs. */
96 if (trapnr == X86_TRAP_NMI)
99 if (early_recursion_flag > 2)
102 if (regs->cs != __KERNEL_CS)
105 e = search_exception_tables(regs->ip);
109 new_ip = ex_fixup_addr(e);
110 handler = ex_fixup_handler(e);
112 /* special handling not supported during early boot */
113 if (handler != ex_handler_default)
120 early_printk("PANIC: early exception 0x%02x IP %lx:%lx error %lx cr2 0x%lx\n",
121 (unsigned)trapnr, (unsigned long)regs->cs, regs->ip,
122 regs->orig_ax, read_cr2());