skip to content

Describe the layering of Windows NT: what runs in user mode, what runs in kernel mode, and what do the executive, the kernel layer, and the HAL each do?

level: middleimportance: must knowfreq 62%

answer

  1. two hardware modes, several software layers
  2. one kernel image, many machines
  3. managers on top, dispatcher underneath
  4. ntdll is the real boundary
  5. drivers share the kernel address space

basics

~20 s

Windows NT layers user mode — applications, subsystem DLLs such as kernel32.dll, and ntdll.dll — over kernel mode, where ntoskrnl.exe holds the executive managers (I/O, memory, process, security), the kernel layer that schedules and dispatches interrupts, plus drivers and the HAL.

solid answer

~50 s

NT is a layered hybrid design. In user mode sit the application, the Win32 subsystem DLLs — `kernel32.dll`/`kernelbase.dll`, `user32.dll`, `gdi32.dll`, `advapi32.dll` — and under them `ntdll.dll`, which holds the actual system-call stubs plus the loader and heap. Kernel mode is mostly `ntoskrnl.exe`, itself two layers: the *executive*, a set of managers (object, I/O, memory, process and thread, configuration a.k.a. the registry, security reference monitor, cache), and below it the *kernel layer*, which does thread scheduling, interrupt and DPC dispatch, and the low-level synchronisation primitives the executive builds on. Device drivers — file system, storage, network — load into that same kernel address space as peers, not into a protected middle ring. `hal.dll` sits underneath and hides platform detail (interrupt controllers, timers, DMA, bus access) so one kernel image boots on many machines. Graphics is the exception: `win32k.sys` puts the window manager and GDI in kernel mode.

go deeper

for a junior

Be able to say that Windows separates user mode from kernel mode, that ntoskrnl.exe is the kernel image with hal.dll under it, and that applications reach the OS through DLLs rather than touching hardware.

for a middle

Explain the two layers inside ntoskrnl.exe — executive managers over the kernel layer that schedules and dispatches interrupts — name what the HAL abstracts, and place ntdll.dll as the last user-mode stop.

for a senior

Use the layering to localise real failures: a bugcheck implicates kernel-mode code sharing one address space, an access-denied on open implicates the Security Reference Monitor, and driver stacks explain where an I/O request actually died.

for a principal

Own the hybrid tradeoff you inherited: in-kernel managers and drivers buy speed and cost isolation, so decide deliberately what may run in kernel mode on a fleet and what enforcement — signing, verifier, code-integrity policy — pays for that decision.

## Two hardware modes, many software layers Every processor Windows supports offers at least two privilege levels; on x86-64 they are ring 3 (user mode) and ring 0 (kernel mode). User-mode code runs in a private virtual address space, cannot execute privileged instructions, and cannot touch devices directly. Kernel-mode code shares one address space and has the full instruction set. Those are hardware facts, and they are not what an interviewer is testing. The question is what NT chose to put in each mode and how the kernel side is organised internally. ## User mode: subsystem DLLs over ntdll.dll An application calls the documented Win32 API: `CreateFileW` in `kernel32.dll` (largely forwarded to `kernelbase.dll` since Windows 7), windows and input in `user32.dll`, drawing in `gdi32.dll`, registry and security helpers in `advapi32.dll`. These are ordinary user-mode DLLs. Their job is to translate the stable, documented Win32 contract into the *native* NT API. Below them is `ntdll.dll`. It exports the `Nt*`/`Zw*` routines, each of which is a short stub ending in the `syscall` instruction — that stub is the real user/kernel boundary. `ntdll.dll` also contains the image loader, the heap manager, and the process startup path, which is why it is mapped into every process, even one that never links Win32. Win32 was designed as one *environment subsystem* among several — early NT also shipped OS/2 and POSIX subsystems. A user-mode server process, `csrss.exe`, still holds the parts of the Win32 subsystem that need central coordination (console handling, some process and thread bookkeeping, shutdown), while the bulk of the work goes straight from the caller's own thread into the kernel. ``` CreateFileW kernel32.dll / kernelbase.dll user mode NtCreateFile ntdll.dll stub user mode syscall -------------------------------------- mode switch NtCreateFile ntoskrnl.exe, I/O manager kernel mode IRP -> file system driver -> volume -> disk driver ``` ## Kernel mode: the executive over the kernel layer `ntoskrnl.exe` is not one flat blob. The upper part is the **executive**: the object manager (every kernel object and the object namespace), the I/O manager (which packages requests as IRPs and sends them down driver stacks), the memory manager, the process and thread manager, the configuration manager (the registry), the cache manager, the power and Plug-and-Play managers, and the Security Reference Monitor, which performs the access check when a handle is opened. Under the executive is the **kernel layer** proper, whose routines carry the `Ke` prefix. It owns thread scheduling and context switching, interrupt and DPC dispatch, spinlocks, and the dispatcher objects (events, mutexes, semaphores, timers) the executive builds on. The division is deliberate: the kernel layer is small, largely non-pageable, and implements *mechanism only* — it makes no policy decisions. Policy — may this caller open that object, where does this page come from — belongs to the executive. ## The HAL `hal.dll` sits beneath the kernel and abstracts the platform, not the devices: interrupt controller programming, the clock and timers, DMA, firmware and bus access, bringing up other CPUs on an SMP machine. Its purpose is that Microsoft ships one kernel image that boots across an enormous range of hardware. It is *not* the driver model, and it is not what talks to your network card. ## Drivers are peers, not a lower ring A Windows kernel-mode driver loads into the same address space with the same privileges as the executive and is arranged in stacks — file system filter over file system over volume over disk over storage port/miniport. NT does not use rings 1 and 2. The direct consequence: a driver that corrupts memory corrupts *kernel* memory, and the system bugchecks (the blue screen) rather than killing one process. Driver signing, the driver verifier and hypervisor-enforced code integrity all exist because of that blast radius. ## Why the layering earns interview time It lets you localise a symptom. A bugcheck means kernel-mode code — a driver or the kernel — not an application bug. An access-denied error from an open call means the Security Reference Monitor rejected the request at handle-open time, not at each read. A hang in a `WaitFor…` call means a dispatcher object at the kernel layer never signalled. Being able to name the layer that produced the behaviour is what separates a candidate who has debugged Windows from one who has only used it.

  • Where does csrss.exe fit, if most Win32 calls go straight to the kernel?
    `csrss.exe` is the user-mode server half of the Win32 subsystem. It handles the parts that need one coordinating process rather than per-caller execution — console and session work, some process and thread bookkeeping, and shutdown sequencing. Ordinary API calls do not round-trip through it; they run on the caller's own thread down into `ntdll.dll` and the kernel, which is why NT is called a hybrid rather than a microkernel.
  • So is Windows a microkernel?
    No. NT borrowed microkernel vocabulary — a small kernel layer, environment subsystems, an object model — but keeps the memory manager, I/O manager, file systems, drivers and even the window manager inside kernel mode for speed. A true microkernel would run those as isolated user-mode servers. "Hybrid" is the accurate description, and the tradeoff is the expected one: fewer boundary crossings, larger blast radius.
  • Why does the HAL matter if drivers already abstract hardware?
    Drivers abstract *devices*; the HAL abstracts the *platform* beneath the kernel — interrupt controllers, timers, DMA, bus and firmware access, SMP startup. Without it the scheduler and interrupt dispatch code would need per-board variants. It is what lets one `ntoskrnl.exe` image plus signed drivers boot on wildly different machines.

saying these in an interview costs you the question

  • Calls the HAL a device driver or the driver model
  • Thinks kernel32.dll executes in kernel mode
  • Believes drivers run in a protected ring between user and kernel
  • Describes NT as a pure microkernel with user-mode servers
  • Assumes all graphics work happens in user mode

context