Windows Kernel Internals II
Windows Kernel Internals II
Device
Object
Driver Object File Object
File Object
© Microsoft Corporation 2004 4
Layering Drivers
Device objects attach one on top of another using
IoAttachDevice* APIs creating device stacks
– IO manager sends IRP to top of the stack
– drivers store next lower device object in their private
data structure
– stack tear down done using IoDetachDevice and
IoDeleteDevice
Device objects point to driver objects
– driver represent driver state, including dispatch table
File objects point to open files
File systems are drivers which manage file objects for
volumes (described by VolumeParameterBlocks)
Handle
Security and IO Special APC
File
access validation
object
IoCompleteRequest
Allocate IRP
Devobj1
Devobj1
Dispatch routine DPC routine
Devobj2
Devobj2
Dispatch routine Interrupt service
routine
© Microsoft Corporation 2004 11
Async IO from Win32
Applications can issue asynchronous IO requests
– to files opened with FILE_FLAG_OVERLAPPED
– passing an LPOVERLAPPED parameter to the IO API
Methods available to wait for IO completion
– Wait on the file handle
– Wait on an event handle passed in the overlapped
structure
• e.g., GetOverlappedResult(…)
– Specify a routine to be called on IO completion.
– Use completion ports
PVOID *EntryPoint;
EntryPoint = irpSpParameters.DeviceIoControl.Type3InputBuffer;
*EntryPoint = (PVOID)SendData;
status = STATUS_SUCCESS;
break;
}
PVOID *EntryPoint;
EntryPoint = irpSpParameters.DeviceIoControl.Type3InputBuffer;
try {
if (IrpRequestorMode != KernelMode) {
D1
D2
HDD
D3
D1
CDROM Net Card
D2
D3
D1
D2
D3
Working D0 D0 D0 D0
C0
HDD DISK.SYS
S0 D0
ATAPI.SYS
S0 D0
© Microsoft Corporation 2004 43
System State S1 – D1
Modem
D2
D3
D1
D2
HDD
D3
D1
CDROM Net Card
D2
D3
D1
D2
D3
Standby D0 D0 D0 D0
C0
HDD DISK.SYS
S1 D1
ATAPI.SYS
S1 D?
© Microsoft Corporation 2004 44
System State S3 – D1
Modem
D2
D3
D1
D2
HDD
D3
D1
CDROM Net Card
D2
D3
D1
D2
D3
Standby D0 D0 D0 D0
C0
HDD DISK.SYS
S3 D3
ATAPI.SYS
S3 D?
© Microsoft Corporation 2004 45
System State S4 – D1
Modem
D2
D3
D1
D2
HDD
D3
D1
CDROM
D2
D3
D1
D2
Net Card
D3
Hibernate D0 D0 D0 D0
C0
HDD DISK.SYS
S4 D3
ATAPI.SYS
S4 D3
© Microsoft Corporation 2004 46
ACPI
Register interface for handling power management
interrupts
Interpreted p-code language (AML)
Human-readable specification for AML (ASL)
Collection of firmware objects organized in namespace
that describe the machine – built from AML
Namespace structure mirrors WDM device tree
Most devices in tree correspond to Devnodes
Devices in tree contain child-objects that modify the
properties of the device (special properties)
Various bus specifications leave out important parts,
which can be filled in with ACPI objects
© Microsoft Corporation 2004 47
ACPI Objects – Motherboard
ACPI objects can fill in machine-specific information
– If the serial port in a laptop is only exposed when
connected to a dock, an ACPI object can tell us that
– If two chips are connected to the same power plane, a
collection of ACPI objects can describe that
– If the CD-ROM drive can be ejected while the machine
is running ACPI objects can describe that
ACPI Objects can give thermal information
– Can be used to expose temperature sensors to the OS
– Can be used to describe thermal relationships
• Slowing the processor may also cool the CD-ROM
• Charging the battery may overheat the processor