【linux】Linux kernel uapi header file(用户态头文件)

uapi目录的创建原因

Linux在3.7以后把很多header file移到 include/uapi或是arch/xxxx/include/uapi下,为了解决include recursive(循环包含头文件)的问题。
英文参考文档:https://lwn.net/Articles/507794/

解决include recursive问题的方法

例如:在A.h中inline function时发现里面用到的某些struct定义在B.h中,而B.h中又有inline function需要用到A.h中的struct,就会造成循环包含recursive include

uapi的创建

把userspace API的文件独立到 include/uapi跟arch/xxxx/include/uapi下,
举例来说本来header中

 /* Header comments (copyright, etc.) */
 #ifndef _XXXXXX_H     /* Guard macro preventing double inclusion */
 #define _XXXXXX_H

 [User-space definitions]
 #ifdef __KERNEL__
 [Kernel-space definitions]
 #endif /* __KERNEL__ */

 [User-space definitions]
 #endif /* End prevent double inclusion */

换成如下两个文件

a. kernel space的东西放在原本路径下

 /* Header comments (copyright, etc.) */

 #ifndef _XXXXXX_H     /* Guard macro preventing double inclusion */
 #define _XXXXXX_H

 #include <include/uapi/path/to/header.h>

 [Kernel-space definitions]

 #endif /* End prevent double inclusion */

 /* Header comments (copyright, etc.) */

b. uapi目录下创建同名文件
#ifndef _UAPI__XXXXXX_H /* Guard macro preventing double inclusion */
#define _UAPI__XXXXXX_H

 [User-space definitions]

 #endif /* End prevent double inclusion */

好处

减少与简化kernel-only header的size;
现在kernel header有的是文件中一部分export给userspace用。这样做简化了头文件间的交互相依性。
处理用户态的人更容易追踪API的变更,透过git来追踪uapi下的log更容易在每个kernel的释放版本中知道做了那些修改
转发自:http://vh21.github.io/linux/2014/11/21/linux-kernel-uapi-include-file.html

 

所以kernel/include/linux/xx.h是用于kernel空间,kernel/include/uapi/linux/xx.h用于用户空间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值