- 論壇徽章:
- 0
|
在內(nèi)核中添加自定義系統(tǒng)調(diào)用的步驟,我的linux版本是2.6.17。不同Linux版本的實(shí)現(xiàn)可能會有不同。
添加步驟:
一
在/usr/src/Linux-2.6.x/kernel/目錄下創(chuàng)建文件mysyscall.c
#include
#include
asmlinkage int sys_mysyscall () {
printk(KERN_EMERG “My Syscall \n”);
return(1);
}
二
修改文件/usr/src/Linux-2.6.17/include/asm-i386/unistd.h,定義自己的系統(tǒng)調(diào)用號
#define __NR_mysyscall 317
將最后一行的系統(tǒng)調(diào)用號總數(shù)加一
#define NR_syscalls 318
三
修改usr/src/Linux-2.6.17/arch/i386/kernel/syscall_table.S,添加系統(tǒng)調(diào)用服務(wù)例程
.long sys_mysyscall
四
修改makefile文件/usr/src/Linux-2.6.17/kernel/Makefile,添加自定義系統(tǒng)調(diào)用的目標(biāo)文件
obj-y += mysyscall.o
五
重新編譯內(nèi)核
cd /usr/src/Linux-2.6.17
make mrproper
make clean
make menuconfig
make
make modules_install
make install
六
重啟系統(tǒng),進(jìn)入編譯好的內(nèi)核的系統(tǒng)
七
編寫測試程序test.c,測試自定義的系統(tǒng)調(diào)用是否成功
#include
#include
#define __NR_mysyscall 317
//_syscall0(int,mysyscall);
int mysyscall()
{
return syscall(__NR_mysyscall);
}
int main()
{
mysyscall();
return 0;
}
編譯后運(yùn)行,即可看到輸出結(jié)果。
遇到問題
mysyscall.c:10: error: expected declaration specifiers or ‘...’ before ‘mysyscall’
將標(biāo)紅的聲明改為標(biāo)紫的內(nèi)容就可以成功編譯。
但什么原因還不清楚。
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u2/83134/showart_1861764.html |
|