OSDEV - Command Line Arguments: Under The Hood

1. the shell splits the command line in chunks of strings (limited by '\0') and stores the adress in the argv array.

2. then, upon calling execve, I pass the argv array as well as the name of the executable.

3. the execve interface counts the number of args stored in argv and calls do_execve (the work horse), which builds a stack image:

4. do_execve makes some sanity checks: is nr of args < 60, and is commandline < 1024 f. ex. then, it allocates some memory on the heap and starts building a stack image: first, the argv_array: the adresses there are replaced by offsets of the start of the corresponding argument to the start of the stack image. then, a zero is added to the argv array. After that, each string adressed in the passed argv array is copied to the stack image - directly after the argv.

5. Upon performing the actual exec, mmsrv copies the stack image from the process to an internal buffer and performs the following:



6. This image, you copy into the process stack area.

7. Upon process startup, you have a stub in asm, which first saves the according pointers (esp, esp+4) in registers - to push them prior to call to int main(argc,argv);