发新话题
打印

内核添加

内核添加

各位大侠好!
   小地在linux中添加系统函数,经过了n次make 后,还是不能如愿实现!
小弟看了“编程开发”中的文章,按要求实行,但还是不行,这是为什么?
我的方法是这样的,希大侠指点迷经,小弟不胜感激!
   1. 编译sys.c
   #cd /usr/src/linux/kernel
   在文件的最后添加一个系统调用:
asmlinkage int sys_print_info(int num)
{
    return num;
}
2。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) /* 225
rept NR_syscalls-225
.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) /* 225
.long SYMBOL_NAME(sys_print_info) /* added by I */
.rept NR_syscalls-226
.endr
3.改相应的头文件:
# cd /usr/src/linux/include/asm
# vi unistd.h
把增加的sys_call_table表项所对应的向量,在include/asm/unistd.h
中进行必要申明,以供用户进程和其他系统进程查询或调用。
#define __NR_putpmsg 224
#define __NR_vfork 225
#define __NR_print_info 226 /*dded by I */
// 引用结束
我在/usr/include/linux/unistd.h,中加了#define __NR_print_info 226
哦,我的内核是linux-2.4.16的
然后就是做过无数次的make了,重起,编个程序一试,不行
# vi test.c
#include
#include
extern int errno;
_syscall1(int,print_info,int,testflag)
main()
{
int i;
i= print_info(2);
if(i==2)
printf("i=%d , syscall success!n",i);
}

#gcc -c test.c
error:
in function 'print_info'
'__NR_print_info'undeclared (first use in this function)
each undeclared identifier is reported only once for each function it appear in)

希望那位大虾帮帮我!谢谢了!      

TOP

内核

今天下午我搞定了!呵呵!      

TOP

:eek: 问题出在哪里,丛你写的好像看不出什么问题      

TOP

内核系统

就是在/usr/include/linux/unistd.h
只把#define __NR_print_info写在程序的第一行就行了
我以前没这样做?把它放在中间了!
谢谢大家的关心!      

TOP

这也有区别??:confused:      

TOP

不可能是这样的。肯定是别的问题。      

TOP

内核系统

可我就是这样改的,之后就make !
在调用时还出现一个问题?
就是在用printk函数时,没显示?
这又是为什么?
但我让他返回数字时是对的!      

TOP

发新话题