As mentioned earlier, the driving layer is the application layer is separated, the driver layer code can not use the re-application layer, the application layer can not directly manipulate the driver code, then the application layer and the driving layer is how to achieve the exchange between the data, the method is through the corresponding interface function.
(1) Copy_from_user
unsigned long copy_from_user (void *to, const void __user *from, unsigned long n) {might_sleep (); if (ACCESS_OK (Verify_read, from, n)) n = __copy_from_user (to, from, N); else memset (to, 0, N); return n;}
This function is to copy data from the user space to the kernel space, failed to return the number of bytes not copied, successfully returned 0, note that the user space data can not be directly copied to the kernel space through memcpy, because the kernel space and user space address is not in the same mapping area. Kernel space and user-space memory are not directly accessible.
(2) Copy_to_user
unsigned long copy_to_user (void __user *to, const void *from, unsigned long n) {might_sleep (); Bug_on ((long) n < 0); if (ACCESS_OK (Verify_write, to, n)) n = __copy_to_user (to, from, N); return n;}
The return value, like Copy_from_user, returns 0 successfully, failing to return the number of bytes that have not been copied successfully.
The parameter to has a __user qualification, which is defined in the ~/include/linux/compiler.h as follows:
# define __user __attribute__ (Noderef, Address_space (1)))
Indicates that this is the address of a user space, which is the memory that it points to for user space.
__ATTRIBUTE__ is a feature of the GNU C compiler that allows developers to use this feature to attach a property to a declared function or variable to make it easier for the compiler to check for errors, which is actually a kernel checker.
Above two function references
Http://blog.sina.com.cn/s/blog_55465b470100kdn9.html
This article is from the "11664570" blog, please be sure to keep this source http://11674570.blog.51cto.com/11664570/1872418
Interface for driving and application of learning