Structure Flashcards
Driver
Is as a container for a collection of subroutines that the operating system calls to perform various operations that relate to your hardware
Routines present in every such container
DriverEntry and AddDevice routines, as well as dispatch functions for a few types of I/O Request Packet (IRP)
Drivers that need to queue requests
Might have a StartIo routine
Drivers for devices that generate hardware interrupts
Have an interrupt service routine (ISR) and a deferred procedure call (DPC) routine
Jobs as the author of a WDM driver
Select the functions that need to be included in your particular container
OS Scheduler
The operating system kernel contains a scheduler that gives short blocks of time, called time slices, to all the
threads that are currently eligible to run. An application begins life with a single thread and can create more if it wants. Each thread has a priority, given to it by the system and subject to adjustment up and down for various reasons. At each decision point, the scheduler picks the highest-priority eligible thread and gives it control by loading a set of saved register images,
including an instruction pointer, into the processor registers. A processor interrupt accompanies expiration of the thread’s time slice. As part of handling the interrupt, the system saves the current register images, which can be restored the next time the system decides to redispatch the same thread.
Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than spinning in a polling loop waiting for completion because it allows other
threads to run sooner than they would if the system had to rely solely on expiration of a time slice to turn its attention to some other thread.
Application is
A selfish thread that grabs the CPU and tries to hold on until it exits and that the operating system scheduler acts like a playground monitor to make a bunch of selfish threads play well together
A a driver is also an executable file with extension
.SYS
Who charge the driver
A driver doesn’t contain a main program. Instead, it contains a collection of subroutines that the
system can call when the system thinks it’s time to. To be sure, these subroutines can use helper subroutines in the driver, in static libraries, and in the operating system, but the driver isn’t in charge of anything except its own hardware: the system is in charge of everything else, including the decisions about when to run your driver code.
Thead context
Running in an arbitrary thread context. A driver subroutine executes in the context of whatever thread happens to be currently active at the time the system decides to call that subroutine. It’s not possible to predict which thread will be current at the time a hardware interrupt occurs.
Arbitrary thread
All the eligible threads that happens to be executing at the time of hardware interrupt is likewise not predictable
The system doesn’t always execute driver code in an arbitrary thread context
A driver can create its own system threads by
calling PsCreateSystemThread. A driver can also ask the system to call it back in the context of a system thread by scheduling a work item. In these situations, we consider the thread context to be nonarbitrary.
Thread block in an arbitrary thread
driver shouldn’t block
When a driver shouldn’t block
- In an arbitrary thread
* When a driver creates an IRP to send to some other driver
IRP in an arbitrary thread
Asynchronous IRP. The I/O Manager doesn’t tie an asynchronous IRP to any particular thread
IRP in a nonarbitrary thread
Synchronous IRP. The I/O Manager ties the synchronous kind of IRP to the thread within which you
create the IRP. It will cancel the IRP automatically if that thread terminates.
Symmetric Multiprocessing
In this model, each CPU is treated exactly like every other CPU with respect to thread scheduling. Each CPU has its own current thread. It’s perfectly possible for the I/O Manager, executing in the context of the threads running on two or more CPUs, to call subroutines in your driver simultaneously.
Function driver
It understands all the details about how to make
the hardware work. It’s responsible for initiating I/O operations, for handling the interrupts that occur when those operations finish, and for providing a way for the end user to exercise any control over the device that might be appropriate.
Bus driver
It’s responsible for managing the connection between
the hardware and the computer
PDO
physical device object
FDO
function device object
FiDO
filter device object
Plug and Play device
Is one that has an electronic signature that a bus driver can interrogate to learn the identity of a device.