小编sec*_*pow的帖子

当我在 Linux 系统上运行“cli; hlt”时实际发生了什么?

所以我最近发现有一个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 …

linux assembly

18
推荐指数
1
解决办法
2614
查看次数

标签 统计

assembly ×1

linux ×1