## Kernel Calls and Thread Context

When a user thread makes a call into any kernel code, the kernel code continues to run in the context of the user thread. This applies to device driver code.

The stack is swapped to a kernel-side stack and the permissions of the thread are increased to kernel privilege, but otherwise the user thread is still running. Each thread has a small kernel stack used to handle kernel calls – it would be dangerous to continue using the normal thread stack in case it overflows. Some calls are handled in this state, others – typically device drivers – will post a message to a kernel side thread to carry out the request.