14 linux assembly elf cpu-registers
当程序启动(Linux中,小精灵) -有归零的eax,ebx等等,或可以有任何东西(我没有做任何电话或使用的extern libraryies)?在我的机器上真的如此,在编写asm程序时我可以继续这种行为吗?
Mic*_*kis 19
这完全取决于每个平台的ABI.既然你提到eax并ebx让我们看看x86是什么情况.在fs/binfmt_elf.c第972行内部load_elf_binary(),内核检查ABI是否在程序加载时指定了对寄存器值的任何要求:
/*
* 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.
*/
Run Code Online (Sandbox Code Playgroud)
然后调用ELF_PLAT_INIT,这是为每个体系结构定义的宏arch/xxx/include/elf.h.对于x86,它执行以下操作:
#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)
Run Code Online (Sandbox Code Playgroud)
因此,当您的ELF二进制文件在Linux x86上加载时,您可以指望所有寄存器值等于零.但这并不意味着你应该这样做.:-)
x86-64 System V ABI第3.4.1节"初始堆栈和寄存器状态"(Basile链接到PDF):
%rsp 指向堆栈
堆栈指针保存具有最低地址的字节的地址,该地址是堆栈的一部分.保证在进程输入时对齐16字节
%rdx 应用程序应该使用atexit注册的函数指针,如果它不为零.
应用程序应注册的函数指针
%rbp 未指定,但userland应将其设置为基础框架.
在进程初始化时未指定该寄存器的内容,但用户代码应通过将帧指针设置为零来标记最深的堆栈帧.
其他一切都未定义.
然后Linux跟随它"因为" LSB这么说.
| 归档时间: |
|
| 查看次数: |
2867 次 |
| 最近记录: |