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