- 论坛徽章:
- 0
|
project1:为linux系统添加新的系统调用,基于linux2.4..20.8版本,存在遗留问题待解决。
Advanced OS, Fall 2006 Project-1
Purpose
Deeper understanding the mechanism of system calls
Real-world implementations of system call in Linux
Background
Interface between the OS and user programs
Corresponding to each system call is a library procedure that
puts parameters in a specified place
switches CPU mode to kernel mode
Requirment:
Platform : Linux
Adding a system call “my_syscall”
The system call my_syscall(arg1) multiplies arg1 by 6 and return the product.
e.g. after execute the C language statement: val = my_syscall(8);
the value of val is (8 * 6) = 48
Write a testing program to test the system call.
Write a report to explain
why you add the lines in unistd.h and entry.s
why the testing program need the blue line.
Note:
You can also write a loadable Linux kernel module and load it in runtime to implement the system call.
General steps to add a system call
Assign an id to the system call
Write a system call function
Make the kernel aware of the system call
Allow user programs to use the system call
Hinting
Assign an id to your system call,
add a line in file /usr/src/linux/include/asm-i386/unistd.h
e.g. #define __NR_my_syscall xxx /* xxx is mysyscall id */
Write source code of your system call function and append it in file
/usr/src/linux/kernel/sys.c
note: function name must be my_syscall
Add an entry into system call table
/usr/src/linux/arch/i386/kernel/entry.S
e.g. .long SYMBOL_NAME(sys_my_syscall)
file:///C:/DOCUME~1/BORA~1.IUE/LOCALS~1/Temp/msohtml1/01/clip_image001.gif
Use makefile to rebuild the kernel image and install it, then reboot the system
compile your system kernel:
1、make sure you enter the directory: /usr/src/linux
2、The compiling order:
make mrproper /*this step can not be ignore , or you will meet some faults.*/
make oldconfig /* you can refer to xconfig */
make menuconfig /*this step can be ignore ,but you may meet some errors. In this project, the main program will work well if you don’t do it. Here you can config your system */
make dep
make bzImage
make modules
make modules_install
make install /*This step you can replace it by using copy bzImage,system.map,link it, and modify grub.conf. */
init 6 /* also you can use “reboot”. */
Write a testing program to test the system call
Note:
If you use loadable module other than to rebuild the kernel, be sure that the system call entry is exported in file kernel/ksyms.c. As there is no extra system call entry for your kernel function, you have to use an existing system call number. Your kernel module must save the original system call entry when load the module and replace it after unload the module. To load the module, use Linux command “insmod” and to unload it use “rmmod”.
Testing Program
#include
#include
#include
#include
#define __NR_my_syscall 259 /**/
_syscall1( int, my_syscall, int, buf) /* note no ‘;’ */
int main(int argc,char **argv)
{
printf("return : %d\n", my_syscall(8));
return 0;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/83313/showart_1351117.html |
|