linux内核 header,Linux kernel uapi header file

Linux在3.7以後把很多header file移到 include/uapi或是arch/xxxx/include/uapi下,感覺起來要追define變得很麻煩,不太清楚為了什麼做這個修改,找了一下看到LWN有一篇文章介紹The UAPI header file split。看起來是個不賴的修正。重點整理如下,

原先待解決的問題

要解決include recursive的問題。如原先要在A.h加inline function時發現裡面用到的某些struct被定義在B.h,而B.h中又有inline function需要用到A.h的struct,就會造成recursive include

概念

把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的東西放在原本path並include uapi下同檔名檔案

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

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

#include

[Kernel-space definitions]

#endif/* End prevent double inclusion */

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

b. uapi下的檔案,include guard稍微有點不同

#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用。這做法簡化header file間複雜的交互相依性。

處理userspace ecosystem的人較容易追蹤API的變更,透過git來追蹤uapi下的log很容易在每個kernel的release週期就知道做了哪些修改

處理過程遇到的問題

檔案太多,必須用scipt自動化

如何讓Linus接受?共74 commits,其中65 commits是透過script做的,共修改超過3500檔案,超過30萬行

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值