System Calls

202310081637
Status: #idea
Tags: OS

System Calls

Info

Dynamic linking - Library is loaded only if it is used in the program

Note

Linux and Solaris are hybrid systems.
The kernel has both monolithic and modular parts

Windows is mostly monolithic. Some subsystems use microkernels

Attention

Application Binary Interface (ABI) is the architechture equivalent of an API

System Design Goals

  1. User goals
    • Convenient to use
    • Easy to learn
    • Reliable
    • Fast and responsive
  2. System goals
    • Easy to design, implement and maintain
    • Flexible
    • Reliable, error-free and efficient

Mechanism - How to do things
Policy - Decided what to be done

Separation between mechanism and policy is important to allow for flexible design

Info

EAX/RAX stores the syscall number before you reach the common entrypoint for all syscalls

Note

The registers are filled with appropriate values before running INT 0x80

This interrupt is used to transfer control from user to kernel

Warning

Having more than 5 parameters passed to a system call leads to memory protection checks, increasing overhead

This is is because there are 5 usable registers

How a syscall works

  1. Check if the syscall number in EAX is valid
  2. User data is pushed to the stack
  3. Jump to the location of the syscall number starts, and execute it
  4. Pop the stack
  5. Return control to the user

How to pass data from user to kernel

Warning

System calls in Linux are not vectored.

The entrypoint to kernel code is same for all syscalls.

Note

A system call leads to loss of locality of reference, causing cahce misses and pipeline flushes.

Attention

A syncronous read operation is blocking.

An async read is non-blocking.

Info

Transitions b/w user and kernel space are more expensive than a function call.

This is because all context needs to be saved.

Designing a System Call

Attention

Ensure that the full memory region passed is suitable, and not just the first and last locations.

Difference b/w syscall and function call

Attention

2 ways to save context:

  1. Selective backup (of registers)
  2. Save all - Done in Intel - Few registers
Note

If you want to write a highly efficient program, you can directly raise the interrupt with the corresponding syscall number

Disadvantages of System Calls


References