unsigned long start, stop;
register unsigned long sp asm ("sp");
start = sp;
这行代码说明了sp
没有初始化的声明变量。
不同的体系结构为堆栈指针使用不同的寄存器。这是一个示例(linux + elf)_start函数来演示:
//unfortunately gcc has no builtin for stack pointer, so we use assembly
#ifdef __x86_64__ || defined __i386__
#define STACK_POINTER "esp"
#elif defined __aarch64__
#define STACK_POINTER "x13"
#elif defined __arm__
#define STACK_POINTER "r13"
#endif
char **environ;
void exit(int);
int main();
void _start(void){
register long *sp __asm__( STACK_POINTER );
//if you don't use argc, argv or envp/environ, you can just remove them
long argc = *sp;
char **argv = (char **)(sp + 1);
environ = (char **)(sp + argc + 1);
exit(main(argc, argv, environ) );
__builtin_unreachable(); //or for(;;); to shut up gcc
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句