您的位置:首页 > 运维架构 > Linux

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

2018-03-16 14:56 1691 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: