-1

From this post, I learned

  • syscall is the default way of entering kernel mode on x86-64.
  • In practice, recent kernels are implementing a VDSO

Then I look up manual, in http://man7.org/linux/man-pages/man2/syscall.2.html :

The first table lists the instruction used to transition to kernel mode (which might not be the fastest or best way to transition to the kernel, so you might have to refer to vdso(7)), the register used to indicate the system call number, the register used to return the sys‐ tem call result, and the register used to signal an error.....

But I lack some essential knowledge to understand the statements.

Is it true that VDSO(7) is the implementation of syscall(2), or syscall(2) will invoke VDSO(7) to complete system call?

If it is not true, what's the relationship between VDSO(7) and SYSCALL(2)?

Chen Li
  • 4,824
  • 3
  • 28
  • 55

2 Answers2

2

the VDSO(7) is not the implementation of syscall(2). Without VDSO(7), syscall will be run in user-space applications. In this case will be occur context switching. if use VDSO(7), will be run syscall without context switching. The kernel automatically maps into the address space of all user-space applications with vDSO.

Eric Lee
  • 54
  • 7
1

Read more carefully the man pages syscalls(2), vdso(7) and the wikipages on system calls and VDSO. Read also the operating system wikipage and Operating Systems: Three Easy Pieces (freely downloadable).

System calls are fundamental, they are the only way a user-space application can interact with the operating system kernel and use services provided by it. So every program uses some system calls (unless it crashes and is terminated by some signal(7)). System calls requires a user to kernel transition (e.g. thru a SYSCALL or SYSENTER machine instruction on x86) which is somehow "costly" (e.g. could take a microsecond).

VDSO is only a clever optimization (to avoid the cost of a genuine system call, for very few functions like clock_gettime(2) which also still exist as genuine system calls), a bit like some shared library magically provided by the kernel without any real file. Some programs (e.g. statically linked ones, or those not using libc like BONES or probably busybox) don't use it.

You can avoid VDSO (or not use it), and earlier kernels did not have it. But you cannot avoid doing system calls, and programs usually do a lot of them.

Play also with strace(1) to understand the (many) system calls done by an application or a running process.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thanks for your inspiration, the question actually is raised from ostep (chapter 6)which you just mentioned, though not directly. I learn much about the relationship between they two. this is quite a awesome answer:P – Chen Li May 05 '18 at 06:34
  • Oh, quite sorry, it is a typo, "If you can come, I will feel honored". – Chen Li May 05 '18 at 06:48