In kern_exec.c
Copy out the strings segment to user space. The strings segment is put on a preinitialized stack frame.
The strings segment layout is backward, from the beginning of the top of the stack to consume the minimal amount of space possible; the returned stack pointer points to the end of the area consumed (stacks grow downward).
argc
is anint
arg[i]
are pointersenv[i]
are pointers- the
0
's are(void *)NULL
's
+-------------+ <- p->user_stack
| 16b |
+-------------+
| STRING AREA |
| : |
| : |
| : |
+- -- -- -- --+
| PATH AREA |
+-------------+
| 0 |
+-------------+
| applev[n] |
+-------------+
:
:
+-------------+
| applev[1] |
+-------------+
| exec_path / |
| applev[0] |
+-------------+
| 0 |
+-------------+
| env[n] |
+-------------+
:
:
+-------------+
| env[0] |
+-------------+
| 0 |
+-------------+
| arg[argc-1] |
+-------------+
:
:
+-------------+
| arg[0] |
+-------------+
| argc |
sp-> +-------------+
Although technically a part of the STRING AREA
,
we treat the PATH AREA
as a separate entity.
This allows us to align the beginning of the PATH AREA
to a pointer boundary
so that the exec_path
, env[i]
, and argv[i]
pointers which preceed it on the stack are properly aligned.