1
0
mirror of https://github.com/0xAX/linux-insides.git synced 2024-12-22 14:48:08 +00:00

Merge pull request #509 from diekmann/initial-stack

Improved picture of stack layout
This commit is contained in:
0xAX 2017-09-02 15:34:05 +06:00 committed by GitHub
commit 6037ecc723
2 changed files with 13 additions and 4 deletions

View File

@ -280,19 +280,23 @@ STATIC int LIBC_START_MAIN (int (*main) (int, char **, char **),
It takes the address of the `main` function of a program, `argc` and `argv`. `init` and `fini` functions are constructor and destructor of the program. The `rtld_fini` is the termination function which will be called after the program will be exited to terminate and free its dynamic section. The last parameter of the `__libc_start_main` is a pointer to the stack of the program. Before we can call the `__libc_start_main` function, all of these parameters must be prepared and passed to it. Let's return to the [sysdeps/x86_64/start.S](https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/start.S;h=f1b961f5ba2d6a1ebffee0005f43123c4352fbf4;hb=HEAD) assembly file and continue to see what happens before the `__libc_start_main` function will be called from there.
We can get all the arguments we need for `__libc_start_main` function from the stack. As `_start` is called, our stack looks like:
We can get all the arguments we need for `__libc_start_main` function from the stack. At the very beginning, when `_start` is called, our stack looks like:
```
+-----------------+
| NULL |
+-----------------+
| ... |
| envp |
| ... |
+-----------------+
| NULL |
+------------------
| argv | <- rsp
| ... |
| argv |
| ... |
+------------------
| argc |
| argc | <- rsp
+-----------------+
```
@ -302,11 +306,15 @@ After we cleared `ebp` register and saved the address of the termination functio
+-----------------+
| NULL |
+-----------------+
| ... |
| envp |
| ... |
+-----------------+
| NULL |
+------------------
| argv | <- rsp
| ... |
| argv |
| ... | <- rsp
+-----------------+
```

View File

@ -107,3 +107,4 @@ Thank you to all contributors:
* [Stéphan Gorget](https://github.com/phantez)
* [Adrian Reyes](https://github.com/int3rrupt)
* [JB Cayrou](https://github.com/jbcayrou)
* [Cornelius Diekmann](https://github.com/diekmann)