CS 111 - Project 2 - Spring 2004
System Call
- All Parts:
- pages 107 - 118 in Kernel Projects for Linux by G. Nutt.
- Tweak:
- Traversal of the task list
- Due date:
- Thursday 05/06/2004 by 22:00 (10:00pm)
Description of tweak, implementation details, and examples
- You must use a stock 2.4.26 kernel. On campus get it here:
ftp://ftp.linux.ucla.edu/kernel/v2.4/linux-2.4.26.tar.bz2
Off campus get it here: http://ftp-mirror.internap.com/pub/linux/kernel/v2.4/linux-2.4.26.tar.bz2
- Your system call, instead of taking in a flag and a struct pointer (as
in the lab manual description), will take two arguments: an array of
processes ids (of type pid_t) terminated by a null element, and and a
pointer to a result structure.
- The first argument is an array of process id's, specified by a
user-space test program.
- The second argument is a pointer to a structure where the results will
be returned. The elements of the structure must be exactly:
1) pid_t mfdpid, 2) unsigned int numfd, 3) unsigned int maxfd
- From the processes listed in the first argument, your system call should
find the process with the largest number of open file descriptors.
It should put the pid of that processes into the mfdpid field of the
result structure. It should also put the number of open file descriptors
that processes has into the numfd field of the result structure. Finally
it should put the integer value of the largest file descriptor seen in
any of the processes (from the first argument) into the maxfd field of
the result structure.
- If one of the processes listed in the first argument no longer exists
when you try to examine it, you should simply skip that processes.
However if there are no valid processes, this is an error case.
- Other processes may interrupt your syscall. The processes that
interrupts may be one of the processes listed in the first argument.
The interrupting process may change what its open file descriptors are.
In order to get a consistent view of the open file descriptors, you must
lock them while accessing them. To figure out the right way to do this,
look at the close syscall and the function fget called by the read
syscall.
- The function mentioned in the book, verify_area, memcpy_fromfs,
memcpy_tofs have been obsoleted, look in include/asm-i386/uaccess.h
to find replacements.
- You must use syscall number 259.
- Your system call will return 0 on success. On error it will return
-1. If the cause of the error was that an input pointer was null,
you must cause errno to be set to EINVAL, if the cause of the error
was anything else, you must cause errno to be set to EFAULT.
(Examine the syscall return code to figure out how to accomplish
this.)
- You must also write a test program to test your system call. It should
demonstrate an instance of your program working, of it failing because
of a null pointer, and of it failing due to an out of range memory
access. It should be self-contained: it should create all processes that
it will pass to your syscall. It must also cleanup all those processes
before exiting.
- Your test program should make a stub for the system call, and use that
stub. i.e. your final version should not use syscall(259, ...)
- Details on how to turn in Project #2 (+ test program)
will be posted before the project is due.