traps.c

来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 1,211 行 · 第 1/3 页

C
1,211
字号
/* *  linux/arch/i386/traps.c * *  Copyright (C) 1991, 1992  Linus Torvalds * *  Pentium III FXSR, SSE support *	Gareth Hughes <gareth@valinux.com>, May 2000 *//* * 'Traps.c' handles hardware traps and faults after we have saved some * state in 'asm.s'. */#include <linux/config.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/spinlock.h>#include <linux/interrupt.h>#include <linux/highmem.h>#include <linux/kallsyms.h>#include <linux/ptrace.h>#include <linux/utsname.h>#include <linux/kprobes.h>#include <linux/kexec.h>#ifdef CONFIG_EISA#include <linux/ioport.h>#include <linux/eisa.h>#endif#ifdef CONFIG_MCA#include <linux/mca.h>#endif#include <asm/processor.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/atomic.h>#include <asm/debugreg.h>#include <asm/desc.h>#include <asm/i387.h>#include <asm/nmi.h>#include <asm/smp.h>#include <asm/arch_hooks.h>#include <asm/kdebug.h>#include <linux/module.h>#include "mach_traps.h"asmlinkage int system_call(void);struct desc_struct default_ldt[] = { { 0, 0 }, { 0, 0 }, { 0, 0 },		{ 0, 0 }, { 0, 0 } };/* Do we ignore FPU interrupts ? */char ignore_fpu_irq = 0;/* * The IDT has to be page-aligned to simplify the Pentium * F0 0F bug workaround.. We have a special link segment * for this. */struct desc_struct idt_table[256] __attribute__((__section__(".data.idt"))) = { {0, 0}, };asmlinkage void divide_error(void);asmlinkage void debug(void);asmlinkage void nmi(void);asmlinkage void int3(void);asmlinkage void overflow(void);asmlinkage void bounds(void);asmlinkage void invalid_op(void);asmlinkage void device_not_available(void);asmlinkage void coprocessor_segment_overrun(void);asmlinkage void invalid_TSS(void);asmlinkage void segment_not_present(void);asmlinkage void stack_segment(void);asmlinkage void general_protection(void);asmlinkage void page_fault(void);asmlinkage void coprocessor_error(void);asmlinkage void simd_coprocessor_error(void);asmlinkage void alignment_check(void);asmlinkage void spurious_interrupt_bug(void);asmlinkage void machine_check(void);static int kstack_depth_to_print = 24;ATOMIC_NOTIFIER_HEAD(i386die_chain);int register_die_notifier(struct notifier_block *nb){	vmalloc_sync_all();	return atomic_notifier_chain_register(&i386die_chain, nb);}EXPORT_SYMBOL(register_die_notifier);int unregister_die_notifier(struct notifier_block *nb){	return atomic_notifier_chain_unregister(&i386die_chain, nb);}EXPORT_SYMBOL(unregister_die_notifier);static inline int valid_stack_ptr(struct thread_info *tinfo, void *p){	return	p > (void *)tinfo &&		p < (void *)tinfo + THREAD_SIZE - 3;}/* * Print CONFIG_STACK_BACKTRACE_COLS address/symbol entries per line. */static inline int print_addr_and_symbol(unsigned long addr, char *log_lvl,					int printed){	if (!printed)		printk(log_lvl);#if CONFIG_STACK_BACKTRACE_COLS == 1	printk(" [<%08lx>] ", addr);#else	printk(" <%08lx> ", addr);#endif	print_symbol("%s", addr);	printed = (printed + 1) % CONFIG_STACK_BACKTRACE_COLS;	if (printed)		printk(" ");	else		printk("\n");	return printed;}static inline unsigned long print_context_stack(struct thread_info *tinfo,				unsigned long *stack, unsigned long ebp,				char *log_lvl){	unsigned long addr;	int printed = 0; /* nr of entries already printed on current line */#ifdef	CONFIG_FRAME_POINTER	while (valid_stack_ptr(tinfo, (void *)ebp)) {		addr = *(unsigned long *)(ebp + 4);		printed = print_addr_and_symbol(addr, log_lvl, printed);		ebp = *(unsigned long *)ebp;	}#else	while (valid_stack_ptr(tinfo, stack)) {		addr = *stack++;		if (__kernel_text_address(addr))			printed = print_addr_and_symbol(addr, log_lvl, printed);	}#endif	if (printed)		printk("\n");	return ebp;}static void show_trace_log_lvl(struct task_struct *task,			       unsigned long *stack, char *log_lvl){	unsigned long ebp;	if (!task)		task = current;	if (task == current) {		/* Grab ebp right from our regs */		asm ("movl %%ebp, %0" : "=r" (ebp) : );	} else {		/* ebp is the last reg pushed by switch_to */		ebp = *(unsigned long *) task->thread.esp;	}	while (1) {		struct thread_info *context;		context = (struct thread_info *)			((unsigned long)stack & (~(THREAD_SIZE - 1)));		ebp = print_context_stack(context, stack, ebp, log_lvl);		stack = (unsigned long*)context->previous_esp;		if (!stack)			break;		printk("%s =======================\n", log_lvl);	}}void show_trace(struct task_struct *task, unsigned long * stack){	show_trace_log_lvl(task, stack, "");}static void show_stack_log_lvl(struct task_struct *task, unsigned long *esp,			       char *log_lvl){	unsigned long *stack;	int i;	if (esp == NULL) {		if (task)			esp = (unsigned long*)task->thread.esp;		else			esp = (unsigned long *)&esp;	}	stack = esp;	for(i = 0; i < kstack_depth_to_print; i++) {		if (kstack_end(stack))			break;		if (i && ((i % 8) == 0))			printk("\n%s       ", log_lvl);		printk("%08lx ", *stack++);	}	printk("\n%sCall Trace:\n", log_lvl);	show_trace_log_lvl(task, esp, log_lvl);}void show_stack(struct task_struct *task, unsigned long *esp){	printk("       ");	show_stack_log_lvl(task, esp, "");}/* * The architecture-independent dump_stack generator */void dump_stack(void){	unsigned long stack;	show_trace(current, &stack);}EXPORT_SYMBOL(dump_stack);void show_registers(struct pt_regs *regs){	int i;	int in_kernel = 1;	unsigned long esp;	unsigned short ss;	esp = (unsigned long) (&regs->esp);	savesegment(ss, ss);	if (user_mode_vm(regs)) {		in_kernel = 0;		esp = regs->esp;		ss = regs->xss & 0xffff;	}	print_modules();	printk(KERN_EMERG "CPU:    %d\nEIP:    %04x:[<%08lx>]    %s VLI\n"			"EFLAGS: %08lx   (%s %.*s) \n",		smp_processor_id(), 0xffff & regs->xcs, regs->eip,		print_tainted(), regs->eflags, system_utsname.release,		(int)strcspn(system_utsname.version, " "),		system_utsname.version);	print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);	printk(KERN_EMERG "eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",		regs->eax, regs->ebx, regs->ecx, regs->edx);	printk(KERN_EMERG "esi: %08lx   edi: %08lx   ebp: %08lx   esp: %08lx\n",		regs->esi, regs->edi, regs->ebp, esp);	printk(KERN_EMERG "ds: %04x   es: %04x   ss: %04x\n",		regs->xds & 0xffff, regs->xes & 0xffff, ss);	printk(KERN_EMERG "Process %s (pid: %d, threadinfo=%p task=%p)",		current->comm, current->pid, current_thread_info(), current);	/*	 * When in-kernel, we also print out the stack and code at the	 * time of the fault..	 */	if (in_kernel) {		u8 __user *eip;		printk("\n" KERN_EMERG "Stack: ");		show_stack_log_lvl(NULL, (unsigned long *)esp, KERN_EMERG);		printk(KERN_EMERG "Code: ");		eip = (u8 __user *)regs->eip - 43;		for (i = 0; i < 64; i++, eip++) {			unsigned char c;			if (eip < (u8 __user *)PAGE_OFFSET || __get_user(c, eip)) {				printk(" Bad EIP value.");				break;			}			if (eip == (u8 __user *)regs->eip)				printk("<%02x> ", c);			else				printk("%02x ", c);		}	}	printk("\n");}	static void handle_BUG(struct pt_regs *regs){	unsigned short ud2;	unsigned short line;	char *file;	char c;	unsigned long eip;	eip = regs->eip;	if (eip < PAGE_OFFSET)		goto no_bug;	if (__get_user(ud2, (unsigned short __user *)eip))		goto no_bug;	if (ud2 != 0x0b0f)		goto no_bug;	if (__get_user(line, (unsigned short __user *)(eip + 2)))		goto bug;	if (__get_user(file, (char * __user *)(eip + 4)) ||		(unsigned long)file < PAGE_OFFSET || __get_user(c, file))		file = "<bad filename>";	printk(KERN_EMERG "------------[ cut here ]------------\n");	printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);no_bug:	return;	/* Here we know it was a BUG but file-n-line is unavailable */bug:	printk(KERN_EMERG "Kernel BUG\n");}/* This is gone through when something in the kernel * has done something bad and is about to be terminated.*/void die(const char * str, struct pt_regs * regs, long err){	static struct {		spinlock_t lock;		u32 lock_owner;		int lock_owner_depth;	} die = {		.lock =			SPIN_LOCK_UNLOCKED,		.lock_owner =		-1,		.lock_owner_depth =	0	};	static int die_counter;	unsigned long flags;	oops_enter();	if (die.lock_owner != raw_smp_processor_id()) {		console_verbose();		spin_lock_irqsave(&die.lock, flags);		die.lock_owner = smp_processor_id();		die.lock_owner_depth = 0;		bust_spinlocks(1);	}	else		local_save_flags(flags);	if (++die.lock_owner_depth < 3) {		int nl = 0;		unsigned long esp;		unsigned short ss;		handle_BUG(regs);		printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);#ifdef CONFIG_PREEMPT		printk(KERN_EMERG "PREEMPT ");		nl = 1;#endif#ifdef CONFIG_SMP		if (!nl)			printk(KERN_EMERG);		printk("SMP ");		nl = 1;#endif#ifdef CONFIG_DEBUG_PAGEALLOC		if (!nl)			printk(KERN_EMERG);		printk("DEBUG_PAGEALLOC");		nl = 1;#endif		if (nl)			printk("\n");		if (notify_die(DIE_OOPS, str, regs, err,					current->thread.trap_no, SIGSEGV) !=				NOTIFY_STOP) {			show_registers(regs);			/* Executive summary in case the oops scrolled away */			esp = (unsigned long) (&regs->esp);			savesegment(ss, ss);			if (user_mode(regs)) {				esp = regs->esp;				ss = regs->xss & 0xffff;			}			printk(KERN_EMERG "EIP: [<%08lx>] ", regs->eip);			print_symbol("%s", regs->eip);			printk(" SS:ESP %04x:%08lx\n", ss, esp);		}		else

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?