Documentation/translations/zh_TW/process/stable-api-nonsense.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_TW/process/stable-api-nonsense.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_TW/process/stable-api-nonsense.rst- Extension
.rst- Size
- 9263 bytes
- Lines
- 160
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. _tw_stable_api_nonsense:
.. include:: ../disclaimer-zh_TW.rst
:Original: :ref:`Documentation/process/stable-api-nonsense.rst
<stable_api_nonsense>`
譯者::
中文版維護者: 鍾宇 TripleX Chung <xxx.phy@gmail.com>
中文版翻譯者: 鍾宇 TripleX Chung <xxx.phy@gmail.com>
中文版校譯者: 李陽 Li Yang <leoyang.li@nxp.com>
胡皓文 Hu Haowen <2023002089@link.tyut.edu.cn>
Linux 內核驅動接口
==================
寫作本文檔的目的,是爲了解釋爲什麼Linux既沒有二進制內核接口,也沒有穩定
的內核接口。這裏所說的內核接口,是指內核裏的接口,而不是內核和用戶空間
的接口。內核到用戶空間的接口,是提供給應用程序使用的系統調用,系統調用
在歷史上幾乎沒有過變化,將來也不會有變化。我有一些老應用程序是在0.9版本
或者更早版本的內核上編譯的,在使用2.6版本內核的Linux發佈上依然用得很好
。用戶和應用程序作者可以將這個接口看成是穩定的。
執行綱要
--------
你也許以爲自己想要穩定的內核接口,但是你不清楚你要的實際上不是它。你需
要的其實是穩定的驅動程序,而你只有將驅動程序放到公版內核的源代碼樹裏,
纔有可能達到這個目的。而且這樣做還有很多其它好處,正是因爲這些好處使得
Linux能成爲強壯,穩定,成熟的操作系統,這也是你最開始選擇Linux的原因。
入門
-----
只有那些寫驅動程序的“怪人”纔會擔心內核接口的改變,對廣大用戶來說,既
看不到內核接口,也不需要去關心它。
首先,我不打算討論關於任何非GPL許可的內核驅動的法律問題,這些非GPL許可
的驅動程序包括不公開源代碼,隱藏源代碼,二進制或者是用源代碼包裝,或者
是其它任何形式的不能以GPL許可公開源代碼的驅動程序。如果有法律問題,請諮
詢律師,我只是一個程序員,所以我只打算探討技術問題(不是小看法律問題,
法律問題很實際,並且需要一直關注)。
既然只談技術問題,我們就有了下面兩個主題:二進制內核接口和穩定的內核源
代碼接口。這兩個問題是互相關聯的,讓我們先解決掉二進制接口的問題。
二進制內核接口
--------------
假如我們有一個穩定的內核源代碼接口,那麼自然而然的,我們就擁有了穩定的
二進制接口,是這樣的嗎?錯。讓我們看看關於Linux內核的幾點事實:
- 取決於所用的C編譯器的版本,不同的內核數據結構裏的結構體的對齊方
式會有差別,代碼中不同函數的表現形式也不一樣(函數是不是被inline
編譯取決於編譯器行爲)。不同的函數的表現形式並不重要,但是數據
結構內部的對齊方式很關鍵。
- 取決於內核的配置選項,不同的選項會讓內核的很多東西發生改變:
- 同一個結構體可能包含不同的成員變量
- 有的函數可能根本不會被實現(比如編譯的時候沒有選擇SMP支持
一些鎖函數就會被定義成空函數)。
- 內核使用的內存會以不同的方式對齊,這取決於不同的內核配置選
項。
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.