How does the undefined system call return -1?

I defined the "helloworld" system call in my Linux kernel and recompiled it. System call code:

#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/sched.h>
#include<linux/syscalls.h>
#include "processInfo.h"
asmlinkage long sys_listProcessInfo(void)
{
    printk("Hello World. My new syscall..FOSS Lab!\n");
    return 0;
}

      

But when I call this system call from the same operating system with a different kernel version that does not include this system call using the code below:

#include<stdio.h>
#include<linux/kernel.h>
#include<sys/syscall.h>
#include<unistd.h>
int main()
{
    long int var = syscall(326);
    printf("Returning: %ld\n",var);
    return 0;
}

      

The variable var

gets the value -1. I would like to know how it var

gets -1 instead of displaying an error.

+3


source to share


1 answer


Why are you expecting an error? The function syscall

exists, the linker can resolve it. This way the compiler or linker won't be a bug. When you run the executable, the old syscall

kernel function detects that 326 is an invalid system call number, and the functions return -1, possibly errno

set to ENOSYS

= system call not implemented.



+2


source







All Articles