“xalloc” is called by “exec” (3130), when a new program is being initiated, to handle the allocation of, or linking to, the text segment. The argument, “ip”, is a pointer to the “mode” of the code file. At the time of this call, “u.u_arg[1]” contains the text segment size in bytes.
If there is no text segment, return immediately;
Look through the “text” array for both an unused entry and an entry for the text segment. If the latter can be found, do the bookkeeping and go to “out” (4474);
Arrange to copy the text segment into the disk swap area. Initialise the unused text entry, and get space in the disk swap area;
Change the space occupied by the process to one large enough to contain the “per process data” area and the text segment;
The call on “estabur” is necessary to set the user mode segmentation registers before reading the code file;
A UNIX process can only initiate one input/output operation at a time. Hence it is possible to store i/o parameters at standard locations in the “u” structure, viz. “u.u_count”, “u.u_offset[ ]” and “u.u_base”;
The octal value 020 (decimal 16) is an offset into the code file;
Information is to be read into the area beginning at location zero in the user address space;
Read the text segment part of the code file into the current data segment;
“Swap out” the data segment (minus the “per process data”) into the disk swap area reserved for the text segment;
“Shrink” the data segment – it is about to be swapped out;
“sched” always “swaps in” the text segment before the data segment i.e. there is no mechanism for bringing the text segment into main memory once the data segment is present. If the text segment is not in main memory, get back into step by “swapping out” the data segment to disk.
It will be noted that the code to handle text segments is very conservative whenever the situation starts to get complicated. For example, the “panic” (4451) when no more text entries are available would seem to be a rather extreme reaction. However the strategy of being generous with “text” array space is quite likely to be less expensive than the code needed to do “better”. What do you think?