<<

TheThe LinuxLinux KernelKernel InternalInternal Implementing a 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 number void *sys_call_table[NR_syscalls] = { [0 ... NR_syscalls-1] = sys_ni_syscall, #include }; https://elixir.bootlin.com/linux/v3.14/source/arch/arc/kernel/sys.#L13

Syscall table : https://github.com/torvalds/linux/blob/v3.13/arch/x86/syscalls/syscall_64.tbl https:// github.com/torvalds/linux/blob/883c9ab9eb595f8542d01e55d29a346c8d96862e/ar ch/parisc/kernel/syscall_table.S https:// github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b7135965b1/a rch/sparc/kernel/systbls_32.S Linux system call in C without a standard

• http:// the-linux-channel.the-toffee-project.org/index.php?page =5-tutorials-a-linux-system-call-in-c-without-a-standar d-library&lang Add SYSCALL in the

• 1- download linux kernel : https://kernel.org • 2- apt-get source linux Define a new System Call, sys_hello()

linux- 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//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-

• sudo make -j4 modules_install install Test the System Call dmesg output The end!

• Question?