Adding custom system calls to the linux kenel 5.14.3
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.16.tar.xz
sudo tar -xvf linux-4.17.4.tar.xz -C/usr/src
cd /usr/src/linux-4.17.4/kernel
- You will find a sys.c file in the this folder, open this file (using any editor, i'm using nano here)
nano sys.c
Note
- sys.c file has all the system call funtion definations, this is where we are going to add our system call funtion
-
Open Syscall folder of this repository to see the format of a syscall & how to write a sycall funtion defination, that folder also has code for a system call (System_call.c )
cd ..
cd arch/x86/entry/syscalls/
nano syscall_64.tbl
-
Open syscall_64.tbl, you will find names of all the sycalls, No of syscalls can vary in different versions, go to the end of the table and add your system call to file sycall_64.tbl eg. (Notice row 548 in this picture that's name of my syscall & all the colums are separated by a tab ) only replace you syscall name with mine and rest of the things remain the same
Once you are done with the above steps, navigate back to the folder where you extracted the kernel folder
sudo make menuconfig
sudo make
sudo make modules_install install
sudo cp -v arch/x86/boot/bzImage /boot/vmlinuz-sam
sudo ls /usr/lib/modules
sudo mkinitcpio -k 5.19.9 -g /boot/initramfs-sam.img
sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo reboot
-
There's test.c file in Testing foler, read the comments carefully and make necessary changes according to your syscall and run the code. if the code compiles and runs successfullly that means you have added the system call correctly
-
there's demo.c file which explains how to use the system call in a C program