Lab4: Adding a System Call (Due date
: February 25, 2004)
Objective:
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".
Background:
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 :
- Read on-line material about Adding a System
Call to UML (.html) from UML webpage or PDF file (.pdf)
- The steps to add a system call to UML (guidelines), suppose you
are at "~/Uml/linux-2.4.23/" dir:
- add a new line providing an id (system call number) in
"include/asm-i386/unistd.h" as "#define __NR_pedagogictime NNN"
- add an entry to system call dispatch table in
"arch/i386/kernel/entry.S" as ".long SYMBOL_NAME(sys_pedagogictime)"
- in "arch/um/kernel/sys_call_table.c", do
- define a system handler , add "extern syscall_handler_t
sys_pedagogictime"
- add it to the call table (sys_call_table[]) as
"[__NR_pedagogictime]
= sys_pedagogictime"
- change "#define LAST_GENERIC_SYSCALL __NR_pedagogictime" if it
is the last system call
- if it is the last system call, do (one may be enough)
- in "arch/um/include/sysdep-i386/syscalls.h", add "#define
LAST_ARCH_SYSCALL __NR_pedagogictime"
- in "arch/um/include/sysdep/syscalls.h", change "#define
LAST_ARCH_SYSCALL
__NR_pedagogictime"
- implement your sys_pedagogictime() function (either inside time.c
or as a separate file with some modification of respective
Makefile in arch/um/kernel).
- 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:
- the source files you have changed
- the source files you have added
- the user-space test source code and the binary code
- a sample output from running your user-space test program
- 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.