Skip to main content
Be Bitwise

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 TypePurpose
ProcessRunning process (EPROCESS)
ThreadThread of execution
FileOpen file/device/pipe
SectionMemory-mapped file
KeyRegistry key
EventSynchronisation event
Mutant (Mutex)Mutual exclusion lock
SemaphoreCounting semaphore
TimerWaitable timer
TokenSecurity access token
DirectoryObject namespace dir
SymbolicLinkNamespace redirection
IoCompletionPortAsync I/O completion
JobProcess group limits
DesktopInteractive desktop
WindowStationLogon session container
Object Type vs Instance

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:

HandleObject PointerAccess Mask
0x04EPROCESS objPROCESS_ALL
0x08FILE_OBJECTGENERIC_READ
0x0CEvent objEVENT_MODIFY
0x10Mutex objMUTANT_ALL
0x14Key objKEY_READ
0x18(free entry)
0x1CSection objSECTION_MAP_READ

Handle values are multiples of 4 (the lowest two bits are used internally). Each handle table entry stores:

  1. Object pointer: The kernel-mode address of the object
  2. Access mask: The specific access rights granted when this handle was created
  3. Audit-on-close flag: Whether closing this handle generates a security audit event
  4. Inheritance flag: Whether child processes inherit this handle

Handle Operations

c
// Opening a handle to an existing object
HANDLE 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 destroyed

Handle Inheritance

When a process creates a child process, it can choose to inherit handles:

c
SECURITY_ATTRIBUTES sa = {
.nLength = sizeof(sa),
.bInheritHandle = TRUE // Mark handle as inheritable
};
// Create a pipe with inheritable handles
HANDLE hRead, hWrite;
CreatePipe(&hRead, &hWrite, &sa, 0);
// Child process inherits the handle
CreateProcess(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:

c
// Duplicate a handle into another process
DuplicateHandle(
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
);
Key Concept
Access Mask Enforcement

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.

text
\ (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
└── File

You can explore this namespace using the Sysinternals WinObj tool or with kernel debugging tools.

Symbolic links in the object namespace redirect name lookups:

text
\GLOBAL??\C: → \Device\HarddiskVolume2
When an application opens "C:\file.txt":
1. Win32 API prepends \??\ → \??\C:\file.txt
2. \?? resolves to \GLOBAL?? (or session-specific \DosDevices)
3. C: is a symbolic link to \Device\HarddiskVolume2
4. Final path: \Device\HarddiskVolume2\file.txt
5. I/O Manager sends IRP to the file system mounted on HarddiskVolume2

Security 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.