Using Ubuntu 18.04.3 LTS (GNU/Linux 5.0.21+ x86_64)
I created a simple syscall and am trying to pass input (the integer 5) through it by calling it in a c program and then see if I can get the input back out. I keep getting random junk as my output rather than my input.
Simple system call:
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/sched.h>
#include<linux/syscalls.h>
#include<linux/signal.h>
#include "tags.h"
asmlinkage int sys_get_tag(int pid)
{
return pid;
}
my userspace test code:
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
int pid = syscall(335, 5); // 335 is the syscall number, 5 is the input to the syscall that I am trying to return
printf("return: %d \n", pid);
return 0;
}
my output:
return: 4980568
I get it to work when I return some integer in my syscall, like return 5; for example; so I know the syscall is being used.