Question: Objectives In this assignment, you will learn how to: add a system call to xv6 add a user level program to xv6 (for testing purposes)

Objectives

In this assignment, you will learn how to:

add a system call to xv6

add a user level program to xv6 (for testing purposes)

navigate the x86 paging structures in order to translate virtual to physical addresses

Exercise 1: The getcount system call (15 points)

The first system call you'll add is one we'll name getcount, which, when passed a valid system call number (listed in the file "syscall.h") as an argument, will return the number of times the referenced system call was invoked by the calling process.

E.g., the following test program:

#include "types.h" #include "user.h" #include "syscall.h" int main(int argc, char *argv[]) { printf(1, "initial fork count %d ", getcount(SYS_fork)); if (fork() == 0) { printf(1, "child fork count %d ", getcount(SYS_fork)); printf(1, "child write count %d ", getcount(SYS_write)); } else { wait(); printf(1, "parent fork count %d ", getcount(SYS_fork)); printf(1, "parent write count %d ", getcount(SYS_write)); } printf(1, "wait count %d ", getcount(SYS_wait)); exit(); } 

should produce the following output (note that each character is output with a separate call to write in xv6):

initial fork count 0 child fork count 0 child write count 19 wait count 0 parent fork count 1 parent write count 41 wait count 1 

Hints

You will need to modify a number of different files for this exercise, though the total number of lines of code you'll be adding is quite small. At a minimum, you'll need to alter syscall.h, syscall.c, user.h, and usys.S to implement your new system call (try tracing how some other system call is implemented, e.g., uptime, for clues). You will likely also need to update struct proc, located in proc.h, to add a syscall-count tracking data structure for each process. To re-initialize your data structure when a process terminates, you may want to look into the functions found in proc.c.

Chapter 3 of the xv6 book contains details on traps and system calls (though most of the low level details won't be necessary for you to complete this exercise).

Testing

To test your implementation, you'll run the getcount executable (when booted into xv6), which is based on the program above. Because the program depends on your implementation, however, it isn't compiled into xv6 by default. When you're ready to test, you should uncomment the line in the Makefile following the UPROGS declaration that builds getcount (delete the '#' character in front of the string "_getcount").

Note that while getcount only prints out counts for three different system calls, your implementation should support all the system calls listed in syscall.h. Feel free to add tests to the test program, located in getcount.c, for other system calls.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!