[kernelreadfans] setup our own syscall based linux2.4.20

  • From: "oyk" <oyk@xxxxxxxxxxx>
  • To: kernelreadfans <kernelreadfans@xxxxxxxxxxxxx>
  • Date: Thu, 29 May 2003 16:55:33 +0800

Hi, guys,
   
基于我前面转载的syscall例子,这封信给出我基于2.4.20写的myfunc。至于myfunc的模块实现,还没有研究。这是在内核里实现的,和例子的步骤有点不同。
1. 添加myfunc标志,涉及到两个文件
   a. /usr/src/linux/arch/i386/kernel/entry.S
   找到:
   .long SYMBOL_NAME(sys_fcntl64)
   在上句下面添加:
   .long SYMBOL_NAME(sys_myfunc)        /*jjww test*/
   注释下面一句:
/*      .long SYMBOL_NAME(sys_ni_syscall)        reserved for TUX */
   b./usr/src/linux/include/asm/unistd.h
   找到:
   #define __NR_fcntl64            221
   在上句下面添加:   
   #define __NR_myfunc             222     /*jjww test*/
2. 添加sys_myfunc实体
   在/usr/src/linux/kernel/sys.c中添加
/*
 * myfunc() is implemented by jjww
 * 1. only printk
 */
asmlinkage int sys_myfunc(int myinput)
{
     printk("1. jjww printk from kernel d\n", myinput);
     return myinput;
}
3. 编译、安装内核,重启。

4. 编写用户调用程序
user_myfunc.c
#include <stdio.h>
#include <stdlib.h>
#include <linux/unistd.h>

static inline _syscall1(int,myfunc,int,a)

int main(void){
        printf("Return Value: d\n",myfunc(1));
        return 0;
}

user_myfunc.mk
INCLUDEDIR = /usr/src/linux/include 

CC = gcc 
DEBFLAG = -O2 

CFLAG = -Wall $(DEBFLAG) 
CFLAG += -I$(INCLUDEDIR) 

TARGET = usr_myfunc
SRC = $(TARGET).c 

all:
        $(CC) $(CFLAG) -o $(TARGET) $(SRC) 
clean:
        rm -f *.o *.core usr_myfunc
5. 测试
#./usr_myfunc 
#tail -f /var/log/messages 
May 29 00:33:18 RHL24 kernel: 1. jjww printk from kernel 1

BTW: 我在想怎么能够在模块里实现系统调用的添加,就避免了系统的重启?

Best Regards
  Ouyang Kai
-----------------------------------------
a HUST guy
FreeBSD: http://www.freebsd.org 
         http://daily.daemonnews.org
Linux:   http://www.kernel.org 
         http://www.linuxfans.org
-----------------------------------------



Other related posts: