当在
Linux / i386系统上看到由gcc生成的精灵可执行文件时,似乎在调用“main”之后,在“nop”填充之前,它会放置一个停止指令(0xf4),例如:
│ ....... ! entrypoint: │ ....... ! xor ebp,ebp │ 80482e2 ! pop esi │ 80482e3 ! mov ecx,esp*emphasized text* │ 80482e5 ! and esp,0fffffff0h │ 80482e8 ! push eax │ 80482e9 ! push esp │ 80482ea ! push edx │ 80482eb ! push __libc_csu_fini │ 80482f0 ! push __libc_csu_init │ 80482f5 ! push ecx │ 80482f6 ! push esi │ 80482f7 ! push main │ 80482fc ! call wrapper_804a004_80482c4 │ 8048301 ! hlt <--- halt instruction │ 8048302 ! nop │ 8048303 ! nop │ 8048304 ! nop
这是什么目的?
不应该达到此代码.这是一种保障措施吗?
解决方法
主要返回后,退出将被调用.如果系统的退出版本没有立即停止该进程的执行,那么hlt就是这样.在用户模式下,会导致保护故障,这将导致进程死机.如果进程由于某种原因在环0中运行,则只会停止处理器直到下一个中断,这将有助于触发操作系统删除进程.在设计为在环0中运行的进程中,通常在hlt之后有一个jmp指令,这将导致hlt一直执行,直到进程终止.