I'd like to add a new system call via an LKM, but I'm not sure how to do this. That is, I know that if I want to add a completely new system call, I can look through the sys_call_table and find a sys_ni_syscall
and just replace it, but I was curious if it was possible to actually add to the sys_call_table
. I realize it's probably not possible, given that it's a fixed size array, but I was wondering if there were any other clever ways to add system calls without overriding an unused system call number.

- 8,444
- 7
- 37
- 49
-
Possible duplicate of [Implementing Linux System Call using LKM](https://stackoverflow.com/questions/12623066/implementing-linux-system-call-using-lkm) – Nir Duan Jan 29 '18 at 15:26
3 Answers
Here's an example
linux system calls
edit:
The example above shows howto implement a system call, as far as implementing one from a loadable module; AFAIK, that's not possible, unless you where to overwrite an existing one because the size of the array is a #define.
Keep in mind there are user space changes required as well, at least if you want to be able to actually use the new system call.

- 2,210
- 1
- 15
- 15
This is an old question, but nevertheless I want to propose my solution. The easiest way to implement a "system-call-like" environment is to rely on a fake device.
In particular, you could create a new device driver which is not actually driving anything. Yet, writing on it, can cause the installed module to perform the required actions.
Additionally, if you want to offer several services, you might map them to ioctl
operations.

- 470
- 5
- 12
Check The Linux Documentation Project website for "The Linux Kernel Module Programming Guide" (http://www.tldp.org/LDP/lkmpg/2.6/html/index.html). Specifically, look here for System Calls: http://www.tldp.org/LDP/lkmpg/2.6/html/x978.html. That should give you a start, at least.

- 2,090
- 14
- 14
-
5Read through that, although it looks like sys_call_table is no longer exported in the 2.6 kernel. See the comment in syscall.c – FreeMemory Jan 21 '09 at 14:25