When I invoke a system call in user mode,how did the call get processed in OS?
Does it invoke some some executable binary or some standard library?
If yes,wh
int X in assembly translates to a system call number n.
Ex read syscall may be given a number 4.
At the system startup, OS builds a table of pointers called interrupt descriptor table (IDT) which has a list of address for system calls along wit the privilege needed to execute them.
The Current Privilege Level(CPL) is saved in one of the bit of CS register(technically 2 bits on x86).
This are the steps followed by an int instruction:
• Fetch the n’th descriptor from the IDT, where n is the argument of int.
• Check that CPL in %cs is <= DPL, where DPL is the privilege level in the descriptor.
• If not then the user didn't have enough privilege to execute this and will result in an int 13 instruction (general protection fault) being executed,(user didnt have enough privilege)
• If yes then the user code has enough privilege to do this system call,the current execution context is saved ( registers etc), because we now switch to kernel mode.
The information includes registers,flags because when the system call is finsihed we want to continue execution from where we left.
• The parameters to the system call are saved on the kernel stack, because system call are executed in kernel mode.
VSYSCALL ( FAST SYSTEM CALL)
Every time system call is executed by the user, the Os saves the current state of the machine(i.e the register, stack pointer etc) and switches to the kernel mode for execution. For some system call it is not necessary to save all the register. Ex gettime of day system call reads the current time and the system call returns. So some system calls are implemented through what are called vsyscalls. Here when a system call is made, it is executed in the user space itself without ever switching to the kernel. So time is saved.
See here for details on vsyscall http://www.trilithium.com/johan/2005/08/linux-gate/
and here Anyone can understand how gettimeofday works?