This system call, #11, changes a process executing one program into a process executing a different program. See Section “EXEC(II)” of the UPM. This is the longest and one of the most important system calls.
“namei” (6618) (which is discussed in detail in Chapter 19) converts the first argument (which is a pointer to a character string defining the name of the new program) into an “inode” reference. (“inodes” are essential parts of the file referencing mechanism.);
Wait if the number of “exec”s currently under way is too large (See the comment on line 3011.);
“getblk(NODEV)” results in the allocation of a 512 byte buffer from the pool of buffers. This buffer is used temporarily to store in core, that information which is currently in the user data area, and which is needed to start the new program. Note that the second argument in “u.u_arg” is a pointer to this information;
“access” returns a non-zero result if the file is not executable. The second condition examines whether the file is a directory or a special character file. (It would seem that by making this test earlier, e.g. just after line 3036, the efficiency of the code could be improved.);
Copy the set of arguments from the user space into the temporary buffer;
If the argument string is too large to fit in the buffer, take an error exit;
If the number of characters in the argument string is odd, add an extra, null character;
The first four words (8 bytes) of the named file are read into “u.u_arg”. The interpretation of these words is indicated in the comment beginning on line 3076 and, more fully, in the section “A.OUT(V)” of the UPM.
Note the setting of “u.u_base”, “u.u_count”, “u.u_offset” and “u.u_segflg” preparatory to the read operation;
If the text segment is not to be protected, add the text area size to the data area size, and set the former to zero;
Check whether the program has a “pure” text area, but the program file has already been opened by some other program as a data file. If so, take the error exit;
When this point is reached, the decision to execute the new program is irrevocable i.e. there is no longer the opportunity to return to the original program with an error flag set;
“expand” here actually implies a major contraction, to the “per process data” area only;
“xalloc” takes care of allocating (if necessary) and linking to the text area;
The information stored in the buffer area is copied into the stack in the user data area of the new program;
The locations in the kernel stack which contain copies of the “previous” values of the registers in user mode are set to zero, except for r6, the stack pointer, which was set at line 3155;
Decrement the reference count for the “inode” structure;
Release the temporary buffer;
Wake up any other process waiting at line 3037.