Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 1991, 1992 Linus Torvalds |
3 | * | |
4 | * Pentium III FXSR, SSE support | |
5 | * Gareth Hughes <gareth@valinux.com>, May 2000 | |
6 | */ | |
7 | ||
8 | /* | |
9 | * 'Traps.c' handles hardware traps and faults after we have saved some | |
10 | * state in 'asm.s'. | |
11 | */ | |
1da177e4 LT |
12 | #include <linux/sched.h> |
13 | #include <linux/kernel.h> | |
14 | #include <linux/string.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/timer.h> | |
17 | #include <linux/mm.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/delay.h> | |
20 | #include <linux/spinlock.h> | |
21 | #include <linux/interrupt.h> | |
22 | #include <linux/highmem.h> | |
23 | #include <linux/kallsyms.h> | |
24 | #include <linux/ptrace.h> | |
25 | #include <linux/utsname.h> | |
26 | #include <linux/kprobes.h> | |
6e274d14 | 27 | #include <linux/kexec.h> |
176a2718 | 28 | #include <linux/unwind.h> |
1e2af92e | 29 | #include <linux/uaccess.h> |
a36df98a | 30 | #include <linux/nmi.h> |
91768d6c | 31 | #include <linux/bug.h> |
1da177e4 LT |
32 | |
33 | #ifdef CONFIG_EISA | |
34 | #include <linux/ioport.h> | |
35 | #include <linux/eisa.h> | |
36 | #endif | |
37 | ||
38 | #ifdef CONFIG_MCA | |
39 | #include <linux/mca.h> | |
40 | #endif | |
41 | ||
c0d12172 DJ |
42 | #if defined(CONFIG_EDAC) |
43 | #include <linux/edac.h> | |
44 | #endif | |
45 | ||
1da177e4 LT |
46 | #include <asm/processor.h> |
47 | #include <asm/system.h> | |
1da177e4 LT |
48 | #include <asm/io.h> |
49 | #include <asm/atomic.h> | |
50 | #include <asm/debugreg.h> | |
51 | #include <asm/desc.h> | |
52 | #include <asm/i387.h> | |
53 | #include <asm/nmi.h> | |
176a2718 | 54 | #include <asm/unwind.h> |
1da177e4 LT |
55 | #include <asm/smp.h> |
56 | #include <asm/arch_hooks.h> | |
1eeb66a1 | 57 | #include <linux/kdebug.h> |
2b14a78c | 58 | #include <asm/stacktrace.h> |
1da177e4 | 59 | |
1da177e4 LT |
60 | #include <linux/module.h> |
61 | ||
62 | #include "mach_traps.h" | |
63 | ||
29cbc78b AK |
64 | int panic_on_unrecovered_nmi; |
65 | ||
1da177e4 LT |
66 | asmlinkage int system_call(void); |
67 | ||
1da177e4 LT |
68 | /* Do we ignore FPU interrupts ? */ |
69 | char ignore_fpu_irq = 0; | |
70 | ||
71 | /* | |
72 | * The IDT has to be page-aligned to simplify the Pentium | |
73 | * F0 0F bug workaround.. We have a special link segment | |
74 | * for this. | |
75 | */ | |
76 | struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, }; | |
77 | ||
78 | asmlinkage void divide_error(void); | |
79 | asmlinkage void debug(void); | |
80 | asmlinkage void nmi(void); | |
81 | asmlinkage void int3(void); | |
82 | asmlinkage void overflow(void); | |
83 | asmlinkage void bounds(void); | |
84 | asmlinkage void invalid_op(void); | |
85 | asmlinkage void device_not_available(void); | |
86 | asmlinkage void coprocessor_segment_overrun(void); | |
87 | asmlinkage void invalid_TSS(void); | |
88 | asmlinkage void segment_not_present(void); | |
89 | asmlinkage void stack_segment(void); | |
90 | asmlinkage void general_protection(void); | |
91 | asmlinkage void page_fault(void); | |
92 | asmlinkage void coprocessor_error(void); | |
93 | asmlinkage void simd_coprocessor_error(void); | |
94 | asmlinkage void alignment_check(void); | |
95 | asmlinkage void spurious_interrupt_bug(void); | |
96 | asmlinkage void machine_check(void); | |
97 | ||
0741f4d2 | 98 | int kstack_depth_to_print = 24; |
86c41837 | 99 | static unsigned int code_bytes = 64; |
e041c683 | 100 | |
36ad4885 | 101 | static inline int valid_stack_ptr(struct thread_info *tinfo, void *p, unsigned size) |
1da177e4 LT |
102 | { |
103 | return p > (void *)tinfo && | |
36ad4885 | 104 | p <= (void *)tinfo + THREAD_SIZE - size; |
1da177e4 LT |
105 | } |
106 | ||
36ad4885 LT |
107 | /* The form of the top of the frame on the stack */ |
108 | struct stack_frame { | |
109 | struct stack_frame *next_frame; | |
110 | unsigned long return_address; | |
111 | }; | |
112 | ||
1da177e4 | 113 | static inline unsigned long print_context_stack(struct thread_info *tinfo, |
7aa89746 | 114 | unsigned long *stack, unsigned long ebp, |
9689ba8a | 115 | const struct stacktrace_ops *ops, void *data) |
1da177e4 | 116 | { |
1da177e4 | 117 | #ifdef CONFIG_FRAME_POINTER |
36ad4885 LT |
118 | struct stack_frame *frame = (struct stack_frame *)ebp; |
119 | while (valid_stack_ptr(tinfo, frame, sizeof(*frame))) { | |
120 | struct stack_frame *next; | |
121 | unsigned long addr; | |
122 | ||
123 | addr = frame->return_address; | |
2b14a78c | 124 | ops->address(data, addr); |
b88d4f1d IM |
125 | /* |
126 | * break out of recursive entries (such as | |
808dbbb6 LT |
127 | * end_of_stack_stop_unwind_function). Also, |
128 | * we can never allow a frame pointer to | |
129 | * move downwards! | |
36ad4885 LT |
130 | */ |
131 | next = frame->next_frame; | |
132 | if (next <= frame) | |
b88d4f1d | 133 | break; |
36ad4885 | 134 | frame = next; |
1da177e4 LT |
135 | } |
136 | #else | |
36ad4885 LT |
137 | while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) { |
138 | unsigned long addr; | |
139 | ||
1da177e4 | 140 | addr = *stack++; |
7aa89746 | 141 | if (__kernel_text_address(addr)) |
2b14a78c | 142 | ops->address(data, addr); |
1da177e4 LT |
143 | } |
144 | #endif | |
145 | return ebp; | |
146 | } | |
147 | ||
b615ebda AK |
148 | #define MSG(msg) ops->warning(data, msg) |
149 | ||
2b14a78c AK |
150 | void dump_trace(struct task_struct *task, struct pt_regs *regs, |
151 | unsigned long *stack, | |
9689ba8a | 152 | const struct stacktrace_ops *ops, void *data) |
1da177e4 | 153 | { |
a32cf397 | 154 | unsigned long ebp = 0; |
1da177e4 LT |
155 | |
156 | if (!task) | |
157 | task = current; | |
158 | ||
a32cf397 | 159 | if (!stack) { |
2b14a78c AK |
160 | unsigned long dummy; |
161 | stack = &dummy; | |
028a690a | 162 | if (task != current) |
2b14a78c | 163 | stack = (unsigned long *)task->thread.esp; |
176a2718 JB |
164 | } |
165 | ||
a32cf397 AK |
166 | #ifdef CONFIG_FRAME_POINTER |
167 | if (!ebp) { | |
168 | if (task == current) { | |
169 | /* Grab ebp right from our regs */ | |
170 | asm ("movl %%ebp, %0" : "=r" (ebp) : ); | |
171 | } else { | |
172 | /* ebp is the last reg pushed by switch_to */ | |
173 | ebp = *(unsigned long *) task->thread.esp; | |
174 | } | |
1da177e4 | 175 | } |
a32cf397 | 176 | #endif |
1da177e4 LT |
177 | |
178 | while (1) { | |
179 | struct thread_info *context; | |
180 | context = (struct thread_info *) | |
181 | ((unsigned long)stack & (~(THREAD_SIZE - 1))); | |
2b14a78c AK |
182 | ebp = print_context_stack(context, stack, ebp, ops, data); |
183 | /* Should be after the line below, but somewhere | |
184 | in early boot context comes out corrupted and we | |
185 | can't reference it -AK */ | |
186 | if (ops->stack(data, "IRQ") < 0) | |
187 | break; | |
1da177e4 LT |
188 | stack = (unsigned long*)context->previous_esp; |
189 | if (!stack) | |
190 | break; | |
a36df98a | 191 | touch_nmi_watchdog(); |
1da177e4 LT |
192 | } |
193 | } | |
2b14a78c AK |
194 | EXPORT_SYMBOL(dump_trace); |
195 | ||
196 | static void | |
197 | print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) | |
198 | { | |
199 | printk(data); | |
200 | print_symbol(msg, symbol); | |
201 | printk("\n"); | |
202 | } | |
203 | ||
204 | static void print_trace_warning(void *data, char *msg) | |
205 | { | |
206 | printk("%s%s\n", (char *)data, msg); | |
207 | } | |
208 | ||
209 | static int print_trace_stack(void *data, char *name) | |
210 | { | |
211 | return 0; | |
212 | } | |
213 | ||
214 | /* | |
215 | * Print one address/symbol entries per line. | |
216 | */ | |
217 | static void print_trace_address(void *data, unsigned long addr) | |
218 | { | |
219 | printk("%s [<%08lx>] ", (char *)data, addr); | |
220 | print_symbol("%s\n", addr); | |
601e6255 | 221 | touch_nmi_watchdog(); |
2b14a78c AK |
222 | } |
223 | ||
9689ba8a | 224 | static const struct stacktrace_ops print_trace_ops = { |
2b14a78c AK |
225 | .warning = print_trace_warning, |
226 | .warning_symbol = print_trace_warning_symbol, | |
227 | .stack = print_trace_stack, | |
228 | .address = print_trace_address, | |
229 | }; | |
230 | ||
231 | static void | |
232 | show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, | |
233 | unsigned long * stack, char *log_lvl) | |
234 | { | |
235 | dump_trace(task, regs, stack, &print_trace_ops, log_lvl); | |
236 | printk("%s =======================\n", log_lvl); | |
237 | } | |
1da177e4 | 238 | |
2b14a78c AK |
239 | void show_trace(struct task_struct *task, struct pt_regs *regs, |
240 | unsigned long * stack) | |
7aa89746 | 241 | { |
176a2718 | 242 | show_trace_log_lvl(task, regs, stack, ""); |
7aa89746 CE |
243 | } |
244 | ||
176a2718 JB |
245 | static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs, |
246 | unsigned long *esp, char *log_lvl) | |
1da177e4 LT |
247 | { |
248 | unsigned long *stack; | |
249 | int i; | |
250 | ||
251 | if (esp == NULL) { | |
252 | if (task) | |
253 | esp = (unsigned long*)task->thread.esp; | |
254 | else | |
255 | esp = (unsigned long *)&esp; | |
256 | } | |
257 | ||
258 | stack = esp; | |
259 | for(i = 0; i < kstack_depth_to_print; i++) { | |
260 | if (kstack_end(stack)) | |
261 | break; | |
75874d5c CE |
262 | if (i && ((i % 8) == 0)) |
263 | printk("\n%s ", log_lvl); | |
1da177e4 LT |
264 | printk("%08lx ", *stack++); |
265 | } | |
75874d5c | 266 | printk("\n%sCall Trace:\n", log_lvl); |
176a2718 | 267 | show_trace_log_lvl(task, regs, esp, log_lvl); |
7aa89746 CE |
268 | } |
269 | ||
270 | void show_stack(struct task_struct *task, unsigned long *esp) | |
271 | { | |
75874d5c | 272 | printk(" "); |
176a2718 | 273 | show_stack_log_lvl(task, NULL, esp, ""); |
1da177e4 LT |
274 | } |
275 | ||
276 | /* | |
277 | * The architecture-independent dump_stack generator | |
278 | */ | |
279 | void dump_stack(void) | |
280 | { | |
281 | unsigned long stack; | |
282 | ||
176a2718 | 283 | show_trace(current, NULL, &stack); |
1da177e4 LT |
284 | } |
285 | ||
286 | EXPORT_SYMBOL(dump_stack); | |
287 | ||
288 | void show_registers(struct pt_regs *regs) | |
289 | { | |
290 | int i; | |
291 | int in_kernel = 1; | |
292 | unsigned long esp; | |
464d1a78 | 293 | unsigned short ss, gs; |
1da177e4 LT |
294 | |
295 | esp = (unsigned long) (®s->esp); | |
0998e422 | 296 | savesegment(ss, ss); |
464d1a78 | 297 | savesegment(gs, gs); |
db753bdf | 298 | if (user_mode_vm(regs)) { |
1da177e4 LT |
299 | in_kernel = 0; |
300 | esp = regs->esp; | |
301 | ss = regs->xss & 0xffff; | |
302 | } | |
303 | print_modules(); | |
f354b3a9 DJ |
304 | printk(KERN_EMERG "CPU: %d\n" |
305 | KERN_EMERG "EIP: %04x:[<%08lx>] %s VLI\n" | |
306 | KERN_EMERG "EFLAGS: %08lx (%s %.*s)\n", | |
1da177e4 | 307 | smp_processor_id(), 0xffff & regs->xcs, regs->eip, |
96b644bd SH |
308 | print_tainted(), regs->eflags, init_utsname()->release, |
309 | (int)strcspn(init_utsname()->version, " "), | |
310 | init_utsname()->version); | |
9c107805 DJ |
311 | print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip); |
312 | printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", | |
1da177e4 | 313 | regs->eax, regs->ebx, regs->ecx, regs->edx); |
9c107805 | 314 | printk(KERN_EMERG "esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", |
1da177e4 | 315 | regs->esi, regs->edi, regs->ebp, esp); |
464d1a78 JF |
316 | printk(KERN_EMERG "ds: %04x es: %04x fs: %04x gs: %04x ss: %04x\n", |
317 | regs->xds & 0xffff, regs->xes & 0xffff, regs->xfs & 0xffff, gs, ss); | |
7e04a118 CE |
318 | printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)", |
319 | TASK_COMM_LEN, current->comm, current->pid, | |
c9f4f06d | 320 | current_thread_info(), current, task_thread_info(current)); |
1da177e4 LT |
321 | /* |
322 | * When in-kernel, we also print out the stack and code at the | |
323 | * time of the fault.. | |
324 | */ | |
325 | if (in_kernel) { | |
11a4180c | 326 | u8 *eip; |
86c41837 CE |
327 | unsigned int code_prologue = code_bytes * 43 / 64; |
328 | unsigned int code_len = code_bytes; | |
99325326 | 329 | unsigned char c; |
1da177e4 | 330 | |
9c107805 | 331 | printk("\n" KERN_EMERG "Stack: "); |
176a2718 | 332 | show_stack_log_lvl(NULL, regs, (unsigned long *)esp, KERN_EMERG); |
1da177e4 | 333 | |
9c107805 | 334 | printk(KERN_EMERG "Code: "); |
1da177e4 | 335 | |
86c41837 | 336 | eip = (u8 *)regs->eip - code_prologue; |
11a4180c AK |
337 | if (eip < (u8 *)PAGE_OFFSET || |
338 | probe_kernel_address(eip, c)) { | |
99325326 | 339 | /* try starting at EIP */ |
11a4180c | 340 | eip = (u8 *)regs->eip; |
86c41837 | 341 | code_len = code_len - code_prologue + 1; |
99325326 | 342 | } |
86c41837 | 343 | for (i = 0; i < code_len; i++, eip++) { |
11a4180c AK |
344 | if (eip < (u8 *)PAGE_OFFSET || |
345 | probe_kernel_address(eip, c)) { | |
1da177e4 LT |
346 | printk(" Bad EIP value."); |
347 | break; | |
348 | } | |
11a4180c | 349 | if (eip == (u8 *)regs->eip) |
1da177e4 LT |
350 | printk("<%02x> ", c); |
351 | else | |
352 | printk("%02x ", c); | |
353 | } | |
354 | } | |
355 | printk("\n"); | |
356 | } | |
357 | ||
91768d6c | 358 | int is_valid_bugaddr(unsigned long eip) |
1da177e4 LT |
359 | { |
360 | unsigned short ud2; | |
1da177e4 LT |
361 | |
362 | if (eip < PAGE_OFFSET) | |
91768d6c | 363 | return 0; |
11a4180c | 364 | if (probe_kernel_address((unsigned short *)eip, ud2)) |
91768d6c | 365 | return 0; |
1da177e4 | 366 | |
91768d6c | 367 | return ud2 == 0x0b0f; |
1da177e4 LT |
368 | } |
369 | ||
91768d6c JF |
370 | /* |
371 | * This is gone through when something in the kernel has done something bad and | |
372 | * is about to be terminated. | |
373 | */ | |
1da177e4 LT |
374 | void die(const char * str, struct pt_regs * regs, long err) |
375 | { | |
376 | static struct { | |
377 | spinlock_t lock; | |
378 | u32 lock_owner; | |
379 | int lock_owner_depth; | |
380 | } die = { | |
6cfd76a2 | 381 | .lock = __SPIN_LOCK_UNLOCKED(die.lock), |
1da177e4 LT |
382 | .lock_owner = -1, |
383 | .lock_owner_depth = 0 | |
384 | }; | |
385 | static int die_counter; | |
e43d674f | 386 | unsigned long flags; |
1da177e4 | 387 | |
dd287796 AM |
388 | oops_enter(); |
389 | ||
39c715b7 | 390 | if (die.lock_owner != raw_smp_processor_id()) { |
1da177e4 | 391 | console_verbose(); |
e43d674f | 392 | spin_lock_irqsave(&die.lock, flags); |
1da177e4 LT |
393 | die.lock_owner = smp_processor_id(); |
394 | die.lock_owner_depth = 0; | |
395 | bust_spinlocks(1); | |
396 | } | |
e43d674f JB |
397 | else |
398 | local_save_flags(flags); | |
1da177e4 LT |
399 | |
400 | if (++die.lock_owner_depth < 3) { | |
7bee5c0f RD |
401 | unsigned long esp; |
402 | unsigned short ss; | |
403 | ||
608e2619 | 404 | report_bug(regs->eip, regs); |
91768d6c | 405 | |
9aa8d719 PE |
406 | printk(KERN_EMERG "%s: %04lx [#%d] ", str, err & 0xffff, |
407 | ++die_counter); | |
1da177e4 | 408 | #ifdef CONFIG_PREEMPT |
9aa8d719 | 409 | printk("PREEMPT "); |
1da177e4 LT |
410 | #endif |
411 | #ifdef CONFIG_SMP | |
412 | printk("SMP "); | |
1da177e4 LT |
413 | #endif |
414 | #ifdef CONFIG_DEBUG_PAGEALLOC | |
415 | printk("DEBUG_PAGEALLOC"); | |
1da177e4 | 416 | #endif |
9aa8d719 PE |
417 | printk("\n"); |
418 | ||
20c0d2d4 JB |
419 | if (notify_die(DIE_OOPS, str, regs, err, |
420 | current->thread.trap_no, SIGSEGV) != | |
7bee5c0f | 421 | NOTIFY_STOP) { |
20c0d2d4 | 422 | show_registers(regs); |
7bee5c0f RD |
423 | /* Executive summary in case the oops scrolled away */ |
424 | esp = (unsigned long) (®s->esp); | |
425 | savesegment(ss, ss); | |
426 | if (user_mode(regs)) { | |
427 | esp = regs->esp; | |
428 | ss = regs->xss & 0xffff; | |
429 | } | |
430 | printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip); | |
431 | print_symbol("%s", regs->eip); | |
432 | printk(" SS:ESP %04x:%08lx\n", ss, esp); | |
433 | } | |
20c0d2d4 JB |
434 | else |
435 | regs = NULL; | |
1da177e4 | 436 | } else |
9c107805 | 437 | printk(KERN_EMERG "Recursive die() failure, output suppressed\n"); |
1da177e4 LT |
438 | |
439 | bust_spinlocks(0); | |
440 | die.lock_owner = -1; | |
bcdcd8e7 | 441 | add_taint(TAINT_DIE); |
e43d674f | 442 | spin_unlock_irqrestore(&die.lock, flags); |
6e274d14 | 443 | |
20c0d2d4 JB |
444 | if (!regs) |
445 | return; | |
446 | ||
6e274d14 AN |
447 | if (kexec_should_crash(current)) |
448 | crash_kexec(regs); | |
449 | ||
1da177e4 LT |
450 | if (in_interrupt()) |
451 | panic("Fatal exception in interrupt"); | |
452 | ||
cea6a4ba | 453 | if (panic_on_oops) |
012c437d | 454 | panic("Fatal exception"); |
cea6a4ba | 455 | |
dd287796 | 456 | oops_exit(); |
1da177e4 LT |
457 | do_exit(SIGSEGV); |
458 | } | |
459 | ||
460 | static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err) | |
461 | { | |
717b594a | 462 | if (!user_mode_vm(regs)) |
1da177e4 LT |
463 | die(str, regs, err); |
464 | } | |
465 | ||
3d97ae5b PP |
466 | static void __kprobes do_trap(int trapnr, int signr, char *str, int vm86, |
467 | struct pt_regs * regs, long error_code, | |
468 | siginfo_t *info) | |
1da177e4 | 469 | { |
4f339ecb | 470 | struct task_struct *tsk = current; |
4f339ecb | 471 | |
1da177e4 LT |
472 | if (regs->eflags & VM_MASK) { |
473 | if (vm86) | |
474 | goto vm86_trap; | |
475 | goto trap_signal; | |
476 | } | |
477 | ||
717b594a | 478 | if (!user_mode(regs)) |
1da177e4 LT |
479 | goto kernel_trap; |
480 | ||
481 | trap_signal: { | |
d1895183 AK |
482 | /* |
483 | * We want error_code and trap_no set for userspace faults and | |
484 | * kernelspace faults which result in die(), but not | |
485 | * kernelspace faults which are fixed up. die() gives the | |
486 | * process no chance to handle the signal and notice the | |
487 | * kernel fault information, so that won't result in polluting | |
488 | * the information about previously queued, but not yet | |
489 | * delivered, faults. See also do_general_protection below. | |
490 | */ | |
491 | tsk->thread.error_code = error_code; | |
492 | tsk->thread.trap_no = trapnr; | |
493 | ||
1da177e4 LT |
494 | if (info) |
495 | force_sig_info(signr, info, tsk); | |
496 | else | |
497 | force_sig(signr, tsk); | |
498 | return; | |
499 | } | |
500 | ||
501 | kernel_trap: { | |
d1895183 AK |
502 | if (!fixup_exception(regs)) { |
503 | tsk->thread.error_code = error_code; | |
504 | tsk->thread.trap_no = trapnr; | |
1da177e4 | 505 | die(str, regs, error_code); |
d1895183 | 506 | } |
1da177e4 LT |
507 | return; |
508 | } | |
509 | ||
510 | vm86_trap: { | |
511 | int ret = handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, trapnr); | |
512 | if (ret) goto trap_signal; | |
513 | return; | |
514 | } | |
515 | } | |
516 | ||
517 | #define DO_ERROR(trapnr, signr, str, name) \ | |
518 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
519 | { \ | |
520 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
521 | == NOTIFY_STOP) \ | |
522 | return; \ | |
523 | do_trap(trapnr, signr, str, 0, regs, error_code, NULL); \ | |
524 | } | |
525 | ||
a10d9a71 | 526 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr, irq) \ |
1da177e4 LT |
527 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ |
528 | { \ | |
529 | siginfo_t info; \ | |
a10d9a71 PZ |
530 | if (irq) \ |
531 | local_irq_enable(); \ | |
1da177e4 LT |
532 | info.si_signo = signr; \ |
533 | info.si_errno = 0; \ | |
534 | info.si_code = sicode; \ | |
535 | info.si_addr = (void __user *)siaddr; \ | |
536 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
537 | == NOTIFY_STOP) \ | |
538 | return; \ | |
539 | do_trap(trapnr, signr, str, 0, regs, error_code, &info); \ | |
540 | } | |
541 | ||
542 | #define DO_VM86_ERROR(trapnr, signr, str, name) \ | |
543 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
544 | { \ | |
545 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
546 | == NOTIFY_STOP) \ | |
547 | return; \ | |
548 | do_trap(trapnr, signr, str, 1, regs, error_code, NULL); \ | |
549 | } | |
550 | ||
551 | #define DO_VM86_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ | |
552 | fastcall void do_##name(struct pt_regs * regs, long error_code) \ | |
553 | { \ | |
554 | siginfo_t info; \ | |
555 | info.si_signo = signr; \ | |
556 | info.si_errno = 0; \ | |
557 | info.si_code = sicode; \ | |
558 | info.si_addr = (void __user *)siaddr; \ | |
559 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \ | |
560 | == NOTIFY_STOP) \ | |
561 | return; \ | |
562 | do_trap(trapnr, signr, str, 1, regs, error_code, &info); \ | |
563 | } | |
564 | ||
565 | DO_VM86_ERROR_INFO( 0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->eip) | |
566 | #ifndef CONFIG_KPROBES | |
567 | DO_VM86_ERROR( 3, SIGTRAP, "int3", int3) | |
568 | #endif | |
569 | DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow) | |
570 | DO_VM86_ERROR( 5, SIGSEGV, "bounds", bounds) | |
a10d9a71 | 571 | DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip, 0) |
1da177e4 LT |
572 | DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun) |
573 | DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS) | |
574 | DO_ERROR(11, SIGBUS, "segment not present", segment_not_present) | |
575 | DO_ERROR(12, SIGBUS, "stack segment", stack_segment) | |
a10d9a71 PZ |
576 | DO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0, 0) |
577 | DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0, 1) | |
1da177e4 | 578 | |
3d97ae5b PP |
579 | fastcall void __kprobes do_general_protection(struct pt_regs * regs, |
580 | long error_code) | |
1da177e4 LT |
581 | { |
582 | int cpu = get_cpu(); | |
583 | struct tss_struct *tss = &per_cpu(init_tss, cpu); | |
584 | struct thread_struct *thread = ¤t->thread; | |
585 | ||
586 | /* | |
587 | * Perform the lazy TSS's I/O bitmap copy. If the TSS has an | |
588 | * invalid offset set (the LAZY one) and the faulting thread has | |
589 | * a valid I/O bitmap pointer, we copy the I/O bitmap in the TSS | |
590 | * and we set the offset field correctly. Then we let the CPU to | |
591 | * restart the faulting instruction. | |
592 | */ | |
a75c54f9 | 593 | if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY && |
1da177e4 LT |
594 | thread->io_bitmap_ptr) { |
595 | memcpy(tss->io_bitmap, thread->io_bitmap_ptr, | |
596 | thread->io_bitmap_max); | |
597 | /* | |
598 | * If the previously set map was extending to higher ports | |
599 | * than the current one, pad extra space with 0xff (no access). | |
600 | */ | |
601 | if (thread->io_bitmap_max < tss->io_bitmap_max) | |
602 | memset((char *) tss->io_bitmap + | |
603 | thread->io_bitmap_max, 0xff, | |
604 | tss->io_bitmap_max - thread->io_bitmap_max); | |
605 | tss->io_bitmap_max = thread->io_bitmap_max; | |
a75c54f9 | 606 | tss->x86_tss.io_bitmap_base = IO_BITMAP_OFFSET; |
d5cd4aad | 607 | tss->io_bitmap_owner = thread; |
1da177e4 LT |
608 | put_cpu(); |
609 | return; | |
610 | } | |
611 | put_cpu(); | |
612 | ||
613 | if (regs->eflags & VM_MASK) | |
614 | goto gp_in_vm86; | |
615 | ||
717b594a | 616 | if (!user_mode(regs)) |
1da177e4 LT |
617 | goto gp_in_kernel; |
618 | ||
619 | current->thread.error_code = error_code; | |
620 | current->thread.trap_no = 13; | |
abd4f750 MAS |
621 | if (show_unhandled_signals && unhandled_signal(current, SIGSEGV) && |
622 | printk_ratelimit()) | |
623 | printk(KERN_INFO | |
624 | "%s[%d] general protection eip:%lx esp:%lx error:%lx\n", | |
625 | current->comm, current->pid, | |
626 | regs->eip, regs->esp, error_code); | |
627 | ||
1da177e4 LT |
628 | force_sig(SIGSEGV, current); |
629 | return; | |
630 | ||
631 | gp_in_vm86: | |
632 | local_irq_enable(); | |
633 | handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code); | |
634 | return; | |
635 | ||
636 | gp_in_kernel: | |
637 | if (!fixup_exception(regs)) { | |
d1895183 AK |
638 | current->thread.error_code = error_code; |
639 | current->thread.trap_no = 13; | |
1da177e4 LT |
640 | if (notify_die(DIE_GPF, "general protection fault", regs, |
641 | error_code, 13, SIGSEGV) == NOTIFY_STOP) | |
642 | return; | |
643 | die("general protection fault", regs, error_code); | |
644 | } | |
645 | } | |
646 |