Documentation/translations/zh_CN/process/stable-api-nonsense.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/process/stable-api-nonsense.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/process/stable-api-nonsense.rst- Extension
.rst- Size
- 9153 bytes
- Lines
- 156
- 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
.. _cn_stable_api_nonsense:
.. include:: ../disclaimer-zh_CN.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>
Linux 内核驱动接口
==================
写作本文档的目的,是为了解释为什么Linux既没有二进制内核接口,也没有稳定
的内核接口。这里所说的内核接口,是指内核里的接口,而不是内核和用户空间
的接口。内核到用户空间的接口,是提供给应用程序使用的系统调用,系统调用
在历史上几乎没有过变化,将来也不会有变化。我有一些老应用程序是在0.9版本
或者更早版本的内核上编译的,在使用2.6版本内核的Linux发布上依然用得很好
。用户和应用程序作者可以将这个接口看成是稳定的。
执行纲要
--------
你也许以为自己想要稳定的内核接口,但是你不清楚你要的实际上不是它。你需
要的其实是稳定的驱动程序,而你只有将驱动程序放到公版内核的源代码树里,
才有可能达到这个目的。而且这样做还有很多其它好处,正是因为这些好处使得
Linux能成为强壮,稳定,成熟的操作系统,这也是你最开始选择Linux的原因。
入门
-----
只有那些写驱动程序的“怪人”才会担心内核接口的改变,对广大用户来说,既
看不到内核接口,也不需要去关心它。
首先,我不打算讨论关于任何非GPL许可的内核驱动的法律问题,这些非GPL许可
的驱动程序包括不公开源代码,隐藏源代码,二进制或者是用源代码包装,或者
是其它任何形式的不能以GPL许可公开源代码的驱动程序。如果有法律问题,请咨
询律师,我只是一个程序员,所以我只打算探讨技术问题(不是小看法律问题,
法律问题很实际,并且需要一直关注)。
既然只谈技术问题,我们就有了下面两个主题:二进制内核接口和稳定的内核源
代码接口。这两个问题是互相关联的,让我们先解决掉二进制接口的问题。
二进制内核接口
--------------
假如我们有一个稳定的内核源代码接口,那么自然而然的,我们就拥有了稳定的
二进制接口,是这样的吗?错。让我们看看关于Linux内核的几点事实:
- 取决于所用的C编译器的版本,不同的内核数据结构里的结构体的对齐方
式会有差别,代码中不同函数的表现形式也不一样(函数是不是被inline
编译取决于编译器行为)。不同的函数的表现形式并不重要,但是数据
结构内部的对齐方式很关键。
- 取决于内核的配置选项,不同的选项会让内核的很多东西发生改变:
- 同一个结构体可能包含不同的成员变量
- 有的函数可能根本不会被实现(比如编译的时候没有选择SMP支持
一些锁函数就会被定义成空函数)。
- 内核使用的内存会以不同的方式对齐,这取决于不同的内核配置选
项。
- Linux可以在很多的不同体系结构的处理器上运行。在某个体系结构上编
译好的二进制驱动程序,不可能在另外一个体系结构上正确的运行。
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.