Adding new System Call to Linux Kernel 3.13 on 64 bit system -
i'm trying add together simple helloworld scheme phone call kernel 3.13.0-37-generic on 64 bit system.
i'll seek show did far step step :
1- i've downloaded kernel source :
sudo apt-get source linux-image-3.13.0-37-generic after that, kernel source files extracted /usr/src/
2- define new scheme phone call sys_hello() :
i've created directory hello name in kernel source directory in /usr/src/linux-3.13/
and created hello.c file in hello directory below content :
#include <linux/kernel.h> asmlinkage long sys_hello(void) { printk(“hello world\n”); homecoming 0; } then created makefile in hello directory next content :
obj-y := hello.o 3- add together hello directory kernel’s makefile
i changed next line in /usr/src/linux-3.13/makefile:
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ to :
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/ 4- add together new scheme phone call sys_hello() scheme phone call table (syscall_64.tbl file)
because i'm using 64 bit system, need alter syscall_64.tbl file in :
/usr/src/linux-3.13/arch/x86/syscalls/syscall_64.tbl added next line in end of file :
-last line number 313
314 mutual hello sys_hello 5- add together new scheme phone call sys_hello() in scheme phone call header file
vim /usr/src/linux-3.13/include/linux/syscalls.h i've added next line end of file before #endif statement @ bottom :
asmlinkage long sys_hello(void); 6- compiling kernel on system
to configure kernel tried next command :
sudo create menuconfig after above command pop window came , made sure ext4 selected , save.
then :
# cd /usr/src/linux-3.13/ # create it tooks 2~3 hours.
after :
# create modules_install install after that, rebooted system.
7- test scheme phone call (problem here)
after reboot, created file name hello.c in home folder next content :
#include <stdio.h> #include <linux/kernel.h> #include <sys/syscall.h> #include <unistd.h> int main() { long int amma = syscall(314); // 314 number of sys_hello line in `syscall_64.tbl` printf(“system phone call sys_hello returned %ld\n”, amma); homecoming 0; } then :
# gcc hello.c # ./a.out the output :
system phone call sys_hello returned -1 problem -1. must homecoming 0 not -1.
seems sys_hello doesn't added kernel scheme call.
what doing wrong?
the problem step 6 lastly step (compile kernel).
after step 5, have next steps :
6- compiling kernel on system
to configure kernel tried next command :
# create menuconfig after above command pop window came , made sure ext4 selected , save.
then create deb file new kernel have :
# create -j 5 kdeb_pkgversion=1.arbitrary-name deb-pkg it create deb files in /usr/src/.
after need install them :
# dpkg -i linux*.deb it install new kernel on system.
now, reboot system. after scheme rebooted can find out whether new kernel installed or not :
$ uname -r and if want know new scheme phone call added kernel or not type :
$ cat /proc/kallsyms | grep <system phone call name> in case :
$ cat /proc/kallsyms | grep hello following output indicates scheme phone call added kernel :
0000000000000000 t sys_hello linux linux-kernel system-calls
No comments:
Post a Comment