__user表示是一个用户空间的指针,所以kernel不可能直接使用。
#ifdef __CHECKER__
# define __user __attribute__((noderef, address_space(1)))
# define __kernel /* default address space */
#else
# define __user
# define __kernel
#endif
noderef告诉编译器,不应该解除该指针的引用,因为在当前地址空间中它是没有意义的。
这里的CHECKER表示是否使用了Sprase(就是一种静态分析工具,用来分析内核源码中的BUG)。是不是想研究一下了?呵呵。可以参见http://sparse.wiki.kernel.org/index.php/Main_Page
所以对于这种变量,在kernel中使用要用到copy_to_user和copy_from_user。
__user宏简单告诉编译器(通过 noderef)不应该解除这个指针的引用(因为在当前地址空间中它是没有意义的)。#ifdef __CHECKER__
# define __user __attribute__((noderef, address_space(1)))
# define __kernel /* default address space */
#else
# define __user
# define __kernel
#endif
noderef告诉编译器,不应该解除该指针的引用,因为在当前地址空间中它是没有意义的。
这里的CHECKER表示是否使用了Sprase(就是一种静态分析工具,用来分析内核源码中的BUG)。是不是想研究一下了?呵呵。可以参见http://sparse.wiki.kernel.org/index.php/Main_Page
所以对于这种变量,在kernel中使用要用到copy_to_user和copy_from_user。
本文介绍Linux内核中如何处理用户空间指针(__user),解释了noderef属性的作用,并说明了在内核中使用用户空间指针时为何需要采用copy_to_user和copy_from_user函数。

被折叠的 条评论
为什么被折叠?



