0

I'm trying to understand how the stack behaves when you use system call execve to call a new function.

I understand there should be variables argc, argv and envp. The last two should be pointers to the vectors containing the arguments and the environment. Those vectors are also in the stackframe.

I'm trying to understand what else might be in the stackframe. Specifically: Does it follow any know calling convention? Is there a return address? Does it store the old stackpointer, as a function would?

user2506946
  • 131
  • 9

1 Answers1

0

According to the Linux man page:

execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded.

So, no, there is no return address, stack frame, etc.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • As far as I understand, there is a stackframe, where it passes the arguments, but you seem to be right about thee return address. – user2506946 Sep 16 '19 at 15:03
  • @user2506946 It depends on when you're looking. Immediately after the call is made to `execve`, there is a full stack frame with parameters and return address. And that stack frame probably exists while `execve` is executing. But once that function makes the system call to execute the new program, the entire stack frame is overwritten. – Jim Mischel Sep 16 '19 at 15:28
  • Yes. I was talking about the stackframe that `execve` creates. In an architecture like x86 32bit, execve needs to put the arguments in a stack before the main starts, right? I was curious to what else was on tat stack. – user2506946 Sep 16 '19 at 18:18
  • 1
    @user2506946 You could always look at the source code: https://stackoverflow.com/questions/4689724/where-do-i-find-the-source-code-for-execve – Jim Mischel Sep 16 '19 at 19:35