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;
}
其中copy_to_user() 从内核空间拷贝数据到用户空间,失败返回没有被拷贝的字节数,成功返回0.参数to的时候有个__user限定,这个在~/include/linux/compiler.h中有如下定义:
# define __user __attribute__((noderef, address_space(1)))
表示这是一个用户空间的地址,即其指向的为用户空间的内存
大家可能对这个__attribute__感到比较迷惑,不过没关系,google一下嘛
__attribute__是gnu c编译器的一个功能,它用来让开发者使用此功能给所声明的函数或者变量附加一个属性,以方便编译器进行错误检查,其实就是一个内核检查器。