什么是默认的寄存器状态时,程序启动(ASM,LINUX)? [英] What is default register state when program launches (asm, linux)?
问题描述
在程序启动(Linux中,小精灵) - 有在 EAX
, EBX
零等,或有可以是任何东西(我没有做任何电话或使用的extern libraryies)?在我的机器真是这样,我可以这样写行为ASM programms的时候继电器?
When the program launches (linux, elf) - is there zeros in eax
, ebx
, etc. or there can be anything (i'm not doing any calls or using extern libraryies)? On my machine it is really so, can I relay on such behavior when writing asm programms?
推荐答案
这在ABI完全取决于每个平台。既然你提到 EAX
和 EBX
让我们来看看有什么针对x86的情况。在 FS / binfmt_elf.c
线#972,在 load_elf_binary()
,内核会检查ABI指定任何< A HREF =http://lxr.linux.no/#linux+v3.2.4/fs/binfmt_elf.c#L972>要求在程序加载了解寄存器的值:
This depends entirely on the ABI for each platform. Since you mention eax
and ebx
let's see what's the case for x86. In fs/binfmt_elf.c
line #972, inside load_elf_binary()
, the kernel checks if the ABI specifies any requirements for register values at program loading:
/*
* The ABI may specify that certain registers be set up in special
* ways (on i386 %edx is the address of a DT_FINI function, for
* example. In addition, it may also specify (eg, PowerPC64 ELF)
* that the e_entry field is the address of the function descriptor
* for the startup routine, rather than the address of the startup
* routine itself. This macro performs whatever initialization to
* the regs structure is required as well as any relocations to the
* function descriptor entries when executing dynamically links apps.
*/
然后调用 ELF_PLAT_INIT
,这是每个架构中定义的宏弓/ XXX /有/ elf.h中
。对于x86,它下面中的:
It then calls ELF_PLAT_INIT
, which is a macro defined for each architecture in arch/xxx/include/elf.h
. For x86, it does the following:
#define ELF_PLAT_INIT(_r, load_addr) \
do { \
_r->bx = 0; _r->cx = 0; _r->dx = 0; \
_r->si = 0; _r->di = 0; _r->bp = 0; \
_r->ax = 0; \
} while (0)
所以,当你的ELF二进制文件被加载在Linux x86,你也不能指望所有的寄存器的值等于零。但这并不意味着你应该,虽然。 : - )
So, when your ELF binary is loaded on Linux x86, you could count on all register values being equal to zero. Doesn't mean you should, though. :-)
这篇关于什么是默认的寄存器状态时,程序启动(ASM,LINUX)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!