1¡¢±àдϵͳµ÷Óú¯Êý
±à¼sys.cÎļþ£º
# cd /usr/src/linux/kernel
# vi sys.c
ÔÚÎļþµÄ×îºóÔö¼ÓÒ»¸öϵͳµ÷Óú¯Êý£º
asmlinkage int sys_print_info(int testflag)
{
printk(" Its my syscall function!n");
return 0;
}
¸Ãº¯ÊýÓÐÒ»¸öintÐÍÈë¿Ú²ÎÊýtestflag,²¢·µ»ØÕûÊý0¡£
2¡¢ÐÞ¸ÄÓëϵͳµ÷ÓúÅÏà¹ØµÄÎļþ
±à¼Èë¿Ú±íÎļþ£º
# cd /usr/src/linux/arch/i386/kernel
# vi entry.S
°Ñº¯ÊýµÄÈë¿ÚµØÖ·¼Óµ½sys_call_table±íÖУº
arch/i386/kernel/entry.SÖеÄ×îºó¼¸ÐÐÔ´´úÂëÐÞ¸ÄǰΪ£º
......
.long SYMBOL_NAME(sys_sendfile)
.long SYMBOL_NAME(sys_ni_syscall)
.long SYMBOL_NAME(sys_ni_syscall)
.long SYMBOL_NAME(sys_vfork)
rept NR_syscalls-190
.long SYMBOL_NAME(sys_ni_syscall)
.endr
Ð޸ĺóΪ£º
......
.long SYMBOL_NAME(sys_sendfile)
.long SYMBOL_NAME(sys_ni_syscall)
.long SYMBOL_NAME(sys_ni_syscall)
.long SYMBOL_NAME(sys_vfork)
.long SYMBOL_NAME(sys_print_info)
.rept NR_syscalls-191
.endr
ÐÞ¸ÄÏàÓ¦µÄÍ·Îļþ£º
# cd /usr/src/linux/include/asm
# vi unistd.h
°ÑÔö¼ÓµÄsys_call_table±íÏîËù¶ÔÓ¦µÄÏòÁ¿£¬ÔÚinclude/asm/unistd.hÖнøÐбØÒªÉêÃ÷£¬ÒÔ¹©Óû§½ø³ÌºÍÆäËûϵͳ½ø³Ì²éѯ»òµ÷Óá£
#define __NR_putpmsg 189
#define __NR_vfork 190
#define __NR_print_info 191
3¡¢±àÒëÄںˣ¬ÔÙÖØÆô¶¯
4¡¢²âÊÔ
±àдÓû§²âÊÔ³ÌÐò£¨test.c£©£º
# vi test.c
#include
#include
extern int errno;
_syscall1(int,print_info,int,testflag)
main()
{
int i;
i= print_info(0);
if(i==0)
printf("i=%d , syscall success!n",i);
}
Èç¹ûÒªÔÚÓû§³ÌÐòÖÐʹÓÃϵͳµ÷Óú¯Êý£¬ÄÇôÔÚÖ÷º¯ÊýmainÇ°±ØÐëÉêÃ÷µ÷ÓÃ_syscall£¬ÆäÖÐ1 ±íʾ¸Ãϵͳµ÷ÓÃÖ»ÓÐÒ»¸öÈë¿Ú²ÎÊý£¬µÚÒ»¸öint ±íʾϵͳµ÷Óõķµ»ØֵΪÕûÐÍ£¬print_infoΪϵͳµ÷Óú¯ÊýÃû£¬µÚ¶þ¸öint ±íʾÈë¿Ú²ÎÊýµÄÀàÐÍΪÕûÐÍ£¬testflagΪÈë¿Ú²ÎÊýÃû¡£
±àÒë²âÊÔ³ÌÐò£º
# gcc -o test test.c
Ö´ÐвâÊÔ³ÌÐò£º
# ./test
Its my syscall function!
i=0, syscall success!
ok!Ôö¼Óϵͳµ÷Óú¯Êý³É¹¦¡£