Lab4: Adding a System Call (Due date :  February 25,  2004)


You will learn how to make a system call and about reading/writing user space from the kernel by adding a new function to the kernel.
The function itself is trivial---it simply returns the value of "xtime" or using "do_gettimeofday".


A system call is the name of kernel function that is exported for use by user-space programs. For instance, system calls such as gettimofday(), gethostname() are implemented to make the user programs to obtain the time or host name.  To learn more, you should read chapter 9 of ULK or Chapter 3.3 and Appendix A of LKP.

Problem Statement:

Part A:
Design and implement a new kernel function, pedagogictime(), that returns the current system time via a call by reference argument.
If the flag argument is TRUE, then your kernel function should also print the current system time on stdout. Your function should have the following prototype:

int pedagogictime(int flag, struct timeval *current_time);

Your new function should be almost the same as "gettimeofday", though it should ignore the time zone parameter and have the flag to control printing the time to the console.
Your function should return TRUE if the function succeeds, and FALSE otherwise.

Part B:
Write a user-space program to test pedagogictime(). The program also should create a stub for your new system call function.

Attacking the Problem :
  1. Read on-line material about Adding a System Call to UML (.html) from UML webpage or PDF file (.pdf)
  2. The steps to add a system call to UML (guidelines), suppose you are at "~/Uml/linux-2.4.23/" dir:
  1. Once you have done above steps and boot the UML, compile the test program in UML like: 
            gcc -o test -I/mnt/Uml/linux-2.4.23/include clockTest.c
        and then run the user-space program inside UML.

    Note: Your user-space program should include a stub of "__syscall2" since pedagogictime takes two arguments. You need "copy_to_user()" function to copy the data from kernel space to user space.

What to submit:

Please submit the following items to your ~/Uml/lab4 directory on elgate:
  1. the source files you have changed
  2. the source files you have added
  3. the user-space test source code and the binary code
  4. a sample output from running your user-space test program
  5. a README file describing how you implemented the system call and how I should run your test program. Also the other issues as shown in the sample README. All comments are welcome.