+ All Categories
Home > Documents > The Linux Kernel Internal · The Linux Kernel Internal Implementing a Linux kernel system call...

The Linux Kernel Internal · The Linux Kernel Internal Implementing a Linux kernel system call...

Date post: 13-Jun-2020
Category:
Upload: others
View: 70 times
Download: 3 times
Share this document with a friend
18
The Linux Kernel Internal The Linux Kernel Internal Implemenng a Linux kernel system call Ramin Farajpour Cami – Twier : @MF4rr3ll
Transcript

The Linux Kernel Internal The Linux Kernel InternalImplementing a Linux kernel system call

Ramin Farajpour Cami – Twitter : @MF4rr3ll

System Call

• Communicating with the Kernel .

• System calls provide a layer between the hardware and user-space processes

SYSCALL RAODMAP

Control Flow Syscall

Select SYSCALL numbervoid *sys_call_table[NR_syscalls] = {

[0 ... NR_syscalls-1] = sys_ni_syscall,

#include <asm/unistd.h>

};

https://elixir.bootlin.com/linux/v3.14/source/arch/arc/kernel/sys.c#L13

Syscall table :

https://github.com/torvalds/linux/blob/v3.13/arch/x86/syscalls/syscall_64.tbl

https://github.com/torvalds/linux/blob/883c9ab9eb595f8542d01e55d29a346c8d96862e/arch/parisc/kernel/syscall_table.S

https://github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b7135965b1/arch/sparc/kernel/systbls_32.S

Add SYSCALL in the linux kernel

• 1- download linux kernel : https://kernel.org

• 2- apt-get source linux

Define a new System Call, sys_hello()

• cd linux-<version>

• mkdir hello

• cd hello

• vim hello.c

Define a new System Call, sys_hello()

Add the hello directory to the kernel’s Makefile

• cd hello

• vim Makefile

• cd ..

Add the hello directory to the kernel’s Makefile

Add the new system call into the System Call table

• vim arch/x86/entry/syscalls/syscall_64.tbl

Add the new System Call in the System Call header file

• cd include/linux/

• vim syscalls.h

Add the new System Call in the System Call header file

Recompile the kernel

• cd linux-<version>

• sudo make -j4 modules_install install

Test the System Call

dmesg output

The end!

• Question?


Recommended