In what library on Linux are the system calls and how is this library linked to the executable object file that contains the system calls?

前端 未结 3 1450
鱼传尺愫
鱼传尺愫 2021-01-06 16:14

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

3条回答
  •  误落风尘
    2021-01-06 16:31

    A system call (listed in syscalls(2)) is mostly interpreted by the linux kernel. The C library just contains the glue code to interface to the kernel. From the application (user-land) point of view, a system call is atomic and is nearly a single machine code instruction (SYSCALL or SYSENTER on x86-64). The ABI used to invoke system calls is not the C ABI. See also Linux Assembler HowTo and x86-64 ABI. Use strace(1) to understand what system calls are done by some command or process.

    Read about operating systems, system calls, linux kernel.

    A SYSENTER (or SYSCALL) machine instruction switches the CPU mode from user-mode to kernel-mode. The kernel then run many (millions) of machine instructions in privileged [kernel] mode, and finally would execute a SYSEXIT (or SYSRETURN) machine instruction to return back to user-mode. The kernel could even schedule another task. So from the application's point of view, a system call is a kind of elementary virtual machine instruction; the application code just "sees" a very complex machine instruction doing an entire system call, and that illusion is provided by the kernel.

    See also this answer to a related question.

    (You could avoid the libc by directly doing syscalls in assembler; Bones is an example of such program; but almost all programs on Linux are using some libc).

    Read also vdso(7), ld-linux(8), elf(5).

提交回复
热议问题