Skip to content

Add a systemcall to the kernel of linux and compile the kernel

Notifications You must be signed in to change notification settings

v-nafiseh/Kernel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

team work with Shokoofa Ghods

steps

  • write systemcall
  • add it to target files
  • compile kernel

position of operating system

the lowest level is hardware which consists of physical devices such as ICs, cathode lamps and .. on top level we've got Michroarchitecture in which physical devices interact with eachother. Normally this levele has CPU registers and a Data Path of ALU.

a computer system hierarchy
  • applications
  • system programs (compilers, editors, shell, command iterpreter)
  • operating system
  • machine language
  • michroarchitecture
  • physical devices
shell
  • is the interface between end user and kernel and its duty is to interprete user commands to into understandable system calls for kernel.
  • in old operating systems like MS-DOS shell was about text commands. Howerever, today there are both text and graphical shells
  • shell is located at User space, in contrary kernel is located at kernel space
systemcall
  • as defined it's a method to get services from the kernel
  • the picture below simply shows how a system call works:
steps for adding the systemcall and compiling the kernel
  • update os
sudo apt update
  • get the latest version of linux kernel from kernel.org
  • check the current kernel version
uname -r
  • change directory to new kernel and create a directory for systemcall
cd linux-version
mkdir mysyscall
cd mysyscall
  • make a c program for the systemcall
vim mysyscall.c
#include <linux/kernel.h>
#include <linux/syscalls.h>

SYSCALL_DEFINE0(mysyscall)

{
    printk("This is my attempt for a basic syscall.\n");
    return 0;
}
  • create Makefile and add the proper code
touch Makefile
echo obj-y : mysyscall.o > Makefile
  • return back to the kernel dir and add the new syscall to the line containing core-y
cd ..
vim Makefile
kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ mysyscall
  • enter the header file add the follwing command
vim include/linux/syscalls.h
asmlinkage long sys_mysyscall(void);
  • add your syscall function tp system call table
vim arch/x86/entry/syscalls/syscall_64.tbl
linenum 64 mysyscall sys_mysyscall
  • specify number of cores for the process of compile, in this case I allocate 2 cores on my vm
make -j2
  • start the process which may take some time according to system resources
make install -j2

About

Add a systemcall to the kernel of linux and compile the kernel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published