Due: TBA
This assignment should be done in groups of 2 or 3 people.
Part 1: Add a
new system call
There are four system calls in Linux related to creating new
processes: fork, vfork, execve, and clone. (The man pages will describe
for you the differences among them.) Instrument the kernel to keep track
of the number of times each of these four system calls has been invoked and
write a user-level C program that will print counts of the number of times each
of them has been invoked (by any process on the system).
To do this requires three things:
Modify the kernel to keep track of this information.
Design and implement a new system call that will get this data back to the user application.
Write the user application.
We'd also like to be able to reset these statistics periodically. So we need a way to clear the request information we've tracked so far. This requires either parameterizing the above system call to add a clear option, or adding another system call.
There are several different ways to approach this problem. It is your job to analyze them from an engineering point-of-view, determine the trade-offs, and to explain the implementation you select.
Warning 1: Remember that the Linux kernel should be allowed to access any memory location, while the calling application should be prevented from causing the kernel to unwittingly read/write addresses other than those in its own address space. Details about this are here.
Warning 2 (Hint 0): Remember that it's inconceivable that this problem (warning 1) has never before been confronted in the existing kernel.
Warning 3: Remember that the kernel must never, ever trust the application to know what it's talking about when it makes a request, particularly with respect to parameters passed in from the application to the kernel.
Warning 4: Remember that you must be sure not to create security holes in the kernel with your code.
Warning 5: Remember that the kernel should not leak memory.
You should be using the C language whenever you alter or add to the Linux kernel.
You can't just make system calls directly from C. Instead, you need to use the syscall function and pass it the number of your new system call. The following code fragment show you how to do that:
/*
* Set the features included by the linux libc to have the BSD extensions
*/
#ifndef _BSD_SOURCE
#define _BSD_SOURCE 1
#endif
#define _NR_execcounts something
#include <unistd.h>
...
int ret = syscall(__NR_execcounts, ...);
Here’s a suggested set of incremental steps for completing this assignment:
Now implement a parameter-less system call, whose body is just a printk() call. Write a user-level routine that invokes it. Check to make sure it was invoked.
Now write the full implementation.
Part 2: Integrate the
system call into the shell
Now that you have a working shell (from assignment 1) and an implementation of your new system call, it's time to integrate them; this should be very simple. Add a new internal command to your shell, called execcounts. The execcounts command should invoke the system call that you build in Part 2, and print out:
Part 3:
Some additional questions
Answer these additional questions and include
them with your write-up:
1) What is "asmlinkage" as it occurs
in the Linux kernel source, what does it do (give a short description)?
2) What is the difference between the "clone" and "fork"
system calls?
3) How long does your new system call take (time it using gettimeofday
and give an approximate answer)? Explain your timing methodology.
What to Turn In
You should turn in the following:
Describe how you found the information needed to complete this project. Did it have the information you needed? Did you consult with any humans? If so, what did you try first and who did you consult with?
Explain the calling sequence that makes your system call work. First, a user program calls <.....>. Then, <.....> calls <.....>. ... and so on. You can explain this using either text or a rough (less than 15 minutes) diagram.
Why do you think the designers of Linux implemented system calls the way they did? What were they trying to achieve? What were they trying to avoid?
Give (in 1-2 sentences) an alternative idea for implementing system calls. State one way your idea would be better or worse than the way it is currently done.
Do not underestimate the importance of the write-up. Your project grade depends significantly on how well you understood what you were doing, and the write-up is the best way for you to demonstrate that understanding.
Submission instructions: We will be using the submit program.