Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You first should understand what is the role of the <a href="http://en.wikipedia.org/wiki/Linux_kernel" rel="nofollow noreferrer">linux kernel</a>, and that applications interact with the kernel <em>only</em> thru <a href="http://en.wikipedia.org/wiki/System_call" rel="nofollow noreferrer">system calls</a>.</p> <p>In effect, an application runs on the "virtual machine" provided by the kernel: it is running in the <a href="http://en.wikipedia.org/wiki/User_space" rel="nofollow noreferrer">user space</a> and can only do (at the lowest machine level) the set of machine instructions permitted in <a href="http://en.wikipedia.org/wiki/CPU_modes" rel="nofollow noreferrer">user CPU mode</a> augmented by the instruction (e.g. <code>SYSENTER</code> or <code>INT 0x80</code> ...) used to make system calls. So, from the user-level application point of view, a syscall is an atomic pseudo machine instruction.</p> <p>The <a href="http://tldp.org/HOWTO/Assembly-HOWTO/" rel="nofollow noreferrer">Linux Assembly Howto</a> explains how a syscall can be done at the assembly (i.e. machine instruction) level.</p> <p>The <a href="http://www.gnu.org/software/libc/" rel="nofollow noreferrer">GNU libc</a> is providing C functions corresponding to the syscalls. So for example the <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html" rel="nofollow noreferrer">open</a> function is a tiny glue (i.e. a wrapper) above the syscall of number <code>NR__open</code> (it is making the syscall then updating <code>errno</code>). Application usually call such C functions in libc instead of doing the syscall.</p> <p><sup>You could use some other <code>libc</code>. For instance the <a href="http://musl-libc.org/" rel="nofollow noreferrer">MUSL libc</a> is somhow "simpler" and its code is perhaps easier to read. It also is wrapping the raw syscalls into corresponding C functions.</sup></p> <p>If you add your own syscall, you better also implement a similar C function (in your own library). So you should have also a header file for your library.</p> <p>See also <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/intro.2.html" rel="nofollow noreferrer">intro(2)</a> and <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/syscall.2.html" rel="nofollow noreferrer">syscall(2)</a> and <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/syscalls.2.html" rel="nofollow noreferrer">syscalls(2)</a> man pages, and the role of <a href="http://davisdoesdownunder.blogspot.fr/2011/02/linux-syscall-vsyscall-and-vdso-oh-my.html" rel="nofollow noreferrer">VDSO in syscalls</a>.</p> <p>Notice that <a href="http://syscalls.kernelgrok.com/" rel="nofollow noreferrer">syscalls</a> are not C functions. They don't use the call stack (they could even be invoked without any stack). A syscall is basically a number like <code>NR__open</code> from <code>&lt;asm/unistd.h&gt;</code>, a <code>SYSENTER</code> machine instruction with conventions about which registers hold before the arguments to the syscall and which ones hold after the result[s] of the syscall (including the failure result, to set <code>errno</code> in the C library wrapping the syscall). The conventions for syscalls are not the calling conventions for C functions in the ABI spec (e.g. <a href="https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI" rel="nofollow noreferrer">x86-64 psABI</a>). So you need a C wrapper.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload