繁体   English   中英

来自 Linux 内核模块的暂停指令不起作用

[英]Halt instruction from Linux kernel module is not working

我写了一个简单的 Linux 内核模块来发出hlt指令

#include <linux/kernel.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");
static int __init test_hello_init(void)
{
    asm("hlt");
    return 0;
}

static void __exit test_hello_exit(void)
{
}

module_init(test_hello_init);
module_exit(test_hello_exit);

在我的虚拟机上加载这个模块,我没有看到我的虚拟机停止了。

我错过了什么吗?

HLT不会停止您的机器,只会让内核休眠(在 C1 中空闲)直到下一个中​​断。

您可以尝试在hlt之前添加cli指令,这样只有 NMI 才能唤醒该 CPU 并使函数返回。

static int __init test_hello_init(void) {
    asm("cli");
    asm("hlt");
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM