How do system calls work?

前端 未结 6 601
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 20:02

I understand that a user can own a process and each process has an address space (which contains valid memory locations, this process can reference). I know that a process can c

6条回答
  •  遇见更好的自我
    2021-01-29 20:17

    Normal programs usually do not "compile syscalls". For each syscall you usually a corresponding userspace library function (usually implemented in libc on Unix-like systems). For example, the mkdir() function forwards its arguments to the mkdir syscall.

    On GNU systems (I guess it's the same for others), a syscall() function is used from the 'mkdir()' function. The syscall function/macros are usually implemented in C. For example have a look at INTERNAL_SYSCALL in sysdeps/unix/sysv/linux/i386/sysdep.h or syscall in sysdeps/unix/sysv/linux/i386/sysdep.S (glibc).

    Now if you look at sysdeps/unix/sysv/linux/i386/sysdep.h, you can see that the call to the kernel is done by ENTER_KERNEL which historically was to call interrupt 0x80 in i386 CPUs. Now it calls a function (I guess it is implemented in linux-gate.so which is a virtual SO file mapped by the kernel, it contains the most efficient way to make a syscall for your type a CPU).

提交回复
热议问题