Assignment 3, due Sept. 7

Part of the homework for 22C:112, Fall 2012
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID and on the class list! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what lawyers call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!

  1. Background: When you call a subroutine in a civilized programming language, for example f(a,b,c,d) it is perfectly reasonable to set things up so that parameter a is a file variable that you have already opened and partially modified, parameter b is a character string, parameter c is an integer, and parameter d is the handle on an object.

    Now suppose you have decided to make f into a program so you can execute it as an application from within shell scripts as well as from other application programs.

    a) Which of the 4 parameters could you pass through to the new version of f() via execve() in essentially the way they were passed in the original. (0.5 point)

    b) Suggest appropriate compromizes that would allow you to pass the information required for the other parameters despite the barriers created by the execve() mechanism. (0.5 point)

    Hint: The key information is all contained in the notes for Friday, Aug. 31.

  2. Background: Some computers have multiple CPUs that execute entirely different instructions sets. For example, the Pr1me computers the University of Iowa had in the 1980s had 16-bit and 32-bit instruction sets with distinctly different memory models. Today, it is possible to imagine a multiprocessor with, perhaps, a mix of Intel x86 and ARM processors with access to a common shared memory.

    A problem: Explain how adding a Unix-style magic number at the head of each object file can be useful in such a system. Your explanation must both identify the system functions that check the magic numbers and what use is made of them. (1 point)

  3. Background Consider this C source file:
        int a;
        static int b;
        int c( int d );
        static int e( int f ) {
                return c( f );
        }
        int g( int h ) {
                return e( h );
        }
    

    A problem: Which of the identifiers above (a through h) are visible to the linker? The others are private symbols known only to the compiler. (1 point)

Machine Problem II

Due Monday, Sep. 19.

Get a copy of the Minimally Usable Shell (Mush) and store it in the file mp2.c. Then, modify it so it conforms to the stylistic requirements set by the Manual of C Style. Note that it is really only the first 7 sections of the manual that apply to this assignment (up to and including the special rules regarding defines.)

In addition, change please eliminate the use of "naked constants" in the code, such as the NUL character, the length of the input command buffer and the length of the argument vector. These constants should be named, using #define. Note that, as originally written, the maximum size of the argument vector is unreasonably large, since it would be impossible to type that many arguments in a line of the maximum length. You should fix this.

Finally, there are numerous places in the original code where it is unsafe -- typing in a line that is too long or a command containing too many arguments will cause it to behave unpredictably. (You might want to try it to see what it does; you may want to set the line limit or the limit on the number of arguments artifically small for this experiment, don't forget to undo that damage.) Fix the code so that if an overlength line is input or if too many arguments are typed, no command is launched and an appropriate error message is output.

Your program header must be edited to include your name as the indicate that it was revised by you to make it conform to the requirements of MP2.

Submit your work using the submit command (as for MP1), but your code should be submitted in the file mp2.c, and it should be submitted in the assignment directory named mp2.