Assignment #3 FAQ


We will keep adding relevant questions(and answers) to this page.

General

Do we need a working Lab2 to implement Lab3?
You may find the code for Thread::Join to be useful in implementing the join syscall, but besides that, you can use the original code provided for Lab2.
Why do I get an assertion failure when the Halt system call gets used? Should I fix it?
The assertion that fails checks that a List is empty when it's deleted. This can actually be a useful thing to have, since we don't ever want to lose all pointers to an undeleted object (or delete it twice.) "Halt", however, doesn't clean up nicely--- just deletes the kernel while there may still be threads on the ready queue. This is fine. You can clean up if you want, but there's no need to do so. (I'd recommend _not_ just removing the assert, however.)
Why can't I use "stdio.h" or other C include files in my Nachos programs?
We did not provide a C library for Nachos, so any library functions are undefined. The C library must be built specifically for the operating system (and architecture), since it must make system calls for I/O and memory allocation. (Not all functions do, of course, but usually the library is compiled as a unit.)

Problem 1 & 2

Once we know how to increment the pc, how much should we increment it?
        4. Remember to take care of PCReg, PrevPCReg as well as NextPCReg.
What should I return from a system call in case of an error
Always return a value of -1 if there was an error in processing a system call.
What should I do with the parameter passed to Exit
This value must be returned to the thread's parent when Join is called.
Can I just cast a pointer to an OpenFile object (or pointer to an AddrSpace object) to get a unique OpenFileID (or SpaceID)? It's so much simpler that way!
This is a design decision you will have to make for yourself.


However, note that most operating systems do distinguish between open file ID's (or process ID's) and the addresses of their kernel data structures. You might want to give some thought as to why they do so before committing yourself...

Do we have to synchronize file accesses so that only one process is writing to a file at a time?
No. If you implement this feature, it will be as part of the file system project. (Note that the current stub file system provides read and write atomicity: no write will be interrupted by another write or read.)
Integers passed to system calls appear as expected, but strings (and pointers) seem to be bogus. What's up?
Remeber that any pointers passed in are in the virtual terms of the user program's address space. Remember that the user's memory is simulated by the array mainMemory in the mahine simulator. At first, the addresses passed in can be read directly from this array (since we have an identity mapping). After you implement part 2, you will have to translate the virtual addresses of the program into the physical addresses of this simulated memory.

Problem 3

Specifically, what am I supposed to implement in problem 2?
You must allow each AddrSpace to have its own page table so that multiple programs may be running at the same time. This has already been done for the most part; just use the pageTable that is owned by each address space. In this assignment, you will only need to modify the page tables that each address space already has. You do not need to deal with the TLB at all. The machine will know how to find your page tables, so do not change their format. All you need to do is correctly populate the page table with the translations made when loading the program. Your page table must allow arbitrary translations. You will probably find a system-wide bitmap helpful to determine which physical pages are free. When you load the program in AddrSpace, instead of putting it at a physical page equal to the virtual page, you will find a free page in physical memory to map to that virtual page (with the page table). Be sure to free the physical memory when the address space is done.


Just follow the model of the current implemetation in AddrSpace but use the page table intelligently.

What am I supposed to do about the stack?
Reserve a block of memory of size UserStackSize at the highest part of your virtual address space. It need not grow until the next assignment.
What if a user program causes any non-syscall exceptions?
Simply terminate the program, but do not exit nachos unless it was the last program.