Re: BUG() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



liang yuanen wrote:

what this(0x0f,0x0b) mean in BUG() function?
__asm__ __volatile__(".byte 0x0f,0x0b");

It is an invalid instruction.

This means the CPU will throw an invalid opcode exception.

In arch/i386/kernel/entry.S:

ENTRY(invalid_op)
        RING0_INT_FRAME
        pushl $0
        CFI_ADJUST_CFA_OFFSET 4
        pushl $do_invalid_op
        CFI_ADJUST_CFA_OFFSET 4
        jmp error_code
        CFI_ENDPROC

In arch/i386/kernel/traps.c you will find the following magic:

DO_ERROR_INFO( 6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->eip)

#define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \
fastcall void do_##name(struct pt_regs * regs, long error_code) \
{ \
        siginfo_t info; \
        info.si_signo = signr; \
        info.si_errno = 0; \
        info.si_code = sicode; \
        info.si_addr = (void __user *)siaddr; \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
                                                == NOTIFY_STOP) \
                return; \
        do_trap(trapnr, signr, str, 0, regs, error_code, &info); \
}

The do_trap function will find out that the trap happened in kernel
mode, and does not have an exception fixup.

        kernel_trap: {
                if (!fixup_exception(regs))
                        die(str, regs, error_code);
                return;
        }

That in turn means that the current thread dies, printing a
pretty register dump and stack trace before it goes.  The die()
function has some magic of its own, which I won't go into here.


--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux