µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux - Ôö¼Ó×Ô¼ºµÄϵͳµ÷ÓÃ(2.4.12)¾­¹ý

Ôö¼Ó×Ô¼ºµÄϵͳµ÷ÓÃ(2.4.12)¾­¹ý

·¢ ±í ÈË£ºXiao_Ju(¿É°®µÄÁúè) °æÃæÃû³Æ£ºLinux[8377]
ÎÄÕÂÌáÒª£ºÔö¼Ó×Ô¼ºµÄϵͳµ÷Óã¨2.4.12£©¾­¹ý
Ô´ ·¢ Õ¾£ºÖйú¿Æ´óBBSÕ¾(Wed, 05 Dec 2001 18:53:11)
24%
ÎÒÊÇLinux KernelÐÂÊÖ£¬µ«ÊÇÏÖÔÚÉæ¼°µ½ÁËÐ޸ĵ÷ÓõĻ
¸ÏѼ×ÓÉϼÜÁË¡£Í¨¹ý¿´ÊéºÍʵ¼ù£¬µ½Ò²×ö³öÁ˼òµ¥µÄ¶«Î÷£¬¸Ðл
james_zhangºÍyoung_yang£¬Ð´³öÎҵľ­Àú£¬Ò²ËãÊÇÒ»¸öÈëÃŹý
³ÌÁË¡£
Ê×ÏÈÎÒ¿´ÁËÒ»±¾Ê顶Linux ²Ù×÷ϵͳÄں˷ÖÎö¡·(9711¿Î±¾)¡£
ûÓÐÌ«ÏêϸµÄÔĶÁ£¬Ö±½ÓÕÒµ½ÁËϵͳµ÷ÓõÄÒ»Õ£¬ºÍ×Ô¼ºµÄ´úÂë
Ò»¶Ô±È£¬·¢ÏÖ²»Ò»Ñù£¡¿´À´2.4.xºÍ2.2.x»¹ÊÇÓб仯µÄ¡£
È»ºóÇë½ÌÁËjames_zhangºÍyoung_yang£¬¼á¶¨ÁËÐÅÐÄ£¬´óÌåµÄ
Ô­Àí²»»á±ä£¬½á¹¹²»»á±ä¡£
Á¬ÉÏÁËgoogle¡£ËÑË÷¡°±àдϵͳµ÷Óá±£¬¹»Âã°É£¡
ÕÒµ½Á˼¸¸öÍøÒ³£¬´ò¿ªÒ»¿´£¬´óÌåÒ²²î²»¶à£º
// ÒÔÏÂÒýÓãº
ÐèÒªÒÔϼ¸¸ö»ù±¾²½Ö裺

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) /* streams1 */
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */
rept NR_syscalls-190
.long SYMBOL_NAME(sys_ni_syscall)
.endr
Ð޸ĺóΪ£º
......
.long SYMBOL_NAME(sys_sendfile)
.long SYMBOL_NAME(sys_ni_syscall) /* streams1 */
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */
.long SYMBOL_NAME(sys_print_info) /* added by I */
.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 /* added by I */
// ÒýÓýáÊø

ÕâÒ»¶ÎÓеã²î±ð£¬¾­¹ý·ÖÎö·¢ÏÖÖ»ÒªÔÚarch/i386/kernel/entry.Sµ¥¶À¼ÓÉÏ
.long SYMBOL_NAME(sys_print_info) /* added by I */
¾ÍÐÐÁË¡£

È»ºó¾ÍÊÇ×ö¹ýÎÞÊý´ÎµÄmakeÁË£¬ÖØÆ𣬱à¸ö³ÌÐòÒ»ÊÔ£¬²»ÐÐ
# 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);
}

·ÖÎöһϣ¬·¢ÏÖ»¹ÐèÒª¸Ä/usr/include/linux/unistd.h£¬¼ÓÉÏͬÑùµÄ¶«Î÷
¾ÍÐÐÁË¡£
È»ºóÊÔÑ飬һÇÐOK£¬ÎÒµÄHello Worldϵͳµ÷ÓþÍÕâÑùд³öÀ´ÁË£¡
ÏàÐÅÎÒÄÜ×öºÜ¶àÈ˾ÍÄÜÏñÎÒÒ»ÑùµÄ¡£ÆäʵһЩ¶«Î÷Ö»Òª¿Ï¶¯ÊÖ¶¼²»ÏëÏëÏñµÄ
ÄÇôÄÑ¡£