Linux kernel interfaces: Difference between revisions

Content deleted Content added
In-kernel APIs: phrasing improvements
m Bot: http → https
 
(21 intermediate revisions by 11 users not shown)
Line 1:
{{Short description|An overview and comparison of the Linux kernalkernel API'sAPIs and ABI's.ABIs}}
{{Multiple issues|section=|
{{essay-like|date=July 2014}}
{{Advert|date=March 2019}}
}}
 
[[File:Linux kernel interfaces.svg|thumb|upright=1.5|Linux API, Linux ABI, and in-kernel APIs and ABIs]]
 
The [[Linux kernel]] provides multiple interfaces to [[User space and kernel space|user-space and kernel-mode]] code. thatThe areinterfaces usedcan forbe varyingclassified purposesas andeither that[[application haveprogramming varyinginterface]] properties(API) by design. There are two types ofor [[application programmingbinary interface]] (APIABI), inand thethey Linuxcan be classified as either kernel:–user space or kernel-internal.
 
# the "kernel–user space" API; and
# the "kernel internal" API.
 
== {{Anchor|Linux API}}Linux API ==
[[File:Linux API.svg|thumb|upright=1.5|The '''Linux API''' is composed out of the system call interface of the Linux kernel, the [[GNU C Library]] (by [[GNU]]), [[cgroups|libcgroup]],<ref name="libcgroup">{{cite web|url=https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/|title=ControlGroupInterface|publisher=[[freedesktop.org]]}}</ref> [[Direct Rendering Manager|libdrm]], [[Advanced Linux Sound Architecture|libalsa]] and [[evdev|libevdev]]<ref name="libevdev">{{cite web |url=httphttps://www.freedesktop.org/wiki/Software/libevdev/ |title=libevdev |publisher=[[freedesktop.org]]}}</ref> (by [[freedesktop.org]]).]]
[[File:Linux kernel API.svg|thumb|upright=1.5|Linux API vs. [[POSIX]] API]]
 
The Linux API includes the kernel&ndash;user space API, which allows code in user space to access system resources and services of the Linux kernel.<ref>{{cite web
| url = httphttps://www.linux.it/~rubini/docs/ksys/ksys.html
| title = Kernel System Calls
| date = 2006-11-02 | access-date = 2014-11-11
Line 36 ⟶ 30:
 
=== {{Anchor|System Call Interface|SCI}} System call interface of the Linux kernel===
The ''system call interface'' of a kernel is athe set of all implemented and available [[system calls]] in a kernel. In the Linux kernel, various subsystems, such as the [[Direct Rendering Manager]] (DRM), define their own system calls, all of which are part of the system call interface.
 
Various issues with the organization of the Linux kernel system calls are being publicly discussed. Issues have been pointed out by Andy Lutomirski, [[Michael Kerrisk]] and others.<ref>{{cite web |url=httphttps://www.linux-magazine.com/Issues/2014/165/Kernel-News |title=System Call Organization}}</ref><ref>{{cite web |url=https://lkml.org/lkml/2014/2/27/571 |title= Making a universal list of syscalls? |publisher=[[LKML]] |date=2014-02-27}}</ref><ref>{{cite web |url=https://lwn.net/Articles/585415/ |title=Flags as a system call API design pattern |publisher=[[LWN.net]] |date=2014-02-12}}</ref><ref>{{cite web |url=https://lwn.net/Articles/446528/ |title=On vsyscalls and the vDSO |publisher=[[LWN.net]] |date=2011-06-08}}</ref>
 
=== The C standard library ===
Line 52 ⟶ 46:
* [[dietlibc]]
* [[Bionic (software)|libbionic]] and [[Hybris (software)|libhybris]]
 
Although the landscape is shifting, amongst these options, glibc remains the most popular implementation, to the point of many treating it as the default and the term equivalent to libc.
 
==== Additions to POSIX ====
Line 74 ⟶ 70:
 
== Linux ABI ==
{{Expert needed|Freefree and open-source software|ex2=Softwaresoftware|ex3=Computingcomputing|reason=This section mostly ignores the kernel-userspace ABI (that is very real and important thing) and jumps into userspace-to-userspace APIs|date=February 2018}}
[[File:Linux API and Linux ABI.svg|thumb|upright=1.5|The Linux API and the Linux [[Application binary interface|ABI]] ]]
{{Main article|x32 ABI|Linux Standard Base}}
 
The term Linux ABI refers tois a kernel–user space ABI. TheAs [[applicationABI binaryis interface]] refers to the compiled binaries, ina [[machine code]]. Anyinterface, suchthe Linux ABI is therefore bound to the [[instruction set]]. Defining a useful ABI and keeping it stable is less the responsibility of the Linux kernel developers or of the developers of the GNU C Library, and more the task for [[Linux distribution]]s and [[independent software vendor]]s (ISVs) who wish to sell and provide support for their proprietary software as binaries only for such a single Linux ABI, as opposed to supporting multiple Linux ABIs.
 
An ABI has to be defined for every instruction set, such as [[x86]], [[x86-64]], [[MIPS architecture|MIPS]], [[ARMv7-A]] (32-Bit), [[ARMv8-A]] (64-Bit), etc. with the [[endianness]], if both are supported.
Line 87 ⟶ 83:
Many kernel-internal APIs exist, allowing kernel subsystems to interface with one another. These are being kept fairly stable, but there is no guarantee for stability. A kernel-internal API can be changed when such a need is indicated by new research or insights; all necessary modifications and testing have to be done by the author.
 
The Linux kernel is a monolithic kernel, hence device drivers are kernel components. To ease the burden of companies maintaining their (proprietary) device drivers out-outside of- the main kernel tree, stable APIs for the device drivers have been repeatedly requested. The Linux kernel developers have repeatedly denied guaranteeing stable in-kernel APIs for device drivers. Guaranteeing such would have faltered the development of the Linux kernel in the past and would still in the future and, due to the nature of free and open-source software, are not necessary. Ergo, by choice, the Linux kernel has no ''stable'' in-kernel API.<ref>{{cite web|url=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-api-nonsense.rst |title=The Linux Kernel Driver Interface}}</ref>
 
== In-kernel ABIs ==
Since there are no stable in-kernel APIs, there cannot be stable in-kernel ABIs.<ref>{{cite web|url=httphttps://abi-laboratory.pro/tracker/timeline/linux/ | title=Analysis of ABI changes in the Linux kernel |publisher=Andrey Ponomarenko's ABI laboratory|date=2016-03-15}}</ref>
 
== Abstraction APIs ==
[[File:Linux kernel and OpenGL video games.svg|thumb|OpenGL is indeed an abstraction API to make use of diverse GPUs of multiple vendors without the need to program for each one specifically.]]
[[File:Division of labor cpu and gpu.svg|thumb|But the implementation of the OpenGL-specification is executed on the CPU in the context of the running operating system. One design goal of [[Vulkan (API)|Vulkan]] was to make the "graphics driver", i.e. the implementation of the graphics API, do less.]]
For severalmany use cases, the Linux API is considered too low-level, andso APIs of higher abstraction APIsmust arebe used. SuchHigher-level ofAPIs coursemust stillbe need to workimplemeted on top of the lowlower-level Linux APIs. Examples:
 
* Implementation of the [[OpenGL]] and [[Vulkan (API)|Vulkan]] specifications in proprietary Linux graphics drivers and the free and open-source implementation in [[Mesa (computer graphics)|Mesa]].
Line 104 ⟶ 100:
== See also ==
{{Portal|Linux}}
** {{monoAnnotated link|[[File descriptor|eventfd()]]}}
* ''[[The Linux Programming Interface]]'' by [[Michael Kerrisk]]
* {{Annotated link|Hybris (software)}}
* [[Semaphore (programming)]]
* ''[[{{Annotated link|The Linux Programming Interface]]}}'' by [[Michael Kerrisk]]
* [[system call]]{{snd}} is a function to facilitate programs to request services from the kernel
* {{Annotated link|netlink}}
** {{mono|[[File descriptor|eventfd()]]}}
* [[{{Annotated link|Semaphore (programming)]]}}
** [[netlink]]{{snd}} socket family used for IPC between kernel and user space processes, designed as the successor of {{mono|[[ioctl]]}}; Netlink was added by [[Alan Cox (computer programmer)|Alan Cox]] during Linux kernel 1.3 development as a character driver interface to provide multiple kernel and user-space bidirectional communications links. Then, Alexey Kuznetsov extended it during Linux kernel 2.1 development to provide a flexible and extensible messaging interface to the new advanced routing infrastructure. Since then, Netlink sockets have become one of the main interfaces that kernel subsystems provide to user-space applications in Linux. Modern [[Wireless network interface controller|WNIC]] [[Comparison of open-source wireless drivers|drivers]] use it to communicate with user-space.
* {{Annotated link|system call}}
* [[Windows API]]{{snd}} article on various API available on Microsoft Windows operating systems
* {{Annotated link|Windows API}}
** [[windows.h]]{{snd}} header file for the [[C (programming language)|C programming language]] which contains declarations for ''all'' of the functions in the Windows API
* {{Annotated link|windows.h}}
* [[Wine (software)|Wine]]{{snd}} a compatibility layer between Linux and programs written for Microsoft Windows
* {{Annotated link|Wine (software)}}
* [[Hybris (software)|libhybris]] – compatibility layer between Linux and programs written for Android
 
== References ==
Line 121 ⟶ 117:
*[https://web.archive.org/web/20070227215533/http://www.gnugeneration.com/books/linux/2.6.20/kernel-api/ The API of Linux kernel 2.6.20] and [https://www.kernel.org/doc/htmldocs/kernel-api/ 4.12] (in deprecated htmldocs format)
*[https://abi-laboratory.pro/?view=timeline&l=linux API/ABI changes review for Linux]
* [httphttps://man7.org/tlpi/ The Linux Programming Interface] book, [httphttps://man7.org/tlpi/api_changes/ Linux and ''glibc'' API changes] since [[The Linux Programming Interface]] was released in 2010
*{{usurped|1=[https://archive.today/20121220032539/http://www.makelinux.net/kernel_map/ Interactive Linux kernel map]}} with main API functions and structures, {{usurped|1=[https://web.archive.org/web/20180827040646/http://www.makelinux.net/kernel_map/LKM.pdf PDF]}} version
* {{usurped|1=[https://archive.today/20130221193824/http://www.makelinux.net/ldd3 Linux Device Drivers]}} by Jonathan Corbet, Greg Kroah-Hartman and Alessandro Rubini, 3rd edition
* [http://isis.poly.edu/kulesh/stuff/src/klist/ Linux Kernel Linked List Explained] {{Webarchive|url=https://web.archive.org/web/20090925130610/http://isis.poly.edu/kulesh/stuff/src/klist/ |date=2009-09-25 }}