How to generate a kernel or panic failure in Linux kernel code?

How can I generate a kernel or crash in the kernel code? Is there a function for this?

+4
source share
2 answers

The usual way to collapse the kernel is with a macro BUG(). There's also a WARN()macro that drops the stack to the console, but the kernel continues to work.

http://kernelnewbies.org/FAQ/BUG

, BUG() ( ) - (, ) panic_on_oops. 0, โ€‹โ€‹ ( - ). 1, โ€‹โ€‹ .

โ€‹โ€‹ , <SysRq> + <c> (, , echo c > /proc/sysrq-trigger). (http://code.metager.de/source/xref/linux/stable/drivers/tty/sysrq.c#134):

static void sysrq_handle_crash(int key)
{
    char *killer = NULL;

    panic_on_oops = 1;  /* force panic */
    wmb();
    *killer = 1;
}

, , .

+6

Source: https://habr.com/ru/post/1539360/


All Articles