免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 990 | 回复: 0
打印 上一主题 下一主题

为linux系统添加新的系统调用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-28 20:29 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP