Using a simple system call as an example (e.g. getpid, or uptime), describe what is
generally involved in providing the result, from the point of calling the function in the C
library to the point where that function returns
Answer:
A system call is completed as follows:
- As the function is called, an interrupt of the type “software exception” is placed on the processor, causing a Context Switch to take place between the calling function and the kernel.
- The exception handler will clear out and save user registers to the kernel stack so that control may be passed on to the C function corresponding to the syscall.
- The syscall is executed.
- The value(s) returned by the syscall is placed into the correctly corresponding registers of the CPU (the same ones that a user function normally places its return values in).
- The handler takes this value, restores user registers and returns said value to the user programme that called it.