Homework 6 Solutions

22C:116, Spring 1995

Douglas W. Jones

  1. The problem, part A: Write code (in the language of your choice, as long as it's C or Pascal), to implement the following:
    function viewuser( address, length, startpage )
      numpages := pagenum(address+length-1) - pagenum(address) + 1;
      for i := 0 to numpages-1 do
        map[system][startpage+i] = map[user][page(address)+i];
      return makeaddr(startpage,offset(address));
       
    

    The problem, part B: After a system call, the first parameter on the stack top is the address of a buffer and the second parameter on the stack top is the length of the buffer. Write code using the viewuser function to map the user's buffer into the system's address space and return a pointer to it.

      userstack := viewuser( usersp, (usersp-userfp)+1, systop );
      bufpointaddr := userstack + (usersp-userfp)-1;
      buflenaddr := userstack + (usersp-userfp)-2;
      bufpoint := bufpointaddr^;
      buflen := buflenaddr^;
      bufferaddr := viewuser( bufpoint, buflen, systop );
    
  2. The problem: Design a capability-based directory structure that results in the same access matrix, at least for the leaf files in the directory structure. Furthermore, your capability list based solution should give each user substantially the same rights, as regards to controlling public access to objects owned by that user.
        Jones C-list
          grades   rw ----------->file
          /export  rw ----------->C-list<---------------.
          handout  rw -----.        handout r --->file   \
          /bin     r  ---.  `------------------'          |
          /public  r  -.  \                               |
                        \  \                              |
        Smith C-list     |  |                             |
          homework rw ---+--+---->file                    |
          /export  rw ---+--+---->C-list<-------------.   |
          project  rw ---+--+-.     project r --->file \  |
          /bin     r  ---+. |  `---------------'        | |
          /bin     r  -. | \|                           | |
                        \|  \                           | |
        Root C-list      |   \                          | |
          /bin     rw ---+------->C-list                | |
          ls       rx ---+----.     ls  r ---->file     | |
          cat      rx ---+--.  \    cat r -./           | |
          /public  rw -. |   \  `----------'\           | |
                        \|      `--------------->file  / /
                         `------->C-list              / /
                                    smith r ---------' /
                                    jones r ----------'