The
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
provides several interfaces to user-space applications that are used for different purposes and that have different properties by design. There are two types of
application programming interface
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how t ...
(API) in the Linux kernel that are not to be confused: the "kernel–user space" API and the "kernel internal" API.
Linux API
The Linux API is the kernel–user space API, which allows programs in user space to access system resources and services of the Linux kernel. It is composed out of the System Call Interface of the Linux kernel and the subroutines in the
GNU C Library
The GNU C Library, commonly known as glibc, is the GNU Project's implementation of the C standard library. Despite its name, it now also directly supports C++ (and, indirectly, other programming languages). It was started in the 1980s by ...
(glibc). The focus of the development of the Linux API has been to provide the ''usable features'' of the specifications defined in
POSIX
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
in a way which is reasonably compatible, robust and performant, and to provide additional useful features not defined in POSIX, just as the kernel–user space APIs of other systems implementing the POSIX API also provide additional features not defined in POSIX.
The Linux API, by choice, has been kept stable over the decades through a policy of not introducing breaking changes; this stability guarantees the portability of
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
. At the same time, Linux kernel developers have historically been conservative and meticulous about introducing new system calls.
Much available
free and open-source software
Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
is written for the POSIX API. Since so much more development flows into the Linux kernel as compared to the other POSIX-compliant combinations of kernel and C standard library, the Linux kernel and its API have been augmented with additional features. As far as these additional features provide a technical advantage, programming for the Linux API is preferred over the POSIX-API. Well-known current examples are
udev
udev (userspace ) is a device manager for the Linux kernel. As the successor of devfsd and hotplug, udev primarily manages device nodes in the directory. At the same time, udev also handles all user space events raised when hardware devices ...
,
systemd
systemd is a software suite that provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions; Its primary component is a "system and service manager ...
and
Weston
Weston may refer to:
Places Australia
* Weston, Australian Capital Territory, a suburb of Canberra
* Weston, New South Wales
* Weston Creek, a residential district of Canberra
* Weston Park, Canberra, a park
Canada
* Weston, Nova Scotia
* ...
. People such as
Lennart Poettering
Lennart Poettering (born 15 October 1980) is a German software engineer working for Microsoft and the original author of PulseAudio, Avahi and systemd.
Life and career
Poettering was born in Guatemala City but grew up in Rio de Janeiro, B ...
openly advocate to prefer the Linux API over the POSIX API, where this offers advantages.
At
FOSDEM
Free and Open source Software Developers' European Meeting (FOSDEM) is a non-commercial, volunteer-organized European event centered on free and open-source software development. It is aimed at developers and anyone interested in the free and ...
2016,
Michael Kerrisk
Michael Kerrisk is a technical author, programmer and, since 2004, maintainer of the Linux man-pages project, succeeding Andries Brouwer. He was born in 1961 in New Zealand and lives in Munich, Germany.
Kerrisk has worked for Digital Equipment, ...
explained some of the perceived issues with the Linux kernel's user-space API, describing that it contains multiple design errors by being non-extensible, unmaintainable, overly complex, of limited purpose, in violation of standards, and inconsistent. Most of those mistakes cannot be fixed because doing so would break the ABI that the kernel presents to the user space.
System Call Interface of the Linux kernel
''System Call Interface'' is the denomination for the entirety of all implemented and available
system calls
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
in a kernel. Various subsystems, such as e.g. the
Direct Rendering Manager
The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations su ...
(DRM), define their own system calls and the entirety is called 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.
The C standard library
A
C standard library
The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard.ISO/IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the original ANSI C standard, it wa ...
is a wrapper around the system calls of the Linux kernel; the combination of the Linux kernel System Call Interface and a C standard library is what builds the Linux API.
*
glibc
The GNU C Library, commonly known as glibc, is the GNU Project's implementation of the C standard library. Despite its name, it now also directly supports C++ (and, indirectly, other programming languages). It was started in the 1980s by ...
*
uClibc
__NOTOC__
In computing, uClibc (sometimes written µClibc) is a small C standard library intended for Linux kernel-based operating systems for embedded systems and mobile devices. uClibc was written to support μClinux, a version of Linux not ...
*
klibc
In computing, klibc is a minimalistic subset of the standard C library developed by H. Peter Anvin. It was developed mainly to be used during the Linux startup process, and it is part of the early user space, i.e. components used during kernel ...
*
Newlib
Newlib is a C standard library implementation intended for use on embedded systems. It is a conglomeration of several library parts, all under free software licenses that make them easily usable on embedded products.
It was created by Cygnus S ...
*
musl
musl is a C standard library intended for operating systems based on the Linux kernel, released under the MIT License. It was developed by Rich Felker with the goal to write a clean, efficient and standards-conformant libc implementation.
O ...
*
dietlibc
dietlibc is a C standard library released under the GNU General Public License Version 2, and proprietary licenses are also available. It was developed with the help of about 100 volunteers by Felix von Leitner with the goal to compile and lin ...
*
libbionic and
libhybris
Additions to POSIX
As in other
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
systems, additional capabilities of the Linux kernel exist that are not part of POSIX:
*
cgroups
cgroups (abbreviated from control groups) is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.
Engineers at Google started the work on this ...
subsystem, the system calls it introduces and libcgroup
* The system calls of the
Direct Rendering Manager
The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations su ...
, especially the driver-private ioctls for the command submission, are ''not'' part of the POSIX specifications.
*
Advanced Linux Sound Architecture
Advanced Linux Sound Architecture (ALSA) is a software framework and part of the Linux kernel that provides an application programming interface (API) for sound card device drivers.
Some of the goals of the ALSA project at its inception w ...
''could'' set system calls, which are not part of the POSIX specifications
* The system calls
futex
In computing, a futex (short for "fast userspace mutex") is a kernel system call that programmers can use to implement basic locking, or as a building block for higher-level locking abstractions such as semaphores and POSIX mutexes or condition ...
(fast userspace mutex),
epoll
epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.44 of the Linux kernel. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them. It i ...
,
splice
,
dnotify
dnotify is a file system event monitor for the Linux kernel, one of the subfeatures of the fcntl call. It was introduced in the 2.4 kernel series. It has been obsoleted by inotify, but will be retained for compatibility reasons.
Its function is es ...
,
fanotify
inotify (inode notify) is a Linux kernel subsystem created by John McCutchan, which monitors changes to the filesystem, and reports those changes to applications. It can be used to automatically update directory views, reload configuration files, ...
, and
inotify
inotify ( inode notify) is a Linux kernel subsystem created by John McCutchan, which monitors changes to the filesystem, and reports those changes to applications. It can be used to automatically update directory views, reload configuration files ...
have been exclusive to the Linux kernel so far.
* The system call
getrandom
Entropy-supplying system calls are system calls in Unix-like operating system kernels through which processes can obtain entropic or random data. The first of these was getentropy, introduced to the OpenBSD operating system in release 5.6 (Novembe ...
was introduced in version 3.17 of the
Linux kernel mainline
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU o ...
*
memfd
was proposed by the kdbus developers
**
memfd_create
was merged into the Linux kernel mainline in kernel version 3.17
*
readahead
Readahead is a system call of the Linux kernel that loads a file's contents into the page cache. This prefetches the file so that when it is subsequently accessed, its contents are read from the main memory (RAM) rather than from a hard disk drive ...
initiates a file "read-ahead" into page cache
DRM
DRM may refer to:
Government, military and politics
* Defense reform movement, U.S. campaign inspired by Col. John Boyd
* Democratic Republic of Madagascar, a former socialist state (1975–1992) on Madagascar
* Direction du renseignement milita ...
has been paramount for the development and implementations of well-defined and performant
free and open-source graphics device drivers without which no rendering acceleration would be available at all, or even worse, only the 2D drivers would be available in the
X.Org Server
X.Org Server is the free and open-source implementation of the X Window System display server stewarded by the X.Org Foundation.
Implementations of the client-side X Window System protocol exist in the form of ''X11 libraries'', which serve a ...
. DRM was developed for Linux, and since has been ported to other operating systems as well.
Further libraries
* libdrm (for
Direct Rendering Manager
The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations su ...
)
* libnl (The libnl suite is a collection of libraries providing APIs to netlink protocol based Linux kernel interfaces.)
* libevdev (for
evdev
evdev (short for 'event device') is a generic input event interface in the Linux kernel and FreeBSD. It generalizes raw input events from device drivers and makes them available through character devices in the /dev/input/ directory.
The us ...
)
* libasound (
Advanced Linux Sound Architecture
Advanced Linux Sound Architecture (ALSA) is a software framework and part of the Linux kernel that provides an application programming interface (API) for sound card device drivers.
Some of the goals of the ALSA project at its inception w ...
)
* ...
Linux ABI
The term Linux ABI refers to a kernel–user space ABI. The
application binary interface
In computer software, an application binary interface (ABI) is an interface between two binary program modules. Often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
An ' ...
refers to the compiled binaries, in
machine code
In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very ...
. Any such ABI is therefore bound to the
instruction set
In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions described by that ISA, such as a central processing unit (CPU), is called an ' ...
. 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
A Linux distribution (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and, often, a package management system. Linux users usually obtain their operating system by downloading one ...
s and
independent software vendor
An independent software vendor (ISV), also known as a software publisher, is an organization specializing in making and selling software, as opposed to computer hardware, designed for mass or niche markets. This is in contrast to in-house software, ...
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 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel based on the Intel 8086 microprocessor and its 8088 variant. The 8086 was introd ...
,
x86-64
x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mod ...
,
MIPS,
ARMv7-A
ARM (stylised in lowercase as arm, formerly an acronym for Advanced RISC Machines and originally Acorn RISC Machine) is a family of reduced instruction set computer (RISC) instruction set architectures for computer processors, configured ...
(32-Bit),
ARMv8-A
ARM (stylised in lowercase as arm, formerly an acronym for Advanced RISC Machines and originally Acorn RISC Machine) is a family of reduced instruction set computer (RISC) instruction set architectures for computer processors, configured ...
(64-Bit), etc. with the
endianness
In computing, endianness, also known as byte sex, is the order or sequence of bytes of a word of digital data in computer memory. Endianness is primarily expressed as big-endian (BE) or little-endian (LE). A big-endian system stores the most sig ...
, if both are supported.
It should be able to compile the software with different compilers against the definitions specified in the ABI and achieve full binary compatibility. Compilers that are
free and open-source software
Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
are e.g.
GNU Compiler Collection
The GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. The Free Software Foundation (FSF) distributes GCC as free software ...
,
LLVM
LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate represen ...
/
Clang
Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), ...
.
End-users are in fact not all interested in the Linux API (or the Windows API), but in the ABIs.
In-kernel APIs
There are a lot of kernel-internal APIs for all the subsystems to interface with one another. These are being kept fairly stable, but there is no guarantee for stability. In case new research or insights make a change seem favorable, an API is changed, all necessary rewrite 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-of-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.
In-kernel ABIs
Since there are no stable in-kernel APIs, there cannot be stable in-kernel ABIs.
Abstraction APIs
For several use cases, the Linux API is considered too low-level and higher abstraction APIs are used. Such of course still need to work on top of the low-level Linux APIs. Examples:
* implementation of the
OpenGL
OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
and
Vulkan
Vulkan is a low- overhead, cross-platform API, open standard for 3D graphics and computing. Vulkan targets high-performance real-time 3D graphics applications, such as video games and interactive media. Vulkan is intended to offer higher perfor ...
specifications in proprietary Linux graphics drivers and the free and open-source implementation in
Mesa
A mesa is an isolated, flat-topped elevation, ridge or hill, which is bounded from all sides by steep escarpments and stands distinctly above a surrounding plain. Mesas characteristically consist of flat-lying soft sedimentary rocks capped by ...
* implementation of the
OpenAL
OpenAL (Open Audio Library) is a cross-platform audio application programming interface (API). It is designed for efficient rendering of multichannel three-dimensional positional audio. Its API style and conventions deliberately resemble those ...
specification
*
Simple DirectMedia Layer
Simple DirectMedia Layer (SDL) is a cross-platform
In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in sever ...
: abstraction API for input/sound/etc. available for many operating systems
*
Simple and Fast Multimedia Library
Simple and Fast Multimedia Library (SFML) is a cross-platform software development library designed to provide a simple application programming interface (API) to various multimedia components in computers. It is written in C++ with
bindings a ...
: like above
See also
* ''
The Linux Programming Interface
''The Linux Programming Interface: A Linux and UNIX System Programming Handbook'' is a book written by Michael Kerrisk, which documents the APIs of the Linux kernel and of the GNU C Library (glibc).
Book
It covers a wide array of topics deali ...
'' by
Michael Kerrisk
Michael Kerrisk is a technical author, programmer and, since 2004, maintainer of the Linux man-pages project, succeeding Andries Brouwer. He was born in 1961 in New Zealand and lives in Munich, Germany.
Kerrisk has worked for Digital Equipment, ...
*
Semaphore (programming)
In computer science, a semaphore is a variable or abstract data type used to control access to a common resource by multiple threads and avoid critical section problems in a concurrent system such as a multitasking operating system. Semaphores ...
*
system call
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
is a function to facilitate programs to request services from the kernel
**
**
netlink
Netlink is a socket family used for inter-process communication (IPC) between both the kernel and userspace processes, and between different userspace processes, in a way similar to the Unix domain sockets available on certain Unix-like operati ...
socket family used for IPC between kernel and user space processes, designed as the successor of ; Netlink was added by
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
WNIC
WNIC (100.3 FM) is a commercial radio station licensed to Dearborn, Michigan and serving the Metro Detroit media market. Owned by iHeartMedia, WNIC broadcasts an adult contemporary radio format. Each year, usually on the first Friday of Novemb ...
drivers use it to communicate with user-space.
*
Windows API
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
article on various API available on Microsoft Windows operating systems
**
windows.h
windows.h is a Microsoft Windows, Windows-specific header file for the C (programming language), C and C++ programming languages which contains declarations for all of the functions in the Windows API, all the common macros used by Windows progr ...
header file for the
C programming language
''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well as ...
which contains declarations for ''all'' of the functions in the Windows API
*
Wine
Wine is an alcoholic drink typically made from fermented grapes. Yeast consumes the sugar in the grapes and converts it to ethanol and carbon dioxide, releasing heat in the process. Different varieties of grapes and strains of yeasts are m ...
a compatibility layer between Linux and programs written for Microsoft Windows
*
libhybris – compatibility layer between Linux and programs written for Android
References
External links
The Linux Kernel API 5.0(new
sphinx
A sphinx ( , grc, σφίγξ , Boeotian: , plural sphinxes or sphinges) is a mythical creature with the head of a human, the body of a lion, and the wings of a falcon.
In Greek tradition, the sphinx has the head of a woman, the haunches of ...
format)
The API of Linux kernel 2.6.20an
4.12(in deprecated htmldocs format)
API/ABI changes review for LinuxThe Linux Programming Interfacebook
Linux and ''glibc'' API changessince
The Linux Programming Interface
''The Linux Programming Interface: A Linux and UNIX System Programming Handbook'' is a book written by Michael Kerrisk, which documents the APIs of the Linux kernel and of the GNU C Library (glibc).
Book
It covers a wide array of topics deali ...
was released in 2010
Interactive Linux kernel mapwith main API functions and structures
PDFversion
Linux Device Driversby Jonathan Corbet, Greg Kroah-Hartman and Alessandro Rubini, 3rd edition
Linux Kernel Linked List Explained
{{DEFAULTSORT:Linux Kernel Api