Programming Assignment 4
CS 30200 / ECE 46810
Operating Systems
Spring, 2021

This assignment makes use of the files contained in this zip file. This assignment is due Monday, May 3.

For this assignment you will write a program that performs virtual memory operations. You will run the program along with a virtual memory mapping program so that you can watch the virtual memory operations take place.

Complete the program that is outlined in the file VMdriver.c from the zip file. Create a text file, called VMcmds.txt, with commands to exercise your virtual memory operations. The form of the command file is described in the comments of VMdriver.c. A simple version of VMcmds.txt is contained in the zip file. Your command file should demonstrate all of the commands described in the comments of VMdriver.c. Be sure to create a command file that really tests your version of VMdriver.c. Test your program in a console window using a command of the form

   C:\VMdriver.exe < VMcmds.txt

Notice that VMdriver.exe should read memory commands from stdin.

Your VMdriver.exe program should create a process from the program VMmapper.exe. The VMmapper.exe process will display a memory map of the VMdriver.exe process as it is running so that you can see the virtual memory operations take place in the VMdriver.exe virtual address space. The source code file, VMmapper.c, is included in the zip file, but you do not (and should not) need to make any changes to it.

The VMmapper.exe gives you a real time display of the virtual memory map of any 32-bit program. VMmapper.exe takes a command-line argument that is the PID (process ID number) of a 32-bit process. Remember that Task Manager will will give you the PID of any process. Task Manager will also tell you which processes are 32-bit and which are 64-bit; in Task Manager's "Detail" tab, select the column called "Platform". In the WIndows folder called "C:\Windows\SysWOW64" there is a collection of 32-bit Windows programs. In particular, there are 32-bit version of cmd.exe and notepad.exe. You can use these to experiment with VMmapper.exe.

In the zip file there is a demo version, VMdriver-demo.exe, that you can run to see how your program should work. You can run the demo version in interactive mode by just double-clicking on VMdriver-demo.exe. You should experiment with the demo program because it allows you to test a lot of ideas about virtual memory. The demo program will launch the VMmapper.exe program on itself so that you can watch as each memory operation that you request takes place. When practicing memory operations, it's a good idea to find a big "empty" region of the virtual memory space to work within. If you scroll up and down the console window for VMmapper.exe, you should see a "free" region of memory labeled as ****FREE**** (in red text). This is a free region of memory that is at least 1GB in size. The VMdriver-demo.exe program is not a large program, so it uses only a tiny fraction of its virtual memory space. Since VMdriver-demo.exe is a 32-bit program, it has a 4 GB virtual address space, but half of this is given to the OS, so VMdriver-demo.exe has 2 GB of user virtual address space. Most of this is "empty" and Windows makes most of the empty space contiguous in one big free block of virtual memory. The red ****FREE**** label denotes this huge free block. (NOTE: If you run the demo program several times, you will notice that the exact location of this huge empty region changes. This is due to a security feature called Address Space Layout Randomization (ASLR).)

In the zip file there is also a copy of the VMMap.exe program from Microsoft. This is a much more sophisticated memory mapping program than VMmapper.exe. When you run the demo program (or your own version of VMdriver.exe) you can simultaneously run VMMap.exe and get two views of the same virtual memory space. After you run VMdriver-demo.exe (or your VMdriver.exe), double click on VMMap.exe and choose the VMdriver-demo.exe process (or your VMdriver.exe process) from the pop-up list. Compare the output from VMMap.exe and VMmapper.exe. For the most part they are the same, but VMMap.exe contains quite a bit more detail than VMmapper.exe. (One disadvantage of VMMap.exe is that it does not automatically refresh its memory map. You need to select the "View -> Refresh" menu item.) Also, you might notice that some regions denoted as "free" by VMmapper.exe are denoted as "Unusable" by VMMap.exe. Needless to say, VMMap.exe is right, and these regions are not really free (there is a bit of an explanation for this discrepancy in this article).

When you are done with your version of VMdriver.c, here are some questions that you should think about. To answer these questions, you need to use your version of VMdriver.exe (or the demo version), the VMmapper.exe program, and you may need to use other programs that let you observe virtual memory (like TaskManager or one of the demo programs we used in class).

Here are a couple of comments about the VMmapper.exe program. When VMmapper.exe detects a runtime error, it prints an error message to the console window and it also pops up a MessageBox. Sometimes these MessageBoxes are useful and sometimes they are annoying. If you find the popup MessageBoxes too annoying, you can comment out line 382 of VMmapper.c and then recompile the program.

Don't resize the console window that VMmapper.exe runs in. Before Windows 10, console windows were not re-sizable. The VMmapper.exe program does not respond well to its console window being resized. If you get repeated error messages from the VMmapper.exe program, please let me know (and if you can figure out how to fix this bug in VMmapper.exe, please do so and let me know how).

Turn in a zip file called CS302Hw4Surname.zip (where Surname is your last name) containing your version of VMdriver.c and your command file VMcmds.txt.

This assignment is due Monday, May 3.

Here are links to some Windows API documentation that you might need to use in this assignment.