]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/sh/kernel/traps.c
3 #include <linux/types.h>
4 #include <linux/kdebug.h>
5 #include <linux/signal.h>
6 #include <linux/sched.h>
7 #include <linux/uaccess.h>
8 #include <linux/hardirq.h>
9 #include <linux/kernel.h>
10 #include <linux/kexec.h>
11 #include <linux/extable.h>
12 #include <linux/module.h> /* print_modules */
13 #include <asm/unwinder.h>
14 #include <asm/traps.h>
16 static DEFINE_SPINLOCK(die_lock
);
18 void die(const char *str
, struct pt_regs
*regs
, long err
)
20 static int die_counter
;
24 spin_lock_irq(&die_lock
);
28 printk("%s: %04lx [#%d]\n", str
, err
& 0xffff, ++die_counter
);
32 printk("Process: %s (pid: %d, stack limit = %p)\n", current
->comm
,
33 task_pid_nr(current
), task_stack_page(current
) + 1);
35 if (!user_mode(regs
) || in_interrupt())
36 dump_mem("Stack: ", regs
->regs
[15], THREAD_SIZE
+
37 (unsigned long)task_stack_page(current
));
39 notify_die(DIE_OOPS
, str
, regs
, err
, 255, SIGSEGV
);
42 add_taint(TAINT_DIE
, LOCKDEP_NOW_UNRELIABLE
);
43 spin_unlock_irq(&die_lock
);
46 if (kexec_should_crash(current
))
50 panic("Fatal exception in interrupt");
53 panic("Fatal exception");
58 void die_if_kernel(const char *str
, struct pt_regs
*regs
, long err
)
65 * try and fix up kernelspace address errors
66 * - userspace errors just cause EFAULT to be returned, resulting in SEGV
67 * - kernel/userspace interfaces cause a jump to an appropriate handler
68 * - other kernel errors are bad
70 void die_if_no_fixup(const char *str
, struct pt_regs
*regs
, long err
)
72 if (!user_mode(regs
)) {
73 const struct exception_table_entry
*fixup
;
74 fixup
= search_exception_tables(regs
->pc
);
76 regs
->pc
= fixup
->fixup
;
84 #ifdef CONFIG_GENERIC_BUG
85 static void handle_BUG(struct pt_regs
*regs
)
87 const struct bug_entry
*bug
;
88 unsigned long bugaddr
= regs
->pc
;
89 enum bug_trap_type tt
;
91 if (!is_valid_bugaddr(bugaddr
))
94 bug
= find_bug(bugaddr
);
96 /* Switch unwinders when unwind_stack() is called */
97 if (bug
->flags
& BUGFLAG_UNWINDER
)
100 tt
= report_bug(bugaddr
, regs
);
101 if (tt
== BUG_TRAP_TYPE_WARN
) {
102 regs
->pc
+= instruction_size(bugaddr
);
107 die("Kernel BUG", regs
, TRAPA_BUG_OPCODE
& 0xff);
110 int is_valid_bugaddr(unsigned long addr
)
114 if (addr
< PAGE_OFFSET
)
116 if (probe_kernel_address((insn_size_t
*)addr
, opcode
))
118 if (opcode
== TRAPA_BUG_OPCODE
)
126 * Generic trap handler.
128 BUILD_TRAP_HANDLER(debug
)
133 regs
->pc
-= instruction_size(__raw_readw(regs
->pc
- 4));
135 if (notify_die(DIE_TRAP
, "debug trap", regs
, 0, vec
& 0xff,
136 SIGTRAP
) == NOTIFY_STOP
)
139 force_sig(SIGTRAP
, current
);
143 * Special handler for BUG() traps.
145 BUILD_TRAP_HANDLER(bug
)
150 regs
->pc
-= instruction_size(__raw_readw(regs
->pc
- 4));
152 if (notify_die(DIE_TRAP
, "bug trap", regs
, 0, TRAPA_BUG_OPCODE
& 0xff,
153 SIGTRAP
) == NOTIFY_STOP
)
156 #ifdef CONFIG_GENERIC_BUG
157 if (__kernel_text_address(instruction_pointer(regs
))) {
158 insn_size_t insn
= *(insn_size_t
*)instruction_pointer(regs
);
159 if (insn
== TRAPA_BUG_OPCODE
)
165 force_sig(SIGTRAP
, current
);
168 BUILD_TRAP_HANDLER(nmi
)
170 unsigned int cpu
= smp_processor_id();
176 switch (notify_die(DIE_NMI
, "NMI", regs
, 0, vec
& 0xff, SIGINT
)) {
181 die("Fatal Non-Maskable Interrupt", regs
, SIGINT
);
183 printk(KERN_ALERT
"Got NMI, but nobody cared. Ignoring...\n");