Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Kernel de Windows - I
Sistemas Operativos
Versin: Abril 2013 Palabras Claves: Windows, Kernel, Executive, Process, System, Threads
Copyright Notice
2000-2005 David A. Solomon and Mark Russinovich
These materials are part of the Windows Operating System Internals Curriculum Development Kit, developed by David A. Solomon and Mark E. Russinovich with Andreas Polze Microsoft has licensed these materials from David Solomon Expert Seminars, Inc. for distribution to academic organizations solely for use in academic environments (and not for commercial use)
Simplified OS Architecture
System support processes User Mode Kernel Mode Kernel Service processes User Environment applications subsystems
Subsystem DLLs
OS Architecture
Multiple personality OS design
user applications don't call the native Windows operating system services directly
Subsystem DLLs is to translate a documented function into the appropriate internal (and undocumented) Windows system service calls. Environment subsystem processes
Manage client processes in their world Impose semantics such as process model, security
Kernel
low-level operating system functions, thread scheduling, interrupt and exception dispatching, multiprocessor synchronization. provides a set of routines and basic objects that the rest of the executive uses to implement higher-level constructs.
Service processes
Host Windows services i.e.; Task Scheduler and Spooler services Many Windows server applications, such as Microsoft SQL Server and Microsoft Exchange Server, also include components that run as services.
Portability
When Windows NT was designed, there was no dominant processor architecture
Therefore it was designed to be portable
How achieved?
Most Windows OS code and device drivers is written in C
HAL and kernel contain some assembly language
Hardware-specific code is isolated in low level layers of the OS (such as Kernel and the HAL)
Provides portable interface
NT 4.0 had support for x86, MIPS, PowerPC, Digital Alpha AXP
PowerPC and MIPS dropped soon after NT 4 release Alpha AXP dropped in 1999 (supported through SP6)
Windowing subsystem:
CSRSS.EXE* WIN32K.SYS KERNEL32/USER32/GDI32.DLL Windows subsystem process USER and GDI kernel-mode components Windows subsystem DLLs
Windows
POSIX Windows
Executive
Kernel
Multiple OS Personalities
Windows was designed to support multiple personalities, called environment subsystems
Programming interface File system syntax Process semantics
Environment subsystems provide exposed, documented interface between application and Windows native API
Each subsystem defines a different set of APIs and semantics Subsystems implement these by invoking native APIs
Example: Windows CreateFile in Kernel32.Dll calls native NtCreateFile
Function requires some work in environment subsystem process (maintain state of client app)
Client/server request (message) to env. Subsystem (LPC facility) Subsystem DLL waits for reply before returning to caller
Windows Architecture
System Processes Service Control Mgr. LSASS WinLogon User Mode SvcHost.Exe WinMgt.Exe SpoolSv.Exe Services.Exe Subsystem DLLs Windows Task Manager Explorer User Application POSIX Windows DLLs OS/2 Services Applications Environment Subsystems
Session Manager
NTDLL.DLL
System Service Dispatcher (kernel mode callable interfaces) I/O Mgr Configuration Mgr (registry) Processes & Threads Local Procedure Call Security Reference Monitor Plug and Play Mgr. Virtual Memory File System Cache Object Mgr. Power Mgr. Windows USER, GDI
Graphics Drivers
Kernel Hardware Abstraction Layer (HAL) hardware interfaces (buses, I/O devices, interrupts, interval timers, DMA, memory cache control, etc., etc.)
Original copyright by Microsoft Corporation. Used by permission.
Microkernel OS?
Is Windows a microkernel-based OS?
No not using the academic definition (OS components and drivers run in their own private address spaces, layered on a primitive microkernel) All kernel components live in a common shared address space
Therefore no protection between OS and drivers
Executive
Upper layer of the operating system Provides generic operating system functions (services)
Process Manager Object Manager Cache Manager LPC (local procedure call) Facility Configuration Manager Memory Manager Security Reference Monitor I/O Manager Power Manager Plug-and-Play Manager
Almost completely portable C code Runs in kernel (privileged, ring 0) mode Most interfaces to executive services not documented
Kernel
Lower layers of the operating system
Implements processor-dependent functions (x86 vs. Itanium etc.) Also implements many processor-independent functions that are closely associated with processor-dependent functions
Main services
Thread waiting, scheduling & context switching Exception and interrupt dispatching Operating system synchronization primitives (different for MP vs. UP) A few of these are exposed to user mode
HAL also implements some functions that appear to be in the Executive and Kernel Selected at installation time
See \windows\repair\setup.log to find out which one Can select manually at boot time with /HAL= in boot.ini
HAL kit
Special kit only for vendors that must write custom HALs (requires approval from Microsoft) see http://www.microsoft.com/whdc/ddk/HALkit/default.mspx
Defined in registry
Same area as Windows services (t.b.d.) - differentiated by Type value
Several types:
ordinary, file system, NDIS miniport, SCSI miniport (linked against port drivers), bus drivers More information in I/O subsystem section
System Threads
Functions in OS and some drivers that need to run as real threads
E.g., need to run concurrently with other system activity, wait on timers, perform background housekeeping work Always run in kernel mode Not non-preemptible (unless they raise IRQL to 2 or above) For details, see DDK documentation on PsCreateSystemThread
10
Network
Redirector and Server Worker Threads
11
Process-Based Code
OS components that run in separate executables (.exes), in their own processes
Started by system Not tied to a user logon
Three types:
Environment Subsystems (already described) System startup processes
note, system startup processes is not an official MS-defined name
Windows Services
(System)
12
csrss.exe winlogon.exe
services.exe
lsass.exe userinit.exe
explorer.exe
13
APIs that take an already-opened handle look in the handle table entry before performing the function
For example: TerminateProcess checks to see if the handle was opened for Terminate access No need to check file ACL, process or thread access token, etc., on every write request---checking is done at file handle creation, i.e. file open, time
Handle to a kernel object is an index into the process handle table, and hence is invalid in any other process
Process B Handle Table
Handle table entry contains the system-space address (8xxxxxxx or above) of the data structure; this address is the same regardless of process context Although handle table is perprocess, it is actually in system address space (hence protected)
14
Object Manager
Executive component for managing system-defined objects
Objects are data structures with optional names Objects managed here include Windows Kernel objects, but not Windows User or GDI objects Object manager implements user-mode handles and the process handle table
Object Manager
In part, a heap manager
Allocates memory for data structure from system-wide, kernel space heaps (pageable or nonpageable)
Maintains counts of handles and references (stored pointers in kernel space) to each object
Object cannot be freed back to the heap until all handles and references are gone
15
Executive Objects
Object type Represents
Object directory Container object for other objects: implement hierarchical namespace to store other object types Symbolic link Process Thread Section File Port Access token Mechanism for referring to an object name indirectly Virtual address space and control information necessary for execution of thread objects Executable entity within a process Region of shared memory (file mapping object in Windows API) Instance of an opened file or I/O device Mechanism to pass messages between processes Security profile (security ID, user rights) of a process or thread
Represents
Object with persistent state (signaled or not) usable for synchronization or notification Counter and resource gate for critical section Synchronization construct to serialize resource access Mechanism to notify a thread when a fixed period of time elapses Method for threads to enqueue/dequeue notifications of I/O completions (Windows I/O completion port) Reference to registry data visible in object manager namespace Mechanism for measuring execution time for a process within an address range
Key Profile
16
Object Structure
Object header
Object body
Object name Object name Object directory Object name Object directory Security descriptor Object directory Security descriptor Quota charges Security descriptor Quota charges Open handle count Quota charges Open handle count Open handles list Open handle count Open handles list Object type Open handles list Object type Reference Objectcount type Reference count Reference data count Object-specific Object-specific data Object-specific data
Process 1 Process 2 Process 3 Type object Type name Access types Synchronizable? (Y/N) Pageable? (Y/N) Methods: open, close, delete parse, security, query name
Type object contains static, object-type specific data: - shared among all instances of an object type - link all instances together (enumeration)
Object Methods
Method Open Close Delete Query name Parse Security Example: When method is called When an object handle is opened When an object handle is closed Before the object manager deletes an object When a thread requests the name of an object, such as a file, that exists in a secondary object domain When the object manager is searching for an object name that exists in a secondary object domain When a process reads/changes protection of an objects, such as a file, that exists in a secondary object domain
Process opens handle to object \Device\Floppy0\docs\resume.doc Object manager traverses name tree until it reaches Floppy0 Calls parse method for object Floppy0 with arg \docs\resume.doc
17
in \BaseNamedObjects
these will appear when Windows programs use CreateEvent, etc. mutant (Windows mutex) queue (Windows I/O completion port) section (Windows file mapping object) event Semaphore
In \GLOBAL??
DOS device name mappings for console session
18
Supports case sensitive or case blind Supports symbolic links (used to implement drive letters, etc.)
Otras Referencias
Windows Academic Program: http://www.microsoft.com/education/faculty connection/articles/articledetails.aspx?cid= 2416 (27/05/2010)
19