Windows Internals - · PDF file3 About the Speaker: Mark Russinovich Co-author of Inside...
Transcript of Windows Internals - · PDF file3 About the Speaker: Mark Russinovich Co-author of Inside...
Windows Internals
David Solomon ([email protected])David Solomon Expert Seminarswww.solsem.com
Mark Russinovich ([email protected])Winternalswww.winternals.com, www.sysinternals.com
2
About the Speaker: David Solomon1982-1992: VMS operating systems development at Digital1992-present: Researching, writing, and teaching Windows operating system internalsFrequent speaker at technical conferences(Microsoft TechEd, IT Forum, PDCs, )Microsoft Most Valuable Professional (1993, 2005)Books
Windows Internals, 4th editionPDF version ships with Server 2003 Resource Kit
Inside Windows 2000, 3rd editionInside Windows NT, 2nd editionWindows NT for OpenVMS Professionals
Live Classes2-5 day classes on Windows Internals,Advanced Troubleshooting
Video Training12 hour interactive internals tutorialLicensed by MS for internal use
http://solsem.com/videos.html
3
About the Speaker: Mark Russinovich
Co-author of Inside Windows 2000, 3rd Edition and Windows Internals, 4th edition with David SolomonSenior Contributing Editor to Windows IT Pro Magazine
Co-authors Windows Power Tools column
Author of tools on www.sysinternals.com Microsoft Most Valuable Professional (MVP)Co-founder and chief software architect of Winternals Software (www.winternals.com)Ph.D. in Computer Engineering
http://www.sysinternals.com/http://www.winternals.com/
4
Purpose of TutorialGive Windows developers a foundation understanding of the systems kernel architecture
Design better for performance & scalabilityDebug problems more effectivelyUnderstand system performance issues
Were covering a small, but important set of core topics:
The plumbing in the boiler room
5hardware interfaces (buses, I/O devices, interrupts,
interval timers, DMA, memory cache control, etc., etc.)
System Service Dispatcher
Task ManagerExplorer
SvcHost.ExeWinMgt.Exe
SpoolSv.Exe
Service Control Mgr.LSASS
ObjectMgr.
WindowsUSER,
GDIFile
System Cache
I/O Mgr
Environment Subsystems
UserApplication
Subsystem DLLs
OS/2
System Processes Services Applications
SystemThreads
UserMode
KernelMode
Windows
NTDLL.DLL
Device &File Sys.Drivers
WinLogon
Session Manager
Services.Exe
POSIX
Plug andPlay Mgr.
PowerMgr.
Security Reference
MonitorVirtual
MemoryProcesses
&Threads
LocalProcedure
CallGraphicsDrivers
KernelHardware Abstraction Layer (HAL)
(kernel mode callable interfaces)
System Architecture
Configura-tion Mgr(registry)
6
Tools Used To Dig InMany tools available to dig into Windows OS internals without requiring source code
Helps to see internals behavior in actionMany of these tools are used in labs in the video and the book
Several sources of toolsSupport Tools (on Windows OS CD-ROM in \support\tools)Resource Kit ToolsSysinternals tools (www.sysinternals.com) Windows Debugging Tools
http://www.sysinternals.com/
7
Live Kernel Debugging
Useful for investigating internal system state not available from other tools
Previously, required 2 computers (host and target)Target would be halted while host debugger in use
XP & later supports live local kernel debugging
Technically requires system to be booted /DEBUG to work correctlyBut, not all commands work
8
LiveKDLiveKd makes more commands work on a live system
Works on NT4, Windows 2000, Windows XP, Server 2003, and VistaWas originally shipped on Inside Windows 2000 book CD-ROM now is free on SysinternalsTricks standard Microsoft kernel debuggers into thinking they are looking at a crash dumpDoes not guarantee consistent view of system memory
Thus can loop or fail with access violationJust quit and restart
9
Outline
1. System Architecture2. Processes and Thread Internals3. Memory Management Internals4. Security Internals
10
System Architecture
Process Execution EnvironmentKernel ArchitectureInterrupt HandlingObject ManagerSystem ThreadsProcess-based codeSummary
11
Processes And Threads
What is a process?Represents an instance of a running program
You create a process to run a programStarting an application creates a process
Process defined byAddress spaceResources (e.g., open handles)Security profile (token)
System callPrimary argument to CreateProcess is image file name (or command line)
Per-processaddress space
System-wide address space
Thread
Thread
Thread
12
Processes And Threads
What is a thread?An execution context within a processUnit of scheduling (threads run, processes dont run)All threads in a process share the same per-process address space
Services provided so that threads can synchronize access to shared resources (critical sections, mutexes, events, semaphores)
All threads in the system are scheduled as peers to all others, without regard to their parent process
System call:Primary argument to CreateThread is a function entry point address
Linux:No threads per-seTasks can act like Windows threads by sharing handle table, PID and address space
Per-processaddress space
System-wide address space
Thread
Thread
Thread
13
Processes And ThreadsEvery process starts with one thread
First thread executes the programs main functionCan create other threads in the same processCan create additional processes
Why divide an application into multiple threads?Perceived user responsiveness, parallel/background execution
Examples: Word background print can continue to edit during printTake advantage of multiple processors
On an MP system with n CPUs, n threads can literally run at the same timeQuestion: Given a single threaded application, will adding a second processor make it run faster?
Does add complexitySynchronizationScalability well is a different question
Number of multiple runnable threads versus number CPUsHaving too many runnable threads causes excess context switching
14
2 GBUser
process space
2 GBSystemSpace
32-bit x86 Address Space
3 GBUser
process space
1 GBSystem Space
Default 3 GB user space
32-bits = 4 GB
15
8192 GB(8 TB)User
process space
6657 GBSystemSpace
64-bit Address Spaces
7152 GB(7 TB)User
process space
6144 GBSystemSpace
x64 Itanium
64-bits = 17,179,869,184 GBx64 today supports 48 bits virtual = 262,144 GBIA-64 today support 50 bits virtual = 1,048,576 GB
16
Memory Protection Model
No user process can touch another user process address space (without first opening a handle to the process, which means passing through NT security)
Separate process page tables prevent thisCurrent page table changed on context switch from a thread in 1 process to a thread in another process
No user process can touch kernel memoryPage protection in process page tables prevent thisOS pages only accessible from kernel mode
x86: Ring 0, Itanium: Privilege Level 0Threads change from user to kernel mode and back (via a secure interface) to execute kernel code
Does not affect scheduling (not a context switch)
17
Process Explorer (Sysinternals)Super Task Manager
Shows full image path, command line, environment variables, parent process, thread details, security access token, open handles, loaded DLLs & mapped files
18
System Architecture
Process Execution EnvironmentKernel ArchitectureInterrupt HandlingObject ManagerSystem ThreadsProcess-based codeSummary
19
Windows Kernel EvolutionBasic kernel architecture has remained stable while system has evolved
Windows 2000: major changes in I/O subsystem (plug & play, power management, WDM), but rest similar to NT4Windows XP & Server 2003: modest upgrades as compared to the changes from NT4 to Windows 2000
Internal version numbers confirm this:Windows 2000 was 5.0Windows XP is 5.1Windows Server 2003 is 5.2Windows Vista is 6.0
20
call NtWriteFilereturn to caller
do the operationreturn to caller
Int 2E or SYSENTER or SYSCALLreturn to caller
call NtWriteFiledismiss interrupt
Windows application
WriteFile in Kernel32.Dll
NtWriteFilein NtDll.Dll
KiSystemServicein NtosKrnl.Exe
NtWriteFilein NtosKrnl.Exe
Example Invoking a Win32 Kernel API
Win32-specific
used by all subsystems
software interrupt
U
K
call WriteFile()
21
NTOSKRNL.EXECore operating system image
Contains Executive and KernelFour retail variations:
NTOSKRNL.EXE UniprocessorNTKRNLMP.EXE Multiprocessor
32-bit Windows PAE versions (for DEP & >4GB RAM):
NTKRNLPA.EXE Uniprocessor w/extended addressing support
NTKRPAMP.EXE Multiprocessor w/extended addressing support
Vista: no uniprocessor kernel
22hardware interfaces (buses, I/O devices, interrupts,
interval timers, DMA, memory cache control, etc., etc.)
System Service Dispatcher
Task ManagerExplorer
SvcHost.ExeWinMgt.Exe
SpoolSv.Exe
Service Control Mgr.LSASS
ObjectMgr.
WindowsUSER,
GDIFile
System Cache
I/O Mgr
Environment Subsystems
UserApplication
Subsystem DLLs
OS/2
System Processes Services Applications
Original copyright by Microsoft Corpor