Code works in NT doesn't work in Win2K(SP4) and Win2003 by wenhua
wenhua
Mon Aug 04 14:17:07 CDT 2003
I checked the definitions of IRP and IO_STACK_LOCATION and
found the following:
//
// I/O Request Packet (IRP) definition
//
typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT)
_IRP {
...
//
// Note that the UserBuffer parameter is outside of
the stack so that I/O
// completion can copy data back into the user's
address space without
// having to know exactly which service was being
invoked. The length
// of the copy is stored in the second half of the I/O
status block. If
// the UserBuffer field is NULL, then no copy is
performed.
//
PVOID UserBuffer;
...
} IRP, *PIRP;
typedef struct _IO_STACK_LOCATION {
...
union {
...
//
// System service parameters for:
NtDeviceIoControlFile
//
// Note that the user's output buffer is stored in
the UserBuffer field
// and the user's input buffer is stored in the
SystemBuffer field.
//
struct {
ULONG OutputBufferLength;
ULONG POINTER_ALIGNMENT InputBufferLength;
ULONG POINTER_ALIGNMENT IoControlCode;
PVOID Type3InputBuffer;
} DeviceIoControl;
...
} Parameters;
...
} IO_STACK_LOCATION, *PIO_STACK_LOCATION;
The definitions are from .NET DDK 3718. This is very
confusing, they are different from what we've talked. from
the comment of UserBuffer, looks that we can always copy
data to UserBuffer.
From the comment of DeviceIoControl in the definition of
IO_STACK_LOCATION, SystemBuffer field is the input buffer,
UserBuffer field is output buffer. The comment doesn't say
anything about METHOD_BUFFERED or METHOD_NEITHER.
I also did a test, I still defined my IOCTL as
METHOD_BUFFERED, but I used SystemBuffer as input buffer
and UserBuffer as output buffer, it worked!!!
So, which is correct?
>-----Original Message-----
>I have 2 drivers and 1 user mode application, one driver
>runs in NT, one driver runs in Win2K and Win2003, they
>share some common codes. The application uses IOCTLs to
>communicate with driver.
>
>There is an IOCTL, if device is in a specific internal
>state, this IOCTL fails and the driver return
>STATUS_INVALID_PARAMETER to system, but the driver also
>return some internal error information to application,
>this information is returned through output buffer
>argument when calling IODeviceControl. In Windows NT,
>this error information can be returned to application, so
>when this IOCTL fails, the application can tell user why
>it fails. In Windows 2000(SP4) and Windows 2003, this
>error information cannot be returned to application, the
>result is when this IOCTL fails, the application tells
>user "unknown error", this is very bad.
>
>This IOCTL uses BUFFERD_IO to communicate with kernel, I
>wonder if this is because of security reason, when an
>IOCTL fails, Win2K(sp4) and Win2003 doesn't copy the data
>in kernel buffer to user mode buffer, but Windows NT
still
>does that?
>
>Thanks.
>
>.
>