I'm trying to import new system call in the kernel 3.19. I've followed the tutorial given here!
This is my simple code to implement factorial calculation via system call.
#include <linux/kernel.h>
asmlinkage long sys_fact(int a)
{
int n;
int c;
for(n = 1;n <= a;n++)
c = c * n;
printk(KERN_INFO "Factorial calculated!\n");
return((long) c);
}
I'm getting Undefined reference to sys_fact error when I try to compile the C code. The program in which I'm using this system call is as follows.
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int n;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
printf("Factorial of %d = %d\n", n, sys_fact(9));
return 0;
}
My system is 64 bit ubuntu 14.04 and I've followed above mentioned tutorial according to my system.
Also, I've combined following commands while installing kernel, and I think this is the reason it did not gave error while installation of kernel.
make && make modules_install && make install
Kernel installation took 2-3 hours, and I'm frustrated now. Please help!!
Edits I made to syscall_64.tbl(final four entries).
320 common kexec_file_load sys_kexec_file_load
321 common bpf sys_bpf
322 64 execveat stub_execveat
323 common fact sys_fact
linux-3.8/arch/x86/syscalls/syscall_32.tblhttp://linuxseekernel.blogspot.in/2014/07/adding-system-call-in-x86-qemu.html