⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traps.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/arch/arm/kernel/traps.c * *  Copyright (C) 1995-2002 Russell King *  Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * *  'traps.c' handles hardware exceptions after we have saved some state in *  'linux/arch/arm/lib/traps.S'.  Mostly a debugging aid, but will probably *  kill the offending process. */#include <linux/module.h>#include <linux/signal.h>#include <linux/spinlock.h>#include <linux/personality.h>#include <linux/kallsyms.h>#include <linux/delay.h>#include <linux/init.h>#include <asm/atomic.h>#include <asm/cacheflush.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/unistd.h>#include <asm/traps.h>#include <asm/io.h>#include "ptrace.h"#include "signal.h"static const char *handler[]= { "prefetch abort", "data abort", "address exception", "interrupt" };#ifdef CONFIG_DEBUG_USERunsigned int user_debug;static int __init user_debug_setup(char *str){	get_option(&str, &user_debug);	return 1;}__setup("user_debug=", user_debug_setup);#endifstatic void dump_mem(const char *str, unsigned long bottom, unsigned long top);static inline int in_exception_text(unsigned long ptr){	extern char __exception_text_start[];	extern char __exception_text_end[];	return ptr >= (unsigned long)&__exception_text_start &&	       ptr < (unsigned long)&__exception_text_end;}void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame){#ifdef CONFIG_KALLSYMS	printk("[<%08lx>] ", where);	print_symbol("(%s) ", where);	printk("from [<%08lx>] ", from);	print_symbol("(%s)\n", from);#else	printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);#endif	if (in_exception_text(where))		dump_mem("Exception stack", frame + 4, frame + 4 + sizeof(struct pt_regs));}/* * Stack pointers should always be within the kernels view of * physical memory.  If it is not there, then we can't dump * out any information relating to the stack. */static int verify_stack(unsigned long sp){	if (sp < PAGE_OFFSET || (sp > (unsigned long)high_memory && high_memory != 0))		return -EFAULT;	return 0;}/* * Dump out the contents of some memory nicely... */static void dump_mem(const char *str, unsigned long bottom, unsigned long top){	unsigned long p = bottom & ~31;	mm_segment_t fs;	int i;	/*	 * We need to switch to kernel mode so that we can use __get_user	 * to safely read from kernel space.  Note that we now dump the	 * code first, just in case the backtrace kills us.	 */	fs = get_fs();	set_fs(KERNEL_DS);	printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);	for (p = bottom & ~31; p < top;) {		printk("%04lx: ", p & 0xffff);		for (i = 0; i < 8; i++, p += 4) {			unsigned int val;			if (p < bottom || p >= top)				printk("         ");			else {				__get_user(val, (unsigned long *)p);				printk("%08x ", val);			}		}		printk ("\n");	}	set_fs(fs);}static void dump_instr(struct pt_regs *regs){	unsigned long addr = instruction_pointer(regs);	const int thumb = thumb_mode(regs);	const int width = thumb ? 4 : 8;	mm_segment_t fs;	int i;	/*	 * We need to switch to kernel mode so that we can use __get_user	 * to safely read from kernel space.  Note that we now dump the	 * code first, just in case the backtrace kills us.	 */	fs = get_fs();	set_fs(KERNEL_DS);	printk("Code: ");	for (i = -4; i < 1; i++) {		unsigned int val, bad;		if (thumb)			bad = __get_user(val, &((u16 *)addr)[i]);		else			bad = __get_user(val, &((u32 *)addr)[i]);		if (!bad)			printk(i == 0 ? "(%0*x) " : "%0*x ", width, val);		else {			printk("bad PC value.");			break;		}	}	printk("\n");	set_fs(fs);}static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk){	unsigned int fp;	int ok = 1;	printk("Backtrace: ");	fp = regs->ARM_fp;	if (!fp) {		printk("no frame pointer");		ok = 0;	} else if (verify_stack(fp)) {		printk("invalid frame pointer 0x%08x", fp);		ok = 0;	} else if (fp < (unsigned long)end_of_stack(tsk))		printk("frame pointer underflow");	printk("\n");	if (ok)		c_backtrace(fp, processor_mode(regs));}void dump_stack(void){	__backtrace();}EXPORT_SYMBOL(dump_stack);void show_stack(struct task_struct *tsk, unsigned long *sp){	unsigned long fp;	if (!tsk)		tsk = current;	if (tsk != current)		fp = thread_saved_fp(tsk);	else		asm("mov %0, fp" : "=r" (fp) : : "cc");	c_backtrace(fp, 0x10);	barrier();}#ifdef CONFIG_PREEMPT#define S_PREEMPT " PREEMPT"#else#define S_PREEMPT ""#endif#ifdef CONFIG_SMP#define S_SMP " SMP"#else#define S_SMP ""#endifstatic void __die(const char *str, int err, struct thread_info *thread, struct pt_regs *regs){	struct task_struct *tsk = thread->task;	static int die_counter;	printk("Internal error: %s: %x [#%d]" S_PREEMPT S_SMP "\n",	       str, err, ++die_counter);	print_modules();	__show_regs(regs);	printk("Process %s (pid: %d, stack limit = 0x%p)\n",		tsk->comm, task_pid_nr(tsk), thread + 1);	if (!user_mode(regs) || in_interrupt()) {		dump_mem("Stack: ", regs->ARM_sp,			 THREAD_SIZE + (unsigned long)task_stack_page(tsk));		dump_backtrace(regs, tsk);		dump_instr(regs);	}}DEFINE_SPINLOCK(die_lock);/* * This function is protected against re-entrancy. */NORET_TYPE void die(const char *str, struct pt_regs *regs, int err){	struct thread_info *thread = current_thread_info();	oops_enter();	console_verbose();	spin_lock_irq(&die_lock);	bust_spinlocks(1);	__die(str, err, thread, regs);	bust_spinlocks(0);	add_taint(TAINT_DIE);	spin_unlock_irq(&die_lock);	if (in_interrupt())		panic("Fatal exception in interrupt");	if (panic_on_oops)		panic("Fatal exception");	oops_exit();	do_exit(SIGSEGV);}void arm_notify_die(const char *str, struct pt_regs *regs,		struct siginfo *info, unsigned long err, unsigned long trap){	if (user_mode(regs)) {		current->thread.error_code = err;		current->thread.trap_no = trap;		force_sig_info(info->si_signo, info, current);	} else {		die(str, regs, err);	}}static LIST_HEAD(undef_hook);static DEFINE_SPINLOCK(undef_lock);void register_undef_hook(struct undef_hook *hook){	unsigned long flags;	spin_lock_irqsave(&undef_lock, flags);	list_add(&hook->node, &undef_hook);	spin_unlock_irqrestore(&undef_lock, flags);}void unregister_undef_hook(struct undef_hook *hook){	unsigned long flags;	spin_lock_irqsave(&undef_lock, flags);	list_del(&hook->node);	spin_unlock_irqrestore(&undef_lock, flags);}asmlinkage void __exception do_undefinstr(struct pt_regs *regs){	unsigned int correction = thumb_mode(regs) ? 2 : 4;	unsigned int instr;	struct undef_hook *hook;	siginfo_t info;	void __user *pc;	unsigned long flags;	/*	 * According to the ARM ARM, PC is 2 or 4 bytes ahead,	 * depending whether we're in Thumb mode or not.	 * Correct this offset.	 */	regs->ARM_pc -= correction;	pc = (void __user *)instruction_pointer(regs);	if (processor_mode(regs) == SVC_MODE) {		instr = *(u32 *) pc;	} else if (thumb_mode(regs)) {		get_user(instr, (u16 __user *)pc);	} else {		get_user(instr, (u32 __user *)pc);	}	spin_lock_irqsave(&undef_lock, flags);	list_for_each_entry(hook, &undef_hook, node) {		if ((instr & hook->instr_mask) == hook->instr_val &&		    (regs->ARM_cpsr & hook->cpsr_mask) == hook->cpsr_val) {			if (hook->fn(regs, instr) == 0) {				spin_unlock_irqrestore(&undef_lock, flags);				return;			}		}	}	spin_unlock_irqrestore(&undef_lock, flags);#ifdef CONFIG_DEBUG_USER	if (user_debug & UDBG_UNDEFINED) {		printk(KERN_INFO "%s (%d): undefined instruction: pc=%p\n",			current->comm, task_pid_nr(current), pc);		dump_instr(regs);	}#endif	info.si_signo = SIGILL;	info.si_errno = 0;	info.si_code  = ILL_ILLOPC;	info.si_addr  = pc;	arm_notify_die("Oops - undefined instruction", regs, &info, 0, 6);}asmlinkage void do_unexp_fiq (struct pt_regs *regs){	printk("Hmm.  Unexpected FIQ received, but trying to continue\n");	printk("You may have a hardware problem...\n");}/* * bad_mode handles the impossible case in the vectors.  If you see one of * these, then it's extremely serious, and could mean you have buggy hardware. * It never returns, and never tries to sync.  We hope that we can at least * dump out some state information... */asmlinkage void bad_mode(struct pt_regs *regs, int reason){	console_verbose();

⌨️ 快捷键说明

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