I have defined a 'helloworld' system call in my Linux kernel and recompiled it. The code for the system call is:
#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'm calling this system call from the same operating system with another kernel version, which does not include this system call, using the below code:
#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 var
gets -1 instead of displaying an error.
Why do you expect an error? The syscall
function exists, the linker can resolve it. So there won't be an error from the compiler or linker.
When you run the executable, the old kernel's syscall
function detects that 326 is an invalid system call number and the functions returns -1, probably with errno
set to ENOSYS
= system call not implemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With