Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In cases where it is not practical to define separate IOCTL or FSCTL control codes for I/O requests from 32-bit and 64-bit applications, it is left to the driver to determine which type of application sent the I/O request. The 64-bit version of Microsoft Windows introduces a new kernel-mode routine, IoIs32bitProcess, that detects whether the current I/O request originated in a 32-bit user-mode process. Its prototype is:
BOOLEAN
IoIs32bitProcess(
_In_opt_ PIRP Irp // NULL for fast I/O call, IRP otherwise
);
IoIs32bitProcess returns TRUE if the originator of the current I/O request is a 32-bit user-mode application.
The following code sample shows how to use IoIs32bitProcess:
typedef UINT32 POINTER_32 PVOID32;
typedef struct _IOCTL_PARAMETERS
{
PVOID Addr;
SIZE_T Length;
HANDLE Handle;
} IOCTL_PARAMETERS, *PIOCTL_PARAMETERS;
typedef struct _IOCTL_PARAMETERS_32
{
PVOID32 Addr;
INT32 Length;
PVOID32 Handle;
} IOCTL_PARAMETERS_32, *PIOCTL_PARAMETERS_32;
...
IOCTL_PARAMETERS LocalParam;
if (IoIs32bitProcess(Irp))
{
/* 32-bit process IOCTL */
PIOCTL_PARAMETERS_32 params32;
params32 = (PIOCTL_PARAMETERS_32)(Irp->AssociatedIrp.SystemBuffer);
if (irpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(IOCTL_PARAMETERS_32))
{
status = STATUS_INVALID_PARAMETER;
}
else
{
LocalParam.Addr = Ptr32ToPtr(params32->Addr);
LocalParam.Handle = Handle32ToHandle(params32->Handle);
LocalParam.Length = params32->Length;
/* Handle the IOCTL here. */
...
status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
}
}
else
{
/* 64-bit process IOCTL */
PIOCTL_PARAMETERS params;
params = (PIOCTL_PARAMETERS)(Irp->AssociatedIrp.SystemBuffer);
if (irpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(IOCTL_PARAMETERS))
{
status = STATUS_INVALID_PARAMETER;
}
else
{
RtlCopyMemory(&LocalParam, params, sizeof(IOCTL_PARAMETERS));
/* Handle the IOCTL here. */
...
status = STATUS_SUCCESS;
}
Irp->IoStatus.Information = 0;
}