KEMBAR78
Linux kernel system call | PPTX
The Linux Kernel Internal
Implementing a Linux kernel system call
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 number
void *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/883c9ab9eb595f8542d01e55d29a346
c8d96862e/arch/parisc/kernel/syscall_table.S
https://github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b
7135965b1/arch/sparc/kernel/systbls_32.S
Linux system call in C without a standard library
• http://the-linux-channel.the-toffee-
project.org/index.php?page=5-tutorials-a-linux-system-
call-in-c-without-a-standard-library&lang
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?

Linux kernel system call

  • 1.
    The Linux KernelInternal Implementing a Linux kernel system call
  • 2.
    System Call • Communicatingwith the Kernel . • System calls provide a layer between the hardware and user-space processes
  • 3.
  • 4.
  • 5.
    Select SYSCALL number void*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/883c9ab9eb595f8542d01e55d29a346 c8d96862e/arch/parisc/kernel/syscall_table.S https://github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b 7135965b1/arch/sparc/kernel/systbls_32.S
  • 6.
    Linux system callin C without a standard library • http://the-linux-channel.the-toffee- project.org/index.php?page=5-tutorials-a-linux-system- call-in-c-without-a-standard-library&lang
  • 7.
    Add SYSCALL inthe linux kernel • 1- download linux kernel : https://kernel.org • 2- apt-get source linux
  • 8.
    Define a newSystem Call, sys_hello() • cd linux-<version> • mkdir hello • cd hello • vim hello.c
  • 9.
    Define a newSystem Call, sys_hello()
  • 10.
    Add the hellodirectory to the kernel’s Makefile • cd hello • vim Makefile • cd ..
  • 11.
    Add the hellodirectory to the kernel’s Makefile
  • 12.
    Add the newsystem call into the System Call table • vim arch/x86/entry/syscalls/syscall_64.tbl
  • 13.
    Add the newSystem Call in the System Call header file • cd include/linux/ • vim syscalls.h
  • 14.
    Add the newSystem Call in the System Call header file
  • 15.
    Recompile the kernel •cd linux-<version> • sudo make -j4 modules_install install
  • 16.
  • 17.
  • 18.