![]() |
![]() |
|||||||
Usenet ArchivesDeviceIoControl Buffers
From paulsan@microsoftSPAM.com Mon Jan 11 12:03:46 1999
Path: relief.cts.com!newshub.cts.com!mercury.cts.com!socal.verio.net! Here is an explanation of buffers and DeviceIoControl. First, here are the parameters,
BOOL DeviceIoControl(
HANDLE hDevice, // handle to device of interest
DWORD dwIoControlCode, // control code of operation
// to perform
LPVOID lpInBuffer, // pointer to buffer to supply
// input data
DWORD nInBufferSize, // size of input buffer
LPVOID lpOutBuffer, // pointer to buffer to receive
// output data
DWORD nOutBufferSize, // size of output buffer
LPDWORD lpBytesReturned, // pointer to variable to receive
// output byte count
LPOVERLAPPED lpOverlapped // pointer to overlapped structure
// for asynchronous operation
);
METHOD_BUFFEREDuser-mode perspective
lpInBuffer - optional, contains data that is written to the driver
I/O Manager perspective
examines nInBufferSize and nOutBufferSize. Allocates memory from non-paged
pool and puts the address of this pool in Irp->AssociatedIrp.SystemBuffer.
The size of this buffer is equal to the size of the larger of the two
bufferes. This buffer is accessible at any IRQL. Device Driver perspective
you have one buffer, Irp->AssociatedIrp.SystemBuffer. You read input data
from this buffer and you write output data to the same buffer, overwriting
the input data. I/O Manager Completion Routine perspective
looks at IoStatus block, if IoStatus.Status = STATUS_SUCCESS, then METHOD_IN_DIRECTuser-mode perspective
lpInBuffer - optional, contains data that is written to the driver. This
buffer is used in the exact same fashion as METHOD_BUFFERED. To avoid
confusion, mentally rename this buffer to lpControlBuffer. This is
typically a small, optional buffer that might contain a control structure
with useful information for the device driver. This buffer is small and is
double buffered.
I/O Manager perspective
If lpInBuffer exists, allocates memory from non-paged pool and puts the
address of this pool in Irp->AssociatedIrp.SystemBuffer. This buffer is
accessible at any IRQL. Device Driver perspective
The device driver can read the copy of lpOutBuffer [should be lpInBuffer--jeh] via
Irp->AssociatedIrp.SystemBuffer. Anything written by the device driver to
this buffer is lost. The I/O Manager does not copy any data back to the
user-mode buffers as it did in the completion routine for METHOD_BUFFERED. Device Driver Completion Routine perspective
standard completion routine operations [I disagree with the "IoStatus.Information is not needed" comment. This longword is passed back to the caller as the returned lpBytesReturned value, and the application may want to see this. This represents the number of bytes of the lpOutBuffer actually written to the device. -- jeh] I/O Manager Completion Routine perspective
standard I/O Manager completion routine operations METHOD_OUT_DIRECTuser-mode perspective
lpInBuffer - optional, contains data that is written to the driver. This
buffer is used in the exact same fashion as METHOD_BUFFERED. To avoid
confusion, mentally rename this buffer to lpControlBuffer. This is
typically a small, optional buffer that might contain a control structure
with useful information for the device driver. This buffer is smal and is
double buffered. I/O Manager perspective
If lpInBuffer exists, allocates memory from non-paged pool and puts the
address of this pool in Irp->AssociatedIrp.SystemBuffer. This buffer is
accessible at any IRQL. Device Driver perspective
The device driver can read the copy of lpOutBuffer [should be lpInBuffer--jeh] via
Irp->AssociatedIrp.SystemBuffer. Anything written by the device driver to
this buffer is lost. Device Driver Completion Routine perspective
standard completion routine operations [I disagree with the "IoStatus.Information is not needed" comment. This longword is passed back to the caller as the returned lpBytesReturned value, and the application may want to see this. This represents the number of bytes of the lpOutBuffer actually read from the device. -- jeh] I/O Manager Completion Routine perspective
standard I/O Manager completion routine operations METHOD_NEITHERI/O Manager perspective
Irp->UserBuffer = lpOutputBuffer; Final CommentDon't touch Irp->UserBuffer. This is a bookmark for the I/O Manager. Two major problems can occur. 1 - page fault at high IRQL, or 2 - you write something to Irp->UserBuffer and the I/O Manager overwrites you in its completion routine. File systems access Irp->UserBuffer, but FSD writers know all of the above and know when it is safe to touch Irp->UserBuffer. top of page | up | previous | next | home |
||||||||