Hacker News new | ask | show | jobs
by praptak 803 days ago
There's another rabbit hole which Musl seems to have skipped. Using `syscall` directly is not all there is to calling system functions on Linux.

The "better behaved" way is to call vDSO. It's a magic mini-library which the kernel automatically maps into your address space. Thus the kernel is free to provide you with whatever code it deems optimal for doing a system call.

In particular some of the system calls might be optimized away and not require the `syscall` at all because they are executed in the userspace. Historically you could expect vDSO to choose between different mechanisms of calling the kernel (int 0x80, sysenter).

https://man7.org/linux/man-pages/man7/vdso.7.html

1 comments

It's only on 32-bit x86 that the vDSO contains the generic fast syscall shim. On x86-64, the standard method for syscalls is the SYSCALL instruction, and the vDSO contains only a few time- and SGX-related functions.