Windows Kernel Internals Ii: Processes, Threads, Virtualmemory
Windows Kernel Internals Ii: Processes, Threads, Virtualmemory
Processes, Threads,
VirtualMemory
University of Tokyo – July 2004*
Security refmon IO Manager Virtual memory Procs & threads Win32 GUI
File filters
FS run-time Scheduler
File systems
Volume mgrs exec synchr
Cache mgr
Device stacks
Object Manager / Configuration Management
Kernel run-time / Hardware Adaptation Layer
© Microsoft Corporation 2004 2
Process
Container for an address space and threads
Associated User-mode Process Environment Block (PEB)
Primary Access Token
Quota, Debug port, Handle Table etc
Unique process ID
Queued to the Job, global process list and Session list
MM structures like the WorkingSet, VAD tree, AWE etc
Thread
Files Virtual
Process’ Thread
Address
Events Handle Table
Descriptors Thread
Devices
Thread
Drivers
Thread
Transition PspCreateThread
Thread
k stack KiReadyThread
swapped KiInsertDeferredReadyList
KiInsertDeferredReadyList
KiReadyThread
scheduling
Deferred
Ready
Ready
process
states
swapped KiRetireDpcList/KiSwapThread/ KiSetAffinityThread
KiExitDispatcher KiSetpriorityThread
KiProcessDeferredReadyList
KiDeferredReadyThread
no avail.
Ready
processor
KiSelectNextThread
KiUnwaitThread
KiReadyThread
Idle
processor
or Standby preemption
Waiting preemption
Affinity
ok
KiQuantumEnd
KiIdleSchedule
KiSwapThread
KiExitDispatcher
NtYieldExecution
Affinity
not ok
Pagefault
NtLockVirtualMemory, NtUnlockVirtualMemory
– locks a region of pages within the working set list
– requires PROCESS_VM_OPERATION on target
process and SeLockMemoryPrivilege
NtReadVirtualMemory, NtWriteVirtualMemory (
Proc, Addr, Buffer, Size)
NtFlushVirtualMemory
© Microsoft Corporation 2004 21
Virtual Memory Manager
NT Internal APIs
NtCreateSection
– creates a section but does not map it
NtOpenSection
– opens an existing section
NtQuerySection
– query attributes for section
NtExtendSection
NtMapViewOfSection (Sect, Proc, Addr, Size, …)
NtUnmapViewOfSection
NtResetWriteWatch
NtGetWriteWatch
Read out dirty bits for a section of memory since last
reset © Microsoft Corporation 2004 23
Allocating kernel memory (pool)
• Tightest x86 system resource is KVA
Kernel Virtual Address space
• Pool allocates in small chunks:
< 4KB: 8B granulariy
>= 4KB: page granularity
• Paged and Non-paged pool
Paged pool backed by pagefile
• Special pool used to find corruptors
• Lots of support for debugging/diagnosis
Pageframe R R R G R D A Cd Wt O W 1
31 12 11 10 9 8 7 6 5 4 3 2 1 0
CR3
PD PT page DATA
CR3
GetPteAddress:
0xe4321000
PD PT => 0xc0390c84
0x300 0x321
0x390 PTE
Transition
Transition Prototype
Process/System Soft
Soft
Working Set Fault
Fault
Trim Trim
Clean Dirty
Delete
Page
Modified
Standby Modified
Page-
List List
writer
MM Low
Memory Physical Page State
Changes
Hardfault Zerofault
(DISK) (FILL)