System Call Handler


It is not possible for user-space applications to execute kernel code directly. They cannot simply make a function call to a method existing in kernel-space because the kernel exists in a protected memory space.

Instead, user-space applications must signal to the kernel that they want to execute a system call and have the system switch to kernel mode, where the system call can be executed in kernel-space by the kernel on behalf of the application.

The mechanism to signal the kernel is a software interrupt

Incur an exception, and the system will switch to kernel mode and execute the exception handler. The exception handler, in this case, is the system call handler.

Initiating the System Call Handler

Before calling the System call routine, the following registers are initialized

  1. rax - contains system call number;
  2. rcx - contains return address to the user space;
  3. r11 - contains register flags;
  4. rdi - contains first argument of a system call handler;
  5. rsi - contains second argument of a system call handler;
  6. rdx - contains third argument of a system call handler;
  7. r10 - contains fourth argument of a system call handler;
  8. r8 - contains fifth argument of a system call handler;
  9. r9 - contains sixth argument of a system call handler;

If the System Call requires more than 6 arguments, the remaining ones are placed on the stack

results matching ""

    No results matching ""