I know that the system calls are not in the C standard Library. Is there any library (some sort of a system library) where the system calls are?
If there is such a l
A system call can work in a few different ways, depending on the target architecture, but in any case, it is not a library call. It is a way for a running user-space program to call some functionality in the kernel.
In very old systems, this typically meant to jump directly to some address where this kernel function starts. Later, kernels introduced "jump tables" adding a layer of indirection, so the addresses don't have to change when the kernel was changed. This simple approach doesn't work any more for a long time (and linux never used it) because nowadays, user-space programs run in some "protected" mode that restricts what they can do and lets them run in virtual address space, thus protecting the system from crashing, just because one user-space program is erroneous.
So new methods are needed that put the CPU in a mode allowing any code (privileged mode) and still making sure control is passed to the kernel only, so no other code can accidentally run in privileged mode. On x86
, this was typically done using an int
instruction that triggers a soft interrupt and the kernel handled that interrupt. On amd64
, there is a special syscall
instruction for entering the kernel.
In any case, C doesn't know about syscalls. You can't directly issue a syscall in C (but you can with inline assembly, if you know your target architecture). The C library on Linux includes a lot of functions that are just tiny wrappers around actual syscalls, so you can use them from C directly.
Although not in the scope of the question: Contrary to Linux, Windows hides syscalls to an extent that they aren't even documented and subject to change any time. On Windows, you're supposed to only use the system libraries (like user32.dll
) for your application software.