1.2 Structure and operation of the kernel mode device driver under Windows NT
In general, the task of the device driver has two: first, accept reading and writing request from the user program,
The user's data is transmitted to the device, or transmit data received from the device to the user; second, polling device or processing
Interrupt request from the device to complete the data transfer.
1.2.1 Communication with the user program
I / O Manager puts every device to the upper layer into a file, so as long as the Win32 user program is passed
A few simple files Operate the API function to implement a device communication with the driver (please note, one
The driver can drive multiple devices):
Function name function
CreateFile opens a device to prepare data transfer. Returns a handle related to the device.
CloseHandle Close a device that is opened by CreateFile.
Readfile reads data from the device.
Writefile writes data to the device.
DeviceIoControl performs some custom operations for the device, such as changing settings, etc.
Table I
1.2.2 Driverentry Process
This is the entry of each device driver, and each time the program is started automatically. Most equipment
The initialization work is done in this process. Including the entry to set the process of responding to various user requests, so that I / O pipe
The instrument can know that the processes should be called when the user's opening, closing, reading and writing is requested. Drive
Only the name "Driverentry" of this process is fixed, all the procedures listed below are mainly
Register.
If the driver does not respond to any request, as long as a driverentry process can form a energy transport
Row driver.
1.2.3 unload and shutdown processes
The UNLOAD process is responsible for doing some necessary processing before the driver is stopped. For example, release resources, record the final status
Samples. The shutdown process is called when the system is about to turn off, and the difference from the former is no need to release any resources.
1.2.4 Dispatchopen and DispatchClose Processes
These two processes are called when the user calls CreateFile and CloseHandle, and is made for the upcoming read and write operation.
Prepare, or do the necessary handles after reading and writing.
1.2.5 DispatchRead, DispatchWrite and StartIO Process
The first two processes are called when the user calls ReadFile and Writefile. They first do some test users request
The legality of the legality is then launched a process called STARTIO to start actual data transmission between the hardware. I
The / O Manager also provides a pointer to the user buffer by IRP for exchange data with the user program.
. For details, please see 1.3.2 for details.
1.2.6 Accepting custom other requests
These two processes are called when the user calls DeviceIocontrol. It gets the user's request number through IRP,
And a pointer to the user buffer can communicate with the user program.
1.2.7 Interrupt Process (ISR)
These processes are called when interrupt occurs.
1.2.8 Postponeted Process (Deferred Procedure)
These processes are used to complete a higher operating level process (such as interrupt processing) at a lower run level.
Some tasks. For details, please see 1.3.3 for details.
-