- get kernel codes from www.kernel.org.
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.3.1.tar.bz2
- Upzip it with command ‘tar xvfj XXX” to a folder For example : /root/kernel tar xvfj linux-3.3.1.tar.bz2
- Edit file “/root/kernel/linux-3.3.1/arch/x86/syscalls/syscall_64.tbl” Add new line
312 64 husky1 sys_husky1 - Eidt file “/root/kernel/linux-3.3.1/include/linux/syscalls.h” Add new function declaration
asmlinkage long sys_husky1(int fd);
before the line “#endif” - Add a new c file under “/root/kernel/linux-3.3.1/arch/x86/kernel”
long sys_husky1(int fd) { ... } - Edit “/root/kernel/linux-3.3.1/arch/x86/kernel/Makefile” Add a new line “obj-y += husky.o”
- goto /root/kernel/linux-3.3.1 folder and run command “make –j8”
User space code for calling the new system call:
int ret = syscall(312);Due to standard kernel header doesn't know our new system call,
we need to use system call number here.
Ref: http://stackoverflow.com/questions/9977968/adding-a-new-system-call-in-linux-kernel-3-3
沒有留言:
張貼留言