Linux: warning implicit declaration of function of system call

Viewed 1404

So I am writing a new system call and adding it to the kernel of Linux which works when I explicitly call it through the system call number: syscall(335, pid); but gives an warning: implicit declaration of function of the system call when using its general name: s_call(pid). I can't figure out why its not finding it.

-test file is already in the kernel
-the system call is already defined in sys.c SYSCALL_DEFINE1(s_call, int, who)
-has an asmlinkage in syscalls.h asmlinkage long sys_s_call(int pid);
-in the syscall_64.tbl as

335 64  s_call      __x64_sys_s_call

-headers being used in the test file:

#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
1 Answers

That's because you need to write a wrapper for the system call in your program. Wrapper functions don't just magically show up in user-space when you write system calls:

long s_call(int pid)
{
    return syscall(335, pid);
}

If you have a header file with your syscall's number, you don't have to use a magic number:

long s_call(int pid)
{
    return syscall(__NR_s_call, pid);
}

Also, you should be using pid_t instead of int.

Related