System calls are nowadays already called through a library interface, for C this is a part of libc (so glibc on most Linux distributions, though there are alternatives such as musl or newlib).
You could try to look at simple existing libc implementations first (glibc is quite complex), there's a list at https://wiki.osdev.org/C_Library
An overview over the available system calls in Linux can be found in the syscalls man page. However, this does not tell you how to execute a system call - this depends on the specific architecture of your computer.
A system call can be invoked by using a special CPU instruction (SYSCALL/SYSENTER on 64-bit x86, SVC on ARM, ECALL on RISC-V or TRAP on Motorola 68k) or a special hardware interrupt/trap (int 0x80 on 32-bit x86). In addition to executing the syscall itself, you have to know how to pass parameters to the OS. This can take place on the stack or in CPU registers (or a combination of both). This convention is also dependent on the architecture and ABI (application binary interface) of your system. A good concise introduction for x86 can be found at [1].
There are also completely different approaches to system calls, e.g. the one described in [2], but you won't find these implemented in any standard Linux distribution.
All system call interfaces, as well as how system calls happen are thoroughly documented there. Though, I would just use libc, since all this stuff is a bit messy and have plenty of legacy stuff.
2 comments
[ 2.8 ms ] story [ 18.6 ms ] threadYou could try to look at simple existing libc implementations first (glibc is quite complex), there's a list at https://wiki.osdev.org/C_Library
An overview over the available system calls in Linux can be found in the syscalls man page. However, this does not tell you how to execute a system call - this depends on the specific architecture of your computer.
A system call can be invoked by using a special CPU instruction (SYSCALL/SYSENTER on 64-bit x86, SVC on ARM, ECALL on RISC-V or TRAP on Motorola 68k) or a special hardware interrupt/trap (int 0x80 on 32-bit x86). In addition to executing the syscall itself, you have to know how to pass parameters to the OS. This can take place on the stack or in CPU registers (or a combination of both). This convention is also dependent on the architecture and ABI (application binary interface) of your system. A good concise introduction for x86 can be found at [1].
There are also completely different approaches to system calls, e.g. the one described in [2], but you won't find these implemented in any standard Linux distribution.
[1] https://linuxhint.com/what-is-a-linux-system-call/
[2] Livio Soares and Michael Stumm, FlexSC: Flexible System Call Scheduling with Exception-Less System Calls, Proc. of OSDI 2010, https://static.usenix.org/event/osdi10/tech/full_papers/Soar...
All system call interfaces, as well as how system calls happen are thoroughly documented there. Though, I would just use libc, since all this stuff is a bit messy and have plenty of legacy stuff.