Windows Object Model
The Windows Architecture Deep Dive · Windows Programming track
8 min read
In this module
Everything Is an Object
A bedrock principle of Windows NT: nearly every system resource is a kernel object. Processes, threads, files, registry keys, mutexes, events, semaphores, timers, I/O completion ports, access tokens — the Object Manager (a core executive component) treats them all the same way. One framework handles security, naming, reference counting, and handle management for the lot.
Object Structure
Every kernel object in Windows has the same basic structure:
The Object Header has the same layout regardless of what it's wrapping; the Object Manager owns it. The Object Body is where things diverge. A process object holds an EPROCESS, a file object holds a FILE_OBJECT, and so on down the type list.
Object Types
Each object is an instance of an object type. The object type defines:
- The size of the object body
- Methods (open, close, delete, parse, security, query name)
- Pool type (paged or nonpaged memory)
- Default security
| Object Type | Purpose |
|---|---|
| Process | Running process (EPROCESS) |
| Thread | Thread of execution |
| File | Open file/device/pipe |
| Section | Memory-mapped file |
| Key | Registry key |
| Event | Synchronisation event |
| Mutant (Mutex) | Mutual exclusion lock |
| Semaphore | Counting semaphore |
| Timer | Waitable timer |
| Token | Security access token |
| Directory | Object namespace dir |
| SymbolicLink | Namespace redirection |
| IoCompletionPort | Async I/O completion |
| Job | Process group limits |
| Desktop | Interactive desktop |
| WindowStation | Logon session container |
An object type is roughly a class in OO terms — it defines structure and behaviour for a category. Every concrete process, file, or mutex is an instance of its type. The Object Manager leans on that type info to allocate the right amount of memory, dispatch the right methods, and apply the right security checks.
Handle Tables
User-mode code never sees a raw kernel pointer. Processes deal in handles — opaque values that index into the process's handle table:
Process Handle Table:
| Handle | Object Pointer | Access Mask |
|---|---|---|
| 0x04 | EPROCESS obj | PROCESS_ALL |
| 0x08 | FILE_OBJECT | GENERIC_READ |
| 0x0C | Event obj | EVENT_MODIFY |
| 0x10 | Mutex obj | MUTANT_ALL |
| 0x14 | Key obj | KEY_READ |
| 0x18 | (free entry) | |
| 0x1C | Section obj | SECTION_MAP_READ |
Handle values are multiples of 4 (the lowest two bits are used internally). Each handle table entry stores:
- Object pointer: The kernel-mode address of the object
- Access mask: The specific access rights granted when this handle was created
- Audit-on-close flag: Whether closing this handle generates a security audit event
- Inheritance flag: Whether child processes inherit this handle
Handle Operations
// Opening a handle to an existing objectHANDLE hProcess = OpenProcess( PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, // Desired access FALSE, // Don't inherit targetPid // Process ID);// The kernel checks:// 1. Does the target process exist?// 2. Does our token have sufficient rights per the process's DACL?// 3. Create handle table entry with ONLY the requested access rights
// Using the handle (access is checked against the stored mask)ReadProcessMemory(hProcess, addr, buf, size, &bytesRead);
// Closing the handle (decrements object reference count)CloseHandle(hProcess);// If reference count reaches 0 and handle count is 0, object is destroyedHandle Inheritance
When a process creates a child process, it can choose to inherit handles:
SECURITY_ATTRIBUTES sa = { .nLength = sizeof(sa), .bInheritHandle = TRUE // Mark handle as inheritable};
// Create a pipe with inheritable handlesHANDLE hRead, hWrite;CreatePipe(&hRead, &hWrite, &sa, 0);
// Child process inherits the handleCreateProcess(NULL, "child.exe", NULL, NULL, TRUE, // bInheritHandles = TRUE 0, NULL, NULL, &si, &pi);With bInheritHandles set TRUE, every inheritable entry in the parent's handle table gets copied into the child's table at the same handle values. That's the mechanism behind passing pipe endpoints, file handles, and similar resources down to a child.
Handle Duplication
Handles can also be explicitly duplicated into another process:
// Duplicate a handle into another processDuplicateHandle( GetCurrentProcess(), // Source process hMyFile, // Source handle hTargetProcess, // Destination process &hDuplicated, // Output: new handle in target 0, // Desired access (0 = same as source) FALSE, // Inherit DUPLICATE_SAME_ACCESS // Flags);When a handle is created (via CreateFile, OpenProcess, etc.), the Object Manager checks the requestor's token against the object's security descriptor and grants only the requested permissions. These granted permissions are stored in the handle table entry. Every subsequent operation using that handle is checked against the stored access mask - NOT against the object's security descriptor again. This means reducing permissions after a handle is opened has no effect on existing handles.
The Object Namespace
The Object Manager keeps a hierarchical namespace for naming objects. It's not the file system — this namespace lives entirely in kernel memory and gets rebuilt at every boot.
\ (root)├── BaseNamedObjects\ (named objects: mutexes, events, sections)│ ├── MyAppMutex│ ├── SharedMemRegion│ └── Global\ (cross-session objects)├── Device\ (device objects)│ ├── HarddiskVolume1│ ├── HarddiskVolume2│ ├── Tcp│ ├── Udp│ └── Null├── Driver\ (driver objects)│ ├── Ntfs│ ├── Tcpip│ └── Disk├── GLOBAL??\ (symbolic links for drive letters)│ ├── C: → \Device\HarddiskVolume2│ ├── D: → \Device\CdRom0│ └── NUL → \Device\Null├── KnownDlls\ (cached DLL section objects)│ ├── kernel32.dll│ └── ntdll.dll├── Registry\ (registry root)│ ├── MACHINE│ └── USER├── Sessions\ (per-session namespaces)│ ├── 0\BaseNamedObjects\ (Session 0 - services)│ └── 1\BaseNamedObjects\ (Session 1 - user)└── ObjectTypes\ (type object definitions) ├── Process ├── Thread └── FileYou can explore this namespace using the Sysinternals WinObj tool or with kernel debugging tools.
Symbolic Links
Symbolic links in the object namespace redirect name lookups:
\GLOBAL??\C: → \Device\HarddiskVolume2
When an application opens "C:\file.txt":1. Win32 API prepends \??\ → \??\C:\file.txt2. \?? resolves to \GLOBAL?? (or session-specific \DosDevices)3. C: is a symbolic link to \Device\HarddiskVolume24. Final path: \Device\HarddiskVolume2\file.txt5. I/O Manager sends IRP to the file system mounted on HarddiskVolume2Security Descriptors
Every named object can have a security descriptor attached to it:
The descriptor gets checked the moment a process tries to open a handle. The Security Reference Monitor takes the process's access token (with its SIDs and privileges), walks the DACL, and decides the maximum access it'll grant.
Reference Counting
Every kernel object has two counters:
- Handle count: Number of open handles across all processes
- Reference count: Number of kernel-mode references (always >= handle count)
An object gets torn down only when both counters hit zero. The split prevents the kernel from yanking memory out from under itself while a driver still has a pointer:
If you're writing Windows code, the object model isn't optional knowledge. Every resource you touch — files, processes, synchronisation primitives, registry keys — is a kernel object running through this same framework. Handle bugs (leaks, use-after-close, sloppy access checks) account for a depressing share of both ordinary defects and serious security holes.