copy_to_user undefined in linux kernel version 4.12.8 - linux

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.

The function copy_to_user and copy_from_user defined in asm/uaccess.h . I think you have some issue when you define this function. I wrote the character device driver with some example about data transfer between Kernel space and User space. View my github: my code for reference. Please star if you feel it is helpful for you :). it has small bug in example 3. I am figuring them, but example 1 and example 2 work well

The answer given by Bronislav Elizaveti is correct. If instead of #include <asm/uaccess.h> we use #include <linux/uaccess.h>, then we won't get the warning.
If you still want to use only #include <asm/uaccess.h>, then you'll need to use _copy_to_user instead of copy_to_user (with the same arguments). A simple _ will do the job.

Related

OpenVino Inference Engine C API not found

I installed the OpenVino on my Ubuntu 20.04 using the apt command.
sudo apt install intel-openvino-dev-ubuntu20-2021.3.394
I am trying to compile this simple program using gcc 1.c -linference_engine_c_api.
#include <stdio.h>
#include <c_api/ie_c_api.h>
int main() {
printf("C API Successfully Loaded!");
}
But the compilation fails with the following error:
1.c:2:10: fatal error: c_api/ie_c_api.h: No such file or directory
2 | #include <c_api/ie_c_api.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
How do I solve this?
You cannot directly call gcc for the 1.c file. You need to create a script to compile necessary dependencies (like CMake).
For example, in \opt\intel\openvino_2021.3.394\deployment_tools\inference_engine\samples\c there is build_sample.h script. This script is used to perform all compilation and it uses CMake. Same goes for gcc, to run the inference lib you need to compile the script first before calling ie_c_api.h. 1.c file cannot be run directly when gcc compiler does not support the operation.
Please go to Integrate the Inference Engine with Your Application - OpenVINO™ Toolkit (openvinotoolkit.org) for reference.

Trying to find gsl library, the only thing I can find is a loop in the system

I am working currently a little bit with wind data and I am using GSL and PlPlot to visualize and work with it.
When I try to add GSL or PlPlot libraries:
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>
I get this message:
inter.c:4:27: fatal error: gsl/gsl_errno.h: No such file or directory
#include <gsl/gsl_errno.h>
^
Far as I know, this means that I need to add the complete path to my library file, when I search for gsl then I get this:
find: File system loop detected; ‘/.snapshots/1/snapshot’ is part of the same file system loop as ‘/’.
/.snapshots/2/snapshot/usr/share/doc/packages/gsl
/.snapshots/93/snapshot/usr/share/doc/packages/gsl
/.snapshots/94/snapshot/usr/share/doc/packages/gsl
I have read a little bit (still searching on the web), something went wrong with the installation of gsl? and plplot?. Strange as it appears is the same with math.h. There is a main difference here, because math.h is detected but gsl/plplot are not. How can I find my path to the library files and how can I eliminate that recursion?.
By the way, gsl and math were installed by default on SuSE at the begining and plplot was installed after using yast. Also I can find the GSL and PlPlot directories but the files are missing.
Thanks for any help guys.

Installing SDL2 on Linux

I try to run simple test.cpp from Twinklebar SDL tutorial, I get this error:
test.cpp:2:10: fatal error: 'SDL2/SDL.h' file not found
So I look up the sdl development package in Ubuntu/Mint:
aptitude search sdl | grep 2
All I can find is this:
libsdl1.2-dev
Does this mean my only option is to install from sources?
It depends which Ubuntu version you are running but yes, there is a libsdl2 package for Ubuntu: http://packages.ubuntu.com/search?keywords=sdl2
The package you want is called libsdl2-dev.
Also, about the #include <SDL/SDL.h> line, it seems the recommended way doing it is by adjusting your compiler flags to add SDL's include pah and use #include "SDL.h". See https://forums.libsdl.org/viewtopic.php?t=5997 for more details on that.

Xattrs are not supported

I am trying to perform a little testing of XATTRs. I recompiled my kernel with ALL the XATTRs enabled.
Now, when I include the header of xattrs :
#include <attr/xattr.h>
I receive an error no such file or directory. I am using UBUNTU 11.10 64 bit system, and I cannot understand why XATTRs are not supported ?
Adding support in the kernel doesn't make the header files magically appear on their own! Install libattr1-dev.
"attr/xattr.h" was replaced by "sys/xattr.h" so try this instead #include <sys/xattr.h>

How to get the processor number on linux

I need to get the processor number in my program with C/C++ language. My code
like as follow:
#include <unistd.h>
int main()
{
int processorNum = sysconf(_SC_NPROCESSORS_CONF);
return 0;
}
when i compile it , it had two errors:
error: '_SC_NPROCESSORS_CONF' was not declared in this scope
error: 'sysconf' was not declared in this scope
so ,what should i do.
ps: my complier's version is gcc version 4.3.2 (Debian 4.3.2-1.1).should i link a library file
ps: Hi all, excuse me ,i made some mistakes. i forgot the head file.
1、The most reliable way is to read /proc/cpuinfo file. like grep processor proc/cpuinfo
2、use command lscpu

Resources