自己添加一个系统调用
自己添加一个系统调用要依照一下步骤完成,不过在产考的过程中还要根据自己的机器来操作。
1)前提:一个干净的系统
2)把redhat下的/usr/src/kernels/2.6.18-164.el5-i686/.config拷到自己下的内核中如(linux-2.6.28)
3)Cd linux-2.6.28
4)Make后接着一路回车
5)编辑/kernel/sys.c文件,添加如下代码:
asmlinkage long sys_mycall(long number)
{
printk(“call number is %ld\n”,number);
return number;
}
6)编辑arch/x86/include/asm/unistd.h(要根据bzImage产生的位置和电脑的位数)文件:
添加一行#define __NR_mycall 324 到当前的最大系统调用号之后 ,比如原来最大的是323,在323的这一行之后 加上一行 #define __NR_mycall 324
修改#define NR_systemcalls 的值,改成原来的值+1,比如原来是324 改成325
7)编辑/arch/x86/kernel/syscall_table_32.S文件
在文件最后加上一行:
.long sys_mycall
8) make bzImage
9) cp /linux-2.6.28/arch/x86/boot/bzImage /boot/vmlinuz-版本号 (拷贝内核镜像)
10)编辑/boot/grub/grub.conf
修改前:
title Red Hat Enterprise Linux Server (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-164.el5.img
修改后:
title Red Hat Enterprise Linux Server (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-164.el5.img
title Red Hat Enterprise Linux Server (2.6.28)
root (hd0,0)
kernel /vmlinuz-2.6.28 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.28
11)重启redhat。