System Calls and Libraries
- The book defines a system call as a controlled entry point into the kernel.
- This allows the process to request the kernel perform an action
- This is the kernel Application Programming Interface (API)
- This includes
- Creating a new process
- I/O
- Interprocess communications.
- He suggests man 2 syscalls
- System Calls
- Change the processor state from user mode to kernel mode
- There are a fixed set, the implementation is actually by number
- When a system call is made
- A wrapper function is employed to make the system call just like a normal procedure call
- The arguments are taken from the stack and placed in registers by the wrapper function.
- The system call number is written to a register.
- On an X86 the trap instruction is called.
- This is the actual switch to kernel space
- The kernel then
- Saves the registers on the kernel stack
- Calls the appropriate service routine based on the system call number.
- restores the registers
- Returns control to the wrapper function in user mode.
- If there is an error, the global variable errno is set.
- An appropriate return value is set.
- Library functions
- For convenience, there are a number of library functions provided to access the kernel
- These generally do some setup then perform a system call
- For example, brk is the way to manipulate the heap
- But malloc and free and new and delete are library functions which simplify this task.