4

I want to know if there is any libc function that does not invoke any syscall()? For example, for the libc function "strcpy()", does it any syscall (let's consider all possible linux systems).

Richard
  • 14,642
  • 18
  • 56
  • 77

2 Answers2

5

System calls are very heavy performance-wise since they imply a context switch into the kernel. Therefore, for a simple library function like strcpy (whose functionality is effectively equivalent to while(*d++ = *s++), but potentially optimized for the architecture), a system call would not make any sense.

Note that a page fault during copying could result in a kernel context switch and the appearance of a system call, but that would not be a result of strcpy directly calling a system call.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • strcpy needs to write to virtual memory, so in the operating system hierarchy, where is virtual memory residing? in kernel space or user space? – Richard Oct 08 '12 at 15:36
  • 1
    Virtual memory is managed by the kernel; user programs sees *only* virtual memory. – nneonneo Oct 08 '12 at 15:37
4

syscalls are somewhat like an interface from the userland (the place where your program runs) to the kernel land. They are needed when you're doing things which only the kernel can, like communicating with hardware (e.g. read bytes from the network card, starting a process, even allocating memory via malloc (using brk), etc.).

Userland functions on the other hand, like strcpy, are not indented to do syscalls. They don't need special privileges to do what they do, they just operate on the memory of the process in user land.

As syscalls introduce a major performance penalty (changing modes from user to kernel land and back is costly), having those in a often called function like strcpy wouldn't make sense from a design point of view and are as such unlikely to be seen.

nemo
  • 55,207
  • 13
  • 135
  • 135