]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - arch/x86/kernel/traps_64.c
x86: remove unneded casts
[karo-tx-linux.git] / arch / x86 / kernel / traps_64.c
index 304ca6b4a1caeceae1b42100b1675867983f11a3..4aa4520f9499e7720c29b76ae0a1b8e4ba1663c3 100644 (file)
@@ -74,6 +74,8 @@ asmlinkage void alignment_check(void);
 asmlinkage void machine_check(void);
 asmlinkage void spurious_interrupt_bug(void);
 
+static unsigned int code_bytes = 64;
+
 static inline void conditional_sti(struct pt_regs *regs)
 {
        if (regs->flags & X86_EFLAGS_IF)
@@ -215,7 +217,7 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
 static inline int valid_stack_ptr(struct thread_info *tinfo,
                        void *p, unsigned int size, void *end)
 {
-       void *t = (void *)tinfo;
+       void *t = tinfo;
        if (end) {
                if (p < end && p >= (end-THREAD_SIZE))
                        return 1;
@@ -459,12 +461,15 @@ EXPORT_SYMBOL(dump_stack);
 void show_registers(struct pt_regs *regs)
 {
        int i;
-       int in_kernel = !user_mode(regs);
        unsigned long sp;
        const int cpu = smp_processor_id();
        struct task_struct *cur = cpu_pda(cpu)->pcurrent;
+       u8 *ip;
+       unsigned int code_prologue = code_bytes * 43 / 64;
+       unsigned int code_len = code_bytes;
 
        sp = regs->sp;
+       ip = (u8 *) regs->ip - code_prologue;
        printk("CPU %d ", cpu);
        __show_regs(regs);
        printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
@@ -474,22 +479,28 @@ void show_registers(struct pt_regs *regs)
         * When in-kernel, we also print out the stack and code at the
         * time of the fault..
         */
-       if (in_kernel) {
+       if (!user_mode(regs)) {
+               unsigned char c;
                printk("Stack: ");
                _show_stack(NULL, regs, (unsigned long *)sp, regs->bp);
+               printk("\n");
 
-               printk("\nCode: ");
-               if (regs->ip < PAGE_OFFSET)
-                       goto bad;
-
-               for (i=0; i<20; i++) {
-                       unsigned char c;
-                       if (__get_user(c, &((unsigned char*)regs->ip)[i])) {
-bad:
+               printk(KERN_EMERG "Code: ");
+               if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
+                       /* try starting at RIP */
+                       ip = (u8 *) regs->ip;
+                       code_len = code_len - code_prologue + 1;
+               }
+               for (i = 0; i < code_len; i++, ip++) {
+                       if (ip < (u8 *)PAGE_OFFSET ||
+                                       probe_kernel_address(ip, c)) {
                                printk(" Bad RIP value.");
                                break;
                        }
-                       printk("%02x ", c);
+                       if (ip == (u8 *)regs->ip)
+                               printk("<%02x> ", c);
+                       else
+                               printk("%02x ", c);
                }
        }
        printk("\n");
@@ -571,7 +582,7 @@ int __kprobes __die(const char * str, struct pt_regs * regs, long err)
        add_taint(TAINT_DIE);
        /* Executive summary in case the oops scrolled away */
        printk(KERN_ALERT "RIP ");
-       printk_address(regs->ip, regs->bp);
+       printk_address(regs->ip, 1);
        printk(" RSP <%016lx>\n", regs->sp);
        if (kexec_should_crash(current))
                crash_kexec(regs);
@@ -631,11 +642,14 @@ static void __kprobes do_trap(int trapnr, int signr, char *str,
                tsk->thread.trap_no = trapnr;
 
                if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
-                   printk_ratelimit())
+                   printk_ratelimit()) {
                        printk(KERN_INFO
-                              "%s[%d] trap %s ip:%lx sp:%lx error:%lx\n",
+                              "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
                               tsk->comm, tsk->pid, str,
                               regs->ip, regs->sp, error_code);
+                       print_vma_addr(" in ", regs->ip);
+                       printk("\n");
+               }
 
                if (info)
                        force_sig_info(signr, info, tsk);
@@ -730,11 +744,14 @@ asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
                tsk->thread.trap_no = 13;
 
                if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
-                   printk_ratelimit())
+                   printk_ratelimit()) {
                        printk(KERN_INFO
-                      "%s[%d] general protection ip:%lx sp:%lx error:%lx\n",
+                      "%s[%d] general protection ip:%lx sp:%lx error:%lx",
                               tsk->comm, tsk->pid,
                               regs->ip, regs->sp, error_code);
+                       print_vma_addr(" in ", regs->ip);
+                       printk("\n");
+               }
 
                force_sig(SIGSEGV, tsk);
                return;
@@ -1164,3 +1181,14 @@ static int __init kstack_setup(char *s)
        return 0;
 }
 early_param("kstack", kstack_setup);
+
+
+static int __init code_bytes_setup(char *s)
+{
+       code_bytes = simple_strtoul(s, NULL, 0);
+       if (code_bytes > 8192)
+               code_bytes = 8192;
+
+       return 1;
+}
+__setup("code_bytes=", code_bytes_setup);