Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to add a particular new system call in the linux kernel 3.2.x but as a loadable kernel module (as I don't want to recompile the kernel again and again)

I read through many posts on internet and also on SO, and some places claim that implementing system calls as loadable modules is not possible, while others say it is possible.

Which is it? How is it done if it's possible?

share|improve this question

closed as off topic by Gilles, jasonwryan, warl0ck, Renan, Michael Mrozek Sep 16 '12 at 17:21

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This question is off-topic here: Unix & Linux is about usage and administration, not about programming. You should ask on Stack Overflow. Don't be so vague: link to the posts you found on Stack Overflow, and explain what you found inconclusive or contradictory. –  Gilles Sep 10 '12 at 22:19
I believe that this question is much more related to Linux as an OS than to programming itself. It is also quite important to know what are the possibilities of extending our system abilities and what are its limits. This, for example, makes you understand why some features are not possible to implement as loadable module and needs kernel patching. Knowing why it is like this may also give you some ideas of security vs usability kernel developers have to make. Would that question be more on topic if OP would ask only if it's possible and why not and not how to implements this? –  Krzysztof Adamski Sep 16 '12 at 20:09
add comment

2 Answers 2

up vote 5 down vote accepted

It is not possible because system call table (called sys_call_table) is a static size array. And its size is determined at compile time by the number of registered syscalls. This means there is no space for another one.

You can check implementation for example for x86 architecture in arch/x86/kernel/syscall_64.c file, where sys_call_table is defined. Its size is exactly __NR_syscall_max+1. __NR_syscall_max is defined in kernel/asm-offsets_64.c as sizeof(syscalls) - 1 (it's the number of last syscall), wher syscall is a table with all the syscalls.

The only possible thing is to replace some existing syscall with yours as this won't require more space in memory. It's not really easy from kernel module as kernel does not export sys_call_table to modules as of version 2.6 (the last kernel version that had this symbol exported was 2.5.41. You can use this technique if you are developing new syscall and just want to avoid rebooting while experimenting. You will have to define your new system call and then replace it from module. To do this, you will have to change your kernel to export sys_call_table symbol to modules. To do this, you have to add following to lines to kernel/kallsyms.c (don't do this on production machines):

extern void *sys_call_table;
share|improve this answer
thanks for the information. –  abhi Sep 18 '12 at 3:54
add comment

Unfortunately you can't add system calls to kernel as loadable modules. You have to take the pain of compiling the kernel each time you add a new system call.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.