#include <linux/kernel.h>
#include <linux/uaccess.h>
unsigned long long cnt = 0;
asmlinkage long sys_customcall(unsigned long long __user *output)
{
unsigned long err;
err = copy_to_user(output, &cnt, sizeof(unsigned long long));
return err;
}
I'm implementing a simple system call. I would like to copy a value from the kernel (cnt
) to user pointer (output
). However, when I run the code err = 8 which is sizeof(unsigned long long)
- user side values are not changing. What have I done wrong?
I'm using linux-kernel version 5.4.59.
The user-level code is as following.
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
unsigned long long cnt=0;
long int err = syscall(436, &cnt);
printf("System call returned %lu\n", err);
printf("System call returned %llu\n", cnt);
return 0;
}