LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1565|回复: 5

我为2.6内核增加系统调用怎么老是失败

[复制链接]
发表于 2005-2-3 21:57:21 | 显示全部楼层 |阅读模式
我用的发行版是Fedora Core 3,内核是2.6.10
我增加系统调用的方法是:


1.修改arch/i386/kernel/entry.S ,sys_call_table(对应源文件倒数第2行)增加:
.long sys_wmzlq
其中, sys_wmzlq为新增加的系统调用

2.修改 include/asm-i386/unistd.h,增加宏定义:
#define __NR_wmzlq 289
然后把原来的#define NR_syscall 289 改为#define NR_syscall 290

3.编写系统调用将其插入kernel/sys.c
asmlinkage int sys_wmzlq()
{
return 1112;
}

5.编译内核(内核源码放在/usr/src中,形式是/usr/src/linux-2.6.10 , 并应用新内核启动linux(编译内核这一步我已经做好了,保证没有问题)

6. 编写程序测试新加入的系统调用
/* test.c by wmzlq */
#include <unistd.h>
#include <stdio.h>
#include <errno.h>

_syscal0(int,wmzlq) ;

int main()
{
int i ;
i = wmzlq() ;
printf("%d",i) ;
return 0 ;
}

但是始终不能通过编译。。。编译时错误提示如下:
[root@Daemon ~]# gcc -o test test.c
test.c:5: error: syntax error before "wmzlq"
test.c:5: warning: data definition has no type or storage class
[root@Daemon ~]#

请问高手我的做法哪一步有错了呢?
我看到网上有一文章是针对2.2.5的(地址是:http://www.linuxsir.cn/forum.php?mod=viewthread&tid=24275 ),但在2.6的内核上有些地方不一样了,我就尝试着上述我自己琢磨出的方法,可惜没有成功
对于2.6.10的内核(或者2.6.* 内核)该怎么添加新的系统调用呢?
有哪位高手曾经做过类似的尝试,能把经验分享一下么?
先谢了。。。
发表于 2005-2-4 10:22:35 | 显示全部楼层
兄弟,确信你的copy没有错??

_syscal0          _syscall0
回复 支持 反对

使用道具 举报

发表于 2005-2-4 10:24:14 | 显示全部楼层
而且从错误讯息syntax error before "wmzlq" ,完全可以看出不是你添加系统调用没有成功,而且普通的c语法问题。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-4 10:55:28 | 显示全部楼层
呵呵,谢谢版主,前面的_syscall0是我在论坛上发贴的笔误
刚才我把测试程序改为:
/* test.c by wmzlq */
#include </usr/src/linux-2.6.10/include/asm-i386/unistd.h>
#include <stdio.h>
#include <errno.h>

_syscall0(int,wmzlq) ;

int main()
{
    int i ;
    i = wmzlq() ;
    printf("%d",i) ;
    return 0 ;
}
结果成功了!!!

估计之前是因为#include<unistd.h>不对吧,想问问版主为什么会这样
另外,之前我曾经用#include <asm/unistd.h>也会出现编译错误
这该怎么理解呢?gcc在编译include 语法时搜索路径是怎样的呢?
回复 支持 反对

使用道具 举报

发表于 2005-2-4 11:02:45 | 显示全部楼层
Post by wmzlq
呵呵,谢谢版主,前面的_syscall0是我在论坛上发贴的笔误
刚才我把测试程序改为:
/* test.c by wmzlq */
#include </usr/src/linux-2.6.10/include/asm-i386/unistd.h>
#include <stdio.h>
#include <errno.h>

_syscall0(int,wmzlq) ;

int main()
{
    int i ;
    i = wmzlq() ;
    printf("%d",i) ;
    return 0 ;
}
结果成功了!!!

估计之前是因为#include<unistd.h>不对吧,想问问版主为什么会这样
另外,之前我曾经用#include <asm/unistd.h>也会出现编译错误
这该怎么理解呢?gcc在编译include 语法时搜索路径是怎样的呢?

其实这是fedora的问题。

gcc的标准搜索路径是/usr/include/,你可以用gcc -I/xxx/xx来改变

标准的做法是将/usr/include/linux /usr/include/asm符号连接到内核软代码的include/asm include/linux,fedona3默认没有安装内核源代码,所以/usr/include/linux /usr/include/asm中是一份静态的拷贝(适用于core 3默认的内核),所以和你改变过的头文件以及内核不符。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-4 11:32:42 | 显示全部楼层
Post by phyma
其实这是fedora的问题。

gcc的标准搜索路径是/usr/include/,你可以用gcc -I/xxx/xx来改变

标准的做法是将/usr/include/linux /usr/include/asm符号连接到内核软代码的include/asm include/linux,fedona3默认没有安装内核源代码,所以/usr/include/linux /usr/include/asm中是一份静态的拷贝(适用于core 3默认的内核),所以和你改变过的头文件以及内核不符。


明白了,谢谢版主~~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表