我是Linux的新手,我对sys_execv
功能感到困惑。
据我了解,sys_execv
将使用load_elf_binary
加载新的二进制文件,然后调用start_thread
函数来更新新的pc和spsr。之后,它会跳转到ret_fast_syscall
,然后使用restore_user_regs
,它会返回到用户空间。
但我无法看到任何地方更新用户堆栈。如果没有人更新用户堆栈,它将返回旧用户堆栈位置的用户空间?
我错过了什么吗?
答案 0 :(得分:0)
您错过了内核将内容放在新进程堆栈上的步骤。 格式与此文件https://android.googlesource.com/platform/bionic/+/master/libc/private/KernelArgumentBlock.h
中描述的格式相同 glibc
同样https://github.com/lattera/glibc/blob/master/csu/libc-start.c
这称为'内核参数块',由argc
,argv
,envp
和auxv
组成。
内核使用argc
在http://elixir.free-electrons.com/linux/v4.4/source/fs/exec.c中填充argv
,envp
和copy_strings
。
auxv
在http://elixir.free-electrons.com/linux/v4.4/source/fs/binfmt_elf.c中填写 fill_auxv_note
个值
最后,新进程中的sp
使用http://elixir.free-electrons.com/linux/v4.4/source/arch/arm/include/asm/processor.h#L56中的#define start_thread(regs,pc,sp)
宏设置 - 并使用start_thread(regs, elf_entry, bprm->p);
来自http://elixir.free-electrons.com/linux/v4.4/source/fs/binfmt_elf.c#L1085