The Journey Before main()
> The Journey Before main()_ October 25, 2025 · Amit Prasad A while back, I worked on a RISC-V-based userspace simulator for fun. In doing so, taught myself a lot more than I wanted to know about what happens in-between when the Kernel is asked to run a program, and when the first line of our program’s main function is actually executed. Here’s a summary of that rabbit hole. In the beginning… First question: When is the OS kernel actually asked to run any program? The answer, at least on Linux, is the execve system call (“syscall”). Let’s take a quick look at that: int execve(const char *filename, char *const argv[], char *const envp[]); This is actually quite straightforward! We pass the name of the exectuable file, a list of arguments, and a list of environment…