How to use a function pointer in a Linux System Call? The purpose of using a function pointer in a Linux system call is to avoid recompile kernel whenever you change its implementation. By fixing a system call interface, you only need to compile the Linux kernel for once. You can use a Linux Kernel Module (LKM) to do whatever you want to achieve for a Linux system call by assigning the function pointer defined in the system call to a function, which is implemented in the LKM. Keep in mind that the real Linux system calls DON'T adopt this kind of function pointer for security reasons. This trick is only used to save your time for the course project. The followings are a sample system call implementation. -------------------------------------------------------------------------------- #include /* Required for EXPORT_SYMBOL */ #include #include long (* mycall_ptr) (int i) = NULL; /* Function pointer */ EXPORT_SYMBOL(mycall_ptr); /* Export the function pointer */ asmlinkage long sys_mycall(int i) { return mycall_ptr ? mycall_ptr(i) : -ENOSYS; } -------------------------------------------------------------------------------- Then, if you need to assign a value to the function pointer defined in the above system call. The following are parts of a LKM, which will use the exported mycall_ptr. -------------------------------------------------------------------------------- #include /* Required by all modules */ #include /* Required for printk */ #include /* Required for the macros */ extern void * mycall_ptr; /* Declare the extern function pointer */ long mycall_real(int i) { printk(KERN_INFO "I am the function to do the real job for mycall\n"); return 0; } static int __init use_function_pointer_init(void) { printk(KERN_INFO "Will assign a new value to mycall_ptr \n"); mycall_ptr = mycall_real; return 0; } static void __exit use_function_pointer_exit(void) { printk(KERN_INFO "Will restore the old value of mycall_ptr\n"); mycall_ptr = NULL; } module_init(use_function_pointer_init); module_exit(use_function_pointer_exit); -------------------------------------------------------------------------------- By now, you can compile the LKM and test whether the system call - mycall will work in your desired way. Whenever you want to change the system call, you only need to modify the LKM and recompile it instead of building the whole Linux kernel and reboot your Linux box. Isn't it wonderful!