Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement my own system call without recompiling the Linux kernel?

I want to implementing my own system call. (See below link)

http://www.tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/

But adding new system call requires kernel compilation.

How to implement my own system call without recompiling the Linux kernel?

like image 854
Amir Saniyan Avatar asked Jun 20 '13 16:06

Amir Saniyan


People also ask

Can I add system call without recompile whole compiler?

You can't. Without recompiling the kernel, all you can do is build and load kernel modules, and kernel modules cannot add new system calls.

Do all system calls require kernel mode?

The original definition of a system call is/was a system support (OS) function that is called by a trap of some kind rather than a "normal" function call. So by that definition, every system call requires a switch to kernel mode, as if it didn't it wouldn't be a system call (just a normal system library call).

Can your programs make Linux calls directly?

For All Practical Purposes. In nearly all cases, you won't ever have to make direct system calls in your C programs. If you use assembly language, however, the need may arise.


1 Answers

Sure, you can.

In short, you'll need to patch the running kernel.

There are at least 2 ways to add a new syscall:

  1. Expand the existing system call tables (sys_call_table and ia32_sys_call_table) and patch system call limit check instruction (usally cmp on x86) at any of the system call entries (system_call, ia32_system_all etc...)
  2. Copy existing system call tables, expand them as needed, patch system call dispatch instruction (usally call on x86) to point to table's copy and patch system call limit check instruction at any of the system call entries.

See this anwers for details:

Implementing Linux System Call using LKM

How do 32-bit applications make system calls on 64-bit Linux?

:)

like image 92
Ilya Matveychikov Avatar answered Oct 21 '22 12:10

Ilya Matveychikov