In my project I am using char driver to communicate between user space and kernel space. I use the function copy_to_user(void user *to, const void *from, unsigned long n)
to copy data from kernel space to user space buffer. We can find this function under #include < asm/uaccess.h >
header file.
I complied the project using Linux Kernel version 4.4.0-59-generic, Ubuntu OS version 16.04 LTS and its working fine without any error and warning. I get the desired output.
I compiled the same project using Linux kernel version 4.12.8, Ubuntu OS version 16.04.2 LTS and it throws me an warning during compile time WARNING: "copy_to_user" [/home/ldrv1/Desktop/Vijay/code/build/uts.ko] undefined!
. When I do insmod of my module I get error as follows insmod: ERROR: could not insert module uts.ko: Unknown symbol in module
. I think that #include <asm/uaccess.h>
header file is still supported in 4.12.8 kernel version else I would have got fatal error: no such file or directory error while compiling. I tried updating the linux kernel headers using apt-get install linux-headers-$(uname -r)
command and I got the following response:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.12.8
E: Couldn't find any package by glob 'linux-headers-4.12.8'
E: Couldn't find any package by regex 'linux-headers-4.12.8'
This OS version 16.04.2 LTS has linux-headers-4.10.0-35. How do I get rid of this warning? Suggestions and support appreciated. If more information is required please feel free to ask.
You should use #include <linux/uaccess.h>
for 4.12.8.
Here is the definition.
In 4.4 some drivers use #include <asm/uaccess.h>
whilst the others
use #include <linux/uaccess.h>
.
#include <linux/uaccess.h>
is preferable, I think.
You should do apt-get update
and then apt-get install linux-headers-generic
.