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

📄 traps.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	printk(KERN_CRIT "Bad mode in %s handler detected\n", handler[reason]);	die("Oops - bad mode", regs, 0);	local_irq_disable();	panic("bad mode");}static int bad_syscall(int n, struct pt_regs *regs){	struct thread_info *thread = current_thread_info();	siginfo_t info;	if (current->personality != PER_LINUX &&	    current->personality != PER_LINUX_32BIT &&	    thread->exec_domain->handler) {		thread->exec_domain->handler(n, regs);		return regs->ARM_r0;	}#ifdef CONFIG_DEBUG_USER	if (user_debug & UDBG_SYSCALL) {		printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",			task_pid_nr(current), current->comm, n);		dump_instr(regs);	}#endif	info.si_signo = SIGILL;	info.si_errno = 0;	info.si_code  = ILL_ILLTRP;	info.si_addr  = (void __user *)instruction_pointer(regs) -			 (thumb_mode(regs) ? 2 : 4);	arm_notify_die("Oops - bad syscall", regs, &info, n, 0);	return regs->ARM_r0;}static inline voiddo_cache_op(unsigned long start, unsigned long end, int flags){	struct vm_area_struct *vma;	if (end < start || flags)		return;	vma = find_vma(current->active_mm, start);	if (vma && vma->vm_start < end) {		if (start < vma->vm_start)			start = vma->vm_start;		if (end > vma->vm_end)			end = vma->vm_end;		flush_cache_user_range(vma, start, end);	}}/* * Handle all unrecognised system calls. *  0x9f0000 - 0x9fffff are some more esoteric system calls */#define NR(x) ((__ARM_NR_##x) - __ARM_NR_BASE)asmlinkage int arm_syscall(int no, struct pt_regs *regs){	struct thread_info *thread = current_thread_info();	siginfo_t info;	if ((no >> 16) != (__ARM_NR_BASE>> 16))		return bad_syscall(no, regs);	switch (no & 0xffff) {	case 0: /* branch through 0 */		info.si_signo = SIGSEGV;		info.si_errno = 0;		info.si_code  = SEGV_MAPERR;		info.si_addr  = NULL;		arm_notify_die("branch through zero", regs, &info, 0, 0);		return 0;	case NR(breakpoint): /* SWI BREAK_POINT */		regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;		ptrace_break(current, regs);		return regs->ARM_r0;	/*	 * Flush a region from virtual address 'r0' to virtual address 'r1'	 * _exclusive_.  There is no alignment requirement on either address;	 * user space does not need to know the hardware cache layout.	 *	 * r2 contains flags.  It should ALWAYS be passed as ZERO until it	 * is defined to be something else.  For now we ignore it, but may	 * the fires of hell burn in your belly if you break this rule. ;)	 *	 * (at a later date, we may want to allow this call to not flush	 * various aspects of the cache.  Passing '0' will guarantee that	 * everything necessary gets flushed to maintain consistency in	 * the specified region).	 */	case NR(cacheflush):		do_cache_op(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2);		return 0;	case NR(usr26):		if (!(elf_hwcap & HWCAP_26BIT))			break;		regs->ARM_cpsr &= ~MODE32_BIT;		return regs->ARM_r0;	case NR(usr32):		if (!(elf_hwcap & HWCAP_26BIT))			break;		regs->ARM_cpsr |= MODE32_BIT;		return regs->ARM_r0;	case NR(set_tls):		thread->tp_value = regs->ARM_r0;#if defined(CONFIG_HAS_TLS_REG)		asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );#elif !defined(CONFIG_TLS_REG_EMUL)		/*		 * User space must never try to access this directly.		 * Expect your app to break eventually if you do so.		 * The user helper at 0xffff0fe0 must be used instead.		 * (see entry-armv.S for details)		 */		*((unsigned int *)0xffff0ff0) = regs->ARM_r0;#endif		return 0;#ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG	/*	 * Atomically store r1 in *r2 if *r2 is equal to r0 for user space.	 * Return zero in r0 if *MEM was changed or non-zero if no exchange	 * happened.  Also set the user C flag accordingly.	 * If access permissions have to be fixed up then non-zero is	 * returned and the operation has to be re-attempted.	 *	 * *NOTE*: This is a ghost syscall private to the kernel.  Only the	 * __kuser_cmpxchg code in entry-armv.S should be aware of its	 * existence.  Don't ever use this from user code.	 */	case 0xfff0:	for (;;) {		extern void do_DataAbort(unsigned long addr, unsigned int fsr,					 struct pt_regs *regs);		unsigned long val;		unsigned long addr = regs->ARM_r2;		struct mm_struct *mm = current->mm;		pgd_t *pgd; pmd_t *pmd; pte_t *pte;		spinlock_t *ptl;		regs->ARM_cpsr &= ~PSR_C_BIT;		down_read(&mm->mmap_sem);		pgd = pgd_offset(mm, addr);		if (!pgd_present(*pgd))			goto bad_access;		pmd = pmd_offset(pgd, addr);		if (!pmd_present(*pmd))			goto bad_access;		pte = pte_offset_map_lock(mm, pmd, addr, &ptl);		if (!pte_present(*pte) || !pte_dirty(*pte)) {			pte_unmap_unlock(pte, ptl);			goto bad_access;		}		val = *(unsigned long *)addr;		val -= regs->ARM_r0;		if (val == 0) {			*(unsigned long *)addr = regs->ARM_r1;			regs->ARM_cpsr |= PSR_C_BIT;		}		pte_unmap_unlock(pte, ptl);		up_read(&mm->mmap_sem);		return val;		bad_access:		up_read(&mm->mmap_sem);		/* simulate a write access fault */		do_DataAbort(addr, 15 + (1 << 11), regs);	}#endif	default:		/* Calls 9f00xx..9f07ff are defined to return -ENOSYS		   if not implemented, rather than raising SIGILL.  This		   way the calling program can gracefully determine whether		   a feature is supported.  */		if (no <= 0x7ff)			return -ENOSYS;		break;	}#ifdef CONFIG_DEBUG_USER	/*	 * experience shows that these seem to indicate that	 * something catastrophic has happened	 */	if (user_debug & UDBG_SYSCALL) {		printk("[%d] %s: arm syscall %d\n",		       task_pid_nr(current), current->comm, no);		dump_instr(regs);		if (user_mode(regs)) {			__show_regs(regs);			c_backtrace(regs->ARM_fp, processor_mode(regs));		}	}#endif	info.si_signo = SIGILL;	info.si_errno = 0;	info.si_code  = ILL_ILLTRP;	info.si_addr  = (void __user *)instruction_pointer(regs) -			 (thumb_mode(regs) ? 2 : 4);	arm_notify_die("Oops - bad syscall(2)", regs, &info, no, 0);	return 0;}#ifdef CONFIG_TLS_REG_EMUL/* * We might be running on an ARMv6+ processor which should have the TLS * register but for some reason we can't use it, or maybe an SMP system * using a pre-ARMv6 processor (there are apparently a few prototypes like * that in existence) and therefore access to that register must be * emulated. */static int get_tp_trap(struct pt_regs *regs, unsigned int instr){	int reg = (instr >> 12) & 15;	if (reg == 15)		return 1;	regs->uregs[reg] = current_thread_info()->tp_value;	regs->ARM_pc += 4;	return 0;}static struct undef_hook arm_mrc_hook = {	.instr_mask	= 0x0fff0fff,	.instr_val	= 0x0e1d0f70,	.cpsr_mask	= PSR_T_BIT,	.cpsr_val	= 0,	.fn		= get_tp_trap,};static int __init arm_mrc_hook_init(void){	register_undef_hook(&arm_mrc_hook);	return 0;}late_initcall(arm_mrc_hook_init);#endifvoid __bad_xchg(volatile void *ptr, int size){	printk("xchg: bad data size: pc 0x%p, ptr 0x%p, size %d\n",		__builtin_return_address(0), ptr, size);	BUG();}EXPORT_SYMBOL(__bad_xchg);/* * A data abort trap was taken, but we did not handle the instruction. * Try to abort the user program, or panic if it was the kernel. */asmlinkage voidbaddataabort(int code, unsigned long instr, struct pt_regs *regs){	unsigned long addr = instruction_pointer(regs);	siginfo_t info;#ifdef CONFIG_DEBUG_USER	if (user_debug & UDBG_BADABORT) {		printk(KERN_ERR "[%d] %s: bad data abort: code %d instr 0x%08lx\n",			task_pid_nr(current), current->comm, code, instr);		dump_instr(regs);		show_pte(current->mm, addr);	}#endif	info.si_signo = SIGILL;	info.si_errno = 0;	info.si_code  = ILL_ILLOPC;	info.si_addr  = (void __user *)addr;	arm_notify_die("unknown data abort code", regs, &info, instr, 0);}void __attribute__((noreturn)) __bug(const char *file, int line){	printk(KERN_CRIT"kernel BUG at %s:%d!\n", file, line);	*(int *)0 = 0;	/* Avoid "noreturn function does return" */	for (;;);}EXPORT_SYMBOL(__bug);void __readwrite_bug(const char *fn){	printk("%s called, but not implemented\n", fn);	BUG();}EXPORT_SYMBOL(__readwrite_bug);void __pte_error(const char *file, int line, unsigned long val){	printk("%s:%d: bad pte %08lx.\n", file, line, val);}void __pmd_error(const char *file, int line, unsigned long val){	printk("%s:%d: bad pmd %08lx.\n", file, line, val);}void __pgd_error(const char *file, int line, unsigned long val){	printk("%s:%d: bad pgd %08lx.\n", file, line, val);}asmlinkage void __div0(void){	printk("Division by zero in kernel.\n");	dump_stack();}EXPORT_SYMBOL(__div0);void abort(void){	BUG();	/* if that doesn't kill us, halt */	panic("Oops failed to kill thread");}EXPORT_SYMBOL(abort);void __init trap_init(void){	unsigned long vectors = CONFIG_VECTORS_BASE;	extern char __stubs_start[], __stubs_end[];	extern char __vectors_start[], __vectors_end[];	extern char __kuser_helper_start[], __kuser_helper_end[];	int kuser_sz = __kuser_helper_end - __kuser_helper_start;	/*	 * Copy the vectors, stubs and kuser helpers (in entry-armv.S)	 * into the vector page, mapped at 0xffff0000, and ensure these	 * are visible to the instruction stream.	 */	memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);	memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);	memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);	/*	 * Copy signal return handlers into the vector page, and	 * set sigreturn to be a pointer to these.	 */	memcpy((void *)KERN_SIGRETURN_CODE, sigreturn_codes,	       sizeof(sigreturn_codes));	flush_icache_range(vectors, vectors + PAGE_SIZE);	modify_domain(DOMAIN_USER, DOMAIN_CLIENT);}

⌨️ 快捷键说明

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