分类: 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)”