So I have seen a bunch of questions about adding system calls but I can't find any examples of one using an LKM that works. I have found resources like this: http://tldp.org/LDP/lkmpg/2.6/html/ This works, in theory, but doesnt compile. Can anyone point me towards a simple example for adding a hello world system call or something. Something like this: https://tssurya.wordpress.com/2014/08/19/adding-a-hello-world-system-call-to-linux-kernel-3-16-0/ that doesn't require me to recompile my kernel?
2 Answers
Generally, it's strongly recommended to not implement a whole new system call.
Rather, only implement a new ioctl
and likely some new block or character devices.
For how to do that, it looks like there is another question/answer already: How do I use ioctl() to manipulate my kernel module?

- 15,265
- 4
- 50
- 75
-
I don't suppose you have some intuition on how to use these things? I found an example: http://www.tldp.org/LDP/lkmpg/2.6/html/x892.html but I am not sure how you would go about using the ioctl's. So you can mknod the device driver and then read from it by cating it. What do you do with the ioctl? – BashOverride Apr 01 '16 at 04:03
-
I think I should actually redefine my question. Say that I want to add a system call that will return data about a process that is currently running. So I would pass it a pid and it would return things like that parent pid, start time, etc.. Would the ioctl just call a read, which would find that info? Or... what? I'm having a hard time understanding how this set-up would work. – BashOverride Apr 01 '16 at 04:16
I don't think you can do that with a module. The definitions of the syscall go into two places which cannot really be changed at runtime (as far as I know): syscall table (which assigns numbers per architecture) and syscalls include file (installed with kernel itself, not modules). (Or at least not without messing with code rewriting at runtime.)
You'll always need to recompile the kernel in that case. But if you want to have a quick update/try cycle, you could implement a syscall that's just a stub, passing a message to the right module if it's loaded. It would allow you to change the implementation, but not the signature.

- 33,322
- 10
- 107
- 191