最近为了在内核中加入指令,需要增加系统调用。我采用的方法是通过修改内核源码来增加系统调用。
1 . 实验环境为 Centos-6.0 + 32位,使用的内核源码为 linux-3.1-rc4.tar.gz.
需要增加的系统调用函数为:
int mycall(int num)
{
printk("This is my syscall from kernel.\n");
printk("current pid is: %d.\n", current->pid);
return num;
}
解压内核源码压缩包,然后修改如下文件:
1) linux-3.1-rc4/arch/x86/kernel/syscall_table_32.S
在最后添加:
.long sys_mycall
2) linux-3.1-rc4/arch/x86/include/asm/unistd_32.h
可以看到原有的最后一个系统调用为:
#define __NR_syncfs 344
在后面添加自己的系统调用:
#define __NR_mycall 345
同时,修改总的系统调用数:
#define NR_syscalls 346
3)linux-3.1-rc4/include/linux/syscalls.h
添加增加的系统调用的声明:
1 . 实验环境为 Centos-6.0 + 32位,使用的内核源码为 linux-3.1-rc4.tar.gz.
需要增加的系统调用函数为:
int mycall(int num)
{
printk("This is my syscall from kernel.\n");
printk("current pid is: %d.\n", current->pid);
return num;
}
解压内核源码压缩包,然后修改如下文件:
1) linux-3.1-rc4/arch/x86/kernel/syscall_table_32.S
在最后添加:
.long sys_mycall
2) linux-3.1-rc4/arch/x86/include/asm/unistd_32.h
可以看到原有的最后一个系统调用为:
#define __NR_syncfs 344
在后面添加自己的系统调用:
#define __NR_mycall 345
同时,修改总的系统调用数:
#define NR_syscalls 346
3)linux-3.1-rc4/include/linux/syscalls.h
添加增加的系统调用的声明: