0% found this document useful (0 votes)
6 views2 pages

UNIX

Unix Class Notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

UNIX

Unix Class Notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
1S INVOKING OTHER PROGRAMS, 29 Magic Number Number of Sections Initial Register Values ection Type Section Size Virtual Address tion Type Section Size Virtual Address Primary Header Section 1 Header Scction 2 Header Section Virtual Address Section n Header Section | Data (e.g. text) Section 2 Data Section n Data Other Information Figure 7.20. Image of an Executable File Specific formats have evolved through the years, but all executable files have contained a primary header with a magic number. The magic number is a short integer, which identifies the file as a load module and enables the kernel to distinguish run-time characteristics about it. For example, use of particular magic numbers on a PDP 11/70 informed the kernel that processes could use up to 128K bytes of memory instead of 64K bytes,” but the magic number still plays an important role in paging systems, as will be seen in Chapter 9. 2. The values of the magic numbers were the values of PDP 11 jump instructions; original versions of the system executed the instructions, and the program counter jumped to various locations depending ‘on the size of the header and on the type of exccutable file being executed! This feature was no Tonger in use by the time the system was written in C. 220 PROCESS CONTROL At this point, the kernel has accessed the inode for the executable file and has verified that it can execute it. It is about to free the memory resources that currently form the user-level context of the process. But since the parameters to the new program are contained in the memory space about to be freed, the kernel first copies the arguments from the old memory space to a temporary buffer until it attaches the regions for the new memory space. Because the parameters to exec are user addresses of arrays of character strings, the kernel copies the address of the character string and then the character strmg to kernel space for cach character string. It may choose several places to store the character strings, dependent on the implementation. The more popular places are the kernel stack (a local array in a kernel routine), unallocated areas (such a pages) of memory that can be borrowed temporarily, ar secondary memory such as a swapping device. The simplest implementation for copying parameters to the new user-level context is to use the kernel stack. But because system configurations usually impose a limit on the size of the kernel stack and because the exec parameters can have arbitrary length, the scheme must be combined with another. Of the other choices, implementations use the fastest method. If it is easy to allocate pages of memory, such a method is preferable since access to primary memory is faster than access to secondary memory (such as a swapping device). After copying the exec parameters to a holding place in the kernel, the kernel detaches the old regions of the process using algorithm detachreg. Special treatment for text regions will be discussed later in this section. At this point the Process has no user-level context, so any errors that it incurs from mow on result in its termination, caused by a signal. Such errors include running out of space in the kernel region table, attempting to load a program whose size exceeds the system limit, attempting to load a program whose region addresses overlap, and others. The kernel allocates and attaches regions for text and data, loading the contents ff the executable file into main memory (algorithms allocreg, attachreg, and loadreg). The data region of a process is (i lly) divided into two parts: data initialized at compile time and data not initialized at compile time (“bss”). ‘The initial allocation and attachment of the data region is for the lized data. The kernel then increases the size of the data region using algorithm growreg for the “bss” data, and initializes the value of the memory to 0. Finally, it allocates a region for the process stack, attaches it to the process, and allocates memory to store the exec parameters. If the kernel has saved the exec parameters in memory pages, it can use those pages for the stack. Otherwise, it copies the exec parameters to the user stack. The kernel clears the addresses of user signal catchers from the u area, because those addresses are meaningless in the new user-level context. Signals that are ignored remain ignored in the new context. Then the kernel sets the saved register context for user mode, specifically setting the initial user stack pointer and program counter: The loader had written the initial program counter in the file header. The kernel takes special action for setuid programs and for process tracing, covered in

You might also like