Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what header is copy_from_user() declared?

Can anyone please help me with getting the proper header files needed for the copy_from_user method?

I found a few of the include headers I need, but my compiler keeps saying that they are not found. I am running CentOS on my machine. I have tried yum installing various kernel-headers and devel packages but still no luck.

Is there a special segment I need to add in my gcc command? Everything I find on the Internet only tells me how to use the method but not actually how I can get access to it in the first place.

like image 522
user1566813 Avatar asked Jul 31 '12 19:07

user1566813


People also ask

Where is Copy_from_user defined?

Defined in 2 files as a function: include/linux/uaccess. h, line 149 (as a function) tools/virtio/linux/uaccess.

Why do we use copy_ to_ user() in kernel programs?

The copy_to_user function copies a block of data from the kernel into user space. This function accepts a pointer to a user space buffer, a pointer to a kernel buffer, and a length defined in bytes. The function returns zero on success or non-zero to indicate the number of bytes that weren't transferred.


1 Answers

I assume you're developing a kernel module, because outside of it trying to use copy_from_user wouldn't make sense. Either way, in the kernel use:

#include <linux/uaccess.h>

Edit: if building a kernel module is what you want, you may want to look at this Hello World Linux Kernel Module. Specifically the makefile portion may be of interest to you (search for obj-m).

like image 196
Giel Avatar answered Oct 03 '22 23:10

Giel