I am new to this and just learning about the kernel, and I am trying to add a custom call to kernel 4.20.4. This is the steps that I did.
- First I create the file (
kernel/printmsg.c
) that contains the code.
#include <linux/kernel.h>
#include <linux/syscalls.h>
SYSCALL_DEFINE1(printmsg, int, i)
{
printk(KERN_DEBUG, "TESTING %d", i);
return 1;
}
- Next, I add this file to the
kernel/Makefile
obj-y = fork.o exec_domain.o panic.o \
// A few more lines
obj-y += printmsg.o // I added this line
- Finally, I add the system call to the syscall table on
arch/x86/entry/syscalls/syscall_64.tbl
(I'm building this on a 64-bit Ubuntu) by appending this line:
548 64 printmsg sys_printmsg
Now, I proceed to run make
. However, it has this error:
arch/x86/entry/syscall_64.o:(.rodata+0x1120): undefined reference to `sys_printmsg'
Makefile:1034: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1
I've been scratching my head for a long time for this but I can't seem to realised what went wrong.
Hope that anyone that managed to find a problem can help out a poor soul. Thanks in advance!