Chinaunix首页 | 论坛 | 博客
  • 博客访问: 617785
  • 博文数量: 201
  • 博客积分: 3076
  • 博客等级: 中校
  • 技术积分: 2333
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-02 19:44
文章分类

全部博文(201)

文章存档

2010年(118)

2009年(83)

我的朋友

分类: LINUX

2009-11-30 20:49:08

http://blog.chinaunix.net/u/26166/showart.php?id=198536 (zz)


(1)    program your system call function in sys.c:

in the linux/kernel/sys.c,add your fuc.

Eg:

asmlinkage long sys_mynum(long num){

       printk("in sys_mynum\n");

       return num;}

My new syscall function name is mynum ,but you have to use sys_mynum in sys.c

(2)please find the include/asm-armnommu/unistd.h

 this file include the system call listing,you can see as follows:

       "#define __NR_XXX  (__NR_SYSCALL_BASE+NNN)"

       the XXX is your function name.eg: mynum

       the NNN is corresponding system call number,it is only.if you find the max system call number that have been assigned is 274,your new system call number must be 275.

Eg:

#define __NR_usb_mount                 (__NR_SYSCALL_BASE+274)

#define __NR_mynum                   (__NR_SYSCALL_BASE+275)

(3)please find the linux-2.6.x\arch\armnommu\kernel\call.S

this file include the system call function pointer,you can see as follows:

        ".long sys_XXX"

        the XXX is your function name and add your ".long sys_XXX" to the end of  list.

eg:        

              .long       sys_usb_mount

              .long      sys_mynum

(4) rebuild your linux kernel

Make your kernel.

(5) test the system call function

#include

#include

#define __NR_mynum   (__NR_SYSCALL_BASE+275)

static inline _syscall1(long,mynum,long,num);

int main(){

long i;

printf("in the main\n");

printf("please input your num.eg:1 ,2 ,4 ,6......\n");

scanf("%d",&i);

printf("you put the num is:%d\n",mynum(i));

return 0;}

the blue num is corresponding the num in “sys_mynum(long num)”

the red mynum is corresponding the mynum in “sys_mynum(long num)”

 

NOTE:the test function is add_syscall.c in the folder.
阅读(571) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~