Project 2
CMSC 421, Fall 2004
Points: 75 (65 + 10)
Released on : Sep 30th, 2004
Due
: Oct 20th, 2004
In Project 2, you are required to add a system call to the Linux kernel
and write a small program to test this system call. Before you begin, create a
custom kernel specific for Project 2, starting with a copy of the pristine Linux kernel
linux-2.4.21-20.EL. Name your custom kernel for Project 2 as linux-2.4.21-20.EL-GLUSRNM-project2, where GLUSRNM is your UMBC GL username.
(Replace the "custom" in Makefile by "-GLUSRNM-project2".)
Part 1: Adding system calls to the kernel.
The system call should return 1 if successful or 0 if there is any error.
Note that the variables max_threads and nr_threads are in the kernel space;
where as, the arguments of the system call are addresses in the user-space
where it needs to put the information.
Make sure that your system calls have exactly the same signatures as
above, (since otherwise our test programs will fail!) Function/variable names
are case sensitive. Any kernel panics/failures will result in a very
substantial reduction of points. Please go through the hints and pay particular
attention to functions you use to copy to/from user/kernel spaces.
Please have
the implementation of the system call in separate files.
Part 2: User mode driver and test programs
Write a user mode driver program (driver.c and driver.h) to demonstrate
that your system call works correctly. Note that you should use your own
test program to test your system calls, to ensure that they work as specified
and they can handle all kinds of (good and bad) inputs.
Hints
- Linux
Resources
- Linux source code navigation can be found at http://lxr.linux.no/source.
This allows you browse through the kernel sources, search for where
variables/identifiers/functions are defined/used, etc.
- How to add Linux System Calls:
- Refer to LKP, section 3.3.
- Recall that a system call is a software trap or interrupt. This means that
when adding a new system call, you will need to update the system calls
table (i.e. the interrupt vector) with new entry/entries, and generate
stub(s) that will be used by user programs. Look for files arch/i386/kernel/entry.S
and inlude/asm/unistd.h, and look for the macros _syscall1 and _syscall2.
- In the critical section of the code you write (e.g. when you access the
new kernel variables), you should try to avoid any race conditions, perhaps
by disabling and enabling the interrupts.
- You will need to dereference a user space pointer in the kernel when
trying to pass a value back in the argument of some of your functions. You
may want to look at the functions copy_to_user(), copy_from_user(), strncpy_user(), strnlen_user(), etc for
help with this.
What to submit
Create and submit a single compressed tar file project2.tar.gz (created
using the Linux tar and gzip commands) via blackboard. It should contain the following
- A Project Report describing your detailed approach in solving this
assignment, (what did you do? how did you do it? why did you follow that
approach? etc). The Project Report is an IMPORTANT component of your
overall project. Follow the guidelines in System
Design Document Template for preparing your project report. The Project
report must be a single PDF file with filename "project2report.pdf";
Yes! this is CASE-SENSITIVE and NO EXCEPTIONS!.
The Project Report carries 10 out of the 75 points for Project 2.
- The patchfile patchPrj2.diff for your changes to the kernel source. As
always, it is a good idea to verify that the patch is correct. A bad patch
file may not patch properly and we may not be able to compile your kernel to
evaluate it.
- All of your source code and header files (for the functions you developed
and test programs). These could be separate files or be part of existing
kernel files.
- The updated entry.S, unistd.h and kernel Makefile
- The driver program(s) (driver.c and driver.h files) and the Makefile to
compile the driver program.
- Sample output showing the execution of your driver program (this can be
obtained by running the "script" command and submitting the file
"typescript" generated as output by script.
- A README file (explaining how to compile/run your program)