Re: Win2000 driver: DeviceIoControl, system threads and addressibility

Embedded pointers in IOCTLs are considered poor programming practice.
You should redefine your IOCTL so that the data buffer is contiguous
with the control structure, as in:

typedef struct {

ULONG Length;
UCHAR Buffer[1];
} REQUEST, *PREQUEST;
// remainder of buffer is allocated with the struct.

If in fact all you are sending to the driver is a buffer with a length,
then arguably you do not need any control structure at all, as the Irp
will contain the length already as either the input buffer length or the
output buffer length.

If you use METHOD_IN/OUT_DIRECT you can use the IOCTL input buffer for a
control structure and the IOCTL output buffer for your data buffer, with
data transfer in either direction (depending on the use of METHOD_IN_ or
METHOD_OUT_ .) So if you really want to use a pointer to the data buffer
that is an alternative way to go.

===========================
Mark Roddy
Consultant, Microsoft DDK MVP
Hollis Technology Solutions
xxxxx@hollistech.com
www.hollistech.com
603-321-1032

-----Original Message-----
From: “Vasili I Galchin”
To: “NT Developers Interest List”
Date: Thu, 29 Aug 2002 14:24:45 -0400
Subject: [ntdev] Win2000 driver: DeviceIoControl, system threads and
addressibility

> Hello,
>
> In my w2k driver I have a DeviceIoControl struct like:
>
> typedef struct {
>
> ULONG Length;
> PUCHAR Buffer;
>
> } REQUEST, *PREQUEST;
>
> I am using Buffered I/O.
>
> If I use the Startio approach, I have addressibility to the “Buffer”
> field. However, now I have eliminated the Startio and implemented the
> notion of an Irp queue with a system thread dequeuing the next Irp and
> initiating the hardware with a new request (the Ioctl Dispatch function
> is
> the producer for this Irp queue). When the system thread (Irp queue
> consumer) attemps to access “Buffer” I get a BSOD with a Bugcheck 0x1E
> and
> an exception code of 0xc0000005 (SATUS_ACCESS_VIOLATION). I understand
> that “Buffer” is no longer mapped for the thread. Question how can I
> insure that “Buffer” is mapped for the consuming thread?
>
> Thanks and regards, Vasili
>
> —
> You are currently subscribed to ntdev as: xxxxx@hollistech.com
> To unsubscribe send a blank email to %%email.unsub%%