所以我最近发现有一个HLT
用于停止 CPU的操作码。酷,让我们看看会发生什么!
user@box:~$ cat > test.c
int main(void)
{
__asm__("HLT");
return 0;
}
user@box:~$ gcc -o test test.c
user@box:~$ ./test
Segmentation fault (core dumped)
user@box:~$
Run Code Online (Sandbox Code Playgroud)
呸!多么无聊。
原来HLT
是一个特权指令,所以让我们尝试别的东西。
user@box:~$ mkdir test; cd test
user@box:~/test$ cat > test.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
int init_module(void)
{
__asm__("hlt");
return 0;
}
void cleanup_module(void)
{
}
user@box:~/test$ echo obj-m += test.o > Makefile
user@box:~/test$ make -C /lib/modules/$(uname -r)/build modules M=$(pwd)
[...]
user@box:~/test$ sudo insmod test.ko
user@box:~/test$
Run Code Online (Sandbox Code Playgroud)
没发生什么事!无聊的!
事实证明,HLT …