This source file includes following definitions.
- trap_init
- die
- unhandled_exception
- DO_ERROR_INFO
- do_machine_check_fault
- do_non_swi_trap
- do_insterror_or_kprobe
- abort
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/sched/signal.h>
14 #include <linux/kdebug.h>
15 #include <linux/uaccess.h>
16 #include <linux/ptrace.h>
17 #include <linux/kprobes.h>
18 #include <linux/kgdb.h>
19 #include <asm/setup.h>
20 #include <asm/unaligned.h>
21 #include <asm/kprobes.h>
22
23 void __init trap_init(void)
24 {
25 return;
26 }
27
28 void die(const char *str, struct pt_regs *regs, unsigned long address)
29 {
30 show_kernel_fault_diag(str, regs, address);
31
32
33 __asm__("flag 1");
34 }
35
36
37
38
39
40
41 static noinline int
42 unhandled_exception(const char *str, struct pt_regs *regs,
43 int signo, int si_code, void __user *addr)
44 {
45 if (user_mode(regs)) {
46 struct task_struct *tsk = current;
47
48 tsk->thread.fault_address = (__force unsigned int)addr;
49
50 force_sig_fault(signo, si_code, addr);
51
52 } else {
53
54 if (fixup_exception(regs))
55 return 0;
56
57 die(str, regs, (unsigned long)addr);
58 }
59
60 return 1;
61 }
62
63 #define DO_ERROR_INFO(signr, str, name, sicode) \
64 int name(unsigned long address, struct pt_regs *regs) \
65 { \
66 return unhandled_exception(str, regs, signr, sicode, \
67 (void __user *)address); \
68 }
69
70
71
72
73 DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
74 DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
75 DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
76 DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", __weak do_memory_error, BUS_ADRERR)
77 DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
78 DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
79 DO_ERROR_INFO(SIGSEGV, "gcc generated __builtin_trap", do_trap5_error, 0)
80
81
82
83
84 int do_misaligned_access(unsigned long address, struct pt_regs *regs,
85 struct callee_regs *cregs)
86 {
87
88 if (misaligned_fixup(address, regs, cregs) != 0)
89 return do_misaligned_error(address, regs);
90
91 return 0;
92 }
93
94
95
96
97
98 void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
99 {
100 die("Unhandled Machine Check Exception", regs, address);
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115 void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
116 {
117 unsigned int param = regs->ecr_param;
118
119 switch (param) {
120 case 1:
121 trap_is_brkpt(address, regs);
122 break;
123
124 case 2:
125 trap_is_kprobe(address, regs);
126 break;
127
128 case 3:
129 case 4:
130 kgdb_trap(regs);
131 break;
132
133 case 5:
134 do_trap5_error(address, regs);
135 break;
136 default:
137 break;
138 }
139 }
140
141
142
143
144
145
146 void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
147 {
148 int rc;
149
150
151 rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL);
152 if (rc == NOTIFY_STOP)
153 return;
154
155 insterror_is_error(address, regs);
156 }
157
158
159
160
161 void abort(void)
162 {
163 __asm__ __volatile__("trap_s 5\n");
164 }