新增自行定義的system call步驟如下:
1. edit arch/x86/kernel/syscall_table_32.S, add
.long sys_mysystemcall /* 338 */
2. edit include/asm-i386/unistd.h, add
#define __NR_mysystemcall 338
3. create new file, arch/x86/kernel/systemcall.c
(defined filename yourself)
#include <linux/linkage.h>
#include <linux/kernel.h>
asmlinkage int sys_mysystemcall(void)
{
printk("mysystemcall\n");
return 0;
}
4. edit arch/x86/kernel/Makefile, add
obj-y += systemcall.o
5. compiler kernel
root@shulong-desktop:/home/shulong/linux-2.6.33-rc2# make clean && make
6. writing code for user mode, create new file test.c
#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#define __NR_mysystemcall 338
#define mysystemcall() syscall(__NR_mysystemcall);
int main ()
{
mysystemcall();
return 0;
}
7. compiler test.c
root@shulong-desktop:~# gcc -Wall test.c -o systemcall
8. execute systemcall
root@shulong-desktop:~# ./systemcall
[ 39.289669] mysystemcall
就可順利加入自行定義的system call。