我写了一个简单的 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;
}
关于c - 来自 Linux 内核模块的暂停指令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59561259/