【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 includeuapi的创建
把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
相关文章推荐
- Linux kernel uapi header file
- linux 内核头文件 linux kernel header
- linux 内核头文件 linux kernel header
- linux 内核头文件 linux kernel header
- linux 内核头文件 linux kernel header
- linux 用户空间调用kernel 的api
- Access the Linux kernel using the /proc filesystem
- Linux系统调用及用户编程接口(API)(二)
- Linux Kernel API (2.6)
- The Linux kernel API.pdf 1,64 MB 2004-01-24
- Linux 用户线程数与文件句柄树调整(nproc与nofile的问题)
- 在 Linux 虚拟机中手动安装或升级 VMware Tools以及Searching for a valid kernel header path... The path "" is not val
- 在 Linux 下用户空间与内核空间数据交换的方式,第 2 部分: procfs、seq_file、debugfs和relayfs
- 原来还有linux kernel api
- Access the Linux kernel using the /proc filesystem
- Linux系统调用及用户编程接口(API)
- Linux新建用户误删除进入时su: warning: cannot change directory to /home/xx: No such file or director
- Linux 3.8 kernel是给Linux用户的圣诞礼物
- Linux系统调用及用户编程接口(API)
- 查阅linux kernel api