Skip to content

harjeet-blue/Custom_System_Calls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom_System_Calls

Adding custom system calls to the linux kenel 5.14.3

In this repo we are going to add custom system calls to linux kernel in just 2 steps

Pre-requisites

downloading and extracting the kernel source code folder

open terminal and write these commands

  • Download the kernel folder

    wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.16.tar.xz
  • Extract the downloaded folder

    sudo tar -xvf linux-4.17.4.tar.xz -C/usr/src
  • Go into kernel directory in the extracted folder

    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

STEP 1

writing/adding system call

  • 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 )

  • write your syscall code anywhere in sys.c file

  • eg (save your code in the file and exit from the file )

  • Adding your sycall name to the table, follow these commands

    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

STEP 2

Compiling and testing

Once you are done with the above steps, navigate back to the folder where you extracted the kernel folder

  • commands to compile

edit config file so that only required things are compiled

    sudo make menuconfig

compile the kernel

    sudo make 

install modules

    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

reboot system

    sudo reboot

Testing

  • 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

About

Adding custom system calls to the linux kernel 5.14.3

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages