Schulung
Modul
Troubleshoot device driver failures - Training
This module focuses on the role of device drivers and troubleshooting problems that pertain to them.
Dieser Browser wird nicht mehr unterstützt.
Führen Sie ein Upgrade auf Microsoft Edge aus, um die neuesten Funktionen, Sicherheitsupdates und technischen Support zu nutzen.
Das folgende Beispiel zeigt, wie Sie einen 32-Bit-Treiber für 64-Bit ändern, indem Sie dem IOCTL-Steuerelementcode ein Feld "64 Bit" hinzufügen. Beachten Sie, dass in diesem Beispiel nur die Teile des Treibercodes angezeigt werden, die geändert werden müssen.
Es folgt die 32-Bit-Version des Treibers:
#define REGISTER_FUNCTION 0 // Define the IOCTL function code
#define IOCTL_REGISTER CTL_CODE(FILE_DEVICE_UNKNOWN, \
REGISTER_FUNCTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
typedef struct _IOCTL_PARAMETERS {
PVOID Addr;
SIZE_T Length;
HANDLE Handle;
} IOCTL_PARAMETERS, *PIOCTL_PARAMETERS;
NTSTATUS
TestdrvDeviceControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION irpSp;
NTSTATUS status;
PIOCTL_PARAMETERS params;
IOCTL_PARAMETERS LocalParam;
PIOCTL_PARAMETERS_32 params32;
//
// Get a pointer to the current parameters for this request. The
// information is contained in the current stack location.
//
irpSp = IoGetCurrentIrpStackLocation(Irp);
//
// Case on the device control code
//
switch (irpSp->Parameters.DeviceIoControl.IoControlCode) {
case IOCTL_REGISTER:
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;
break;
//
// Unrecognized device control request
//
default:
Irp->IoStatus.Information = 0;
status = STATUS_INVALID_PARAMETER;
break;
}
//
// If status is pending, mark the IRP pending and start the
// request in a cancelable state. Otherwise, complete the IRP.
//
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(status);
}
Es folgt die 64-Bit-Version des Treibers:
#define REGISTER_FUNCTION 0 // Define the IOCTL function code
#ifdef _WIN64
#define CLIENT_64BIT 0x800
#define REGISTER_FUNCTION 0
#define IOCTL_REGISTER CTL_CODE(FILE_DEVICE_UNKNOWN, \
CLIENT_64BIT|REGISTER_FUNCTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
#else
#define IOCTL_REGISTER CTL_CODE(FILE_DEVICE_UNKNOWN, \
REGISTER_FUNCTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif
typedef struct _IOCTL_PARAMETERS {
PVOID Addr;
SIZE_T Length;
HANDLE Handle;
} IOCTL_PARAMETERS, *PIOCTL_PARAMETERS;
#ifdef _WIN64
#define IOCTL_REGISTER_32 CTL_CODE(FILE_DEVICE_UNKNOWN, \
REGISTER_FUNCTION, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif
...
#ifdef _WIN64
typedef struct _IOCTL_PARAMETERS_32 {
VOID*POINTER_32 Addr;
INT32 Length;
VOID*POINTER_32 Handle;
} IOCTL_PARAMETERS_32, *PIOCTL_PARAMETERS_32;
#endif
...
NTSTATUS
TestdrvDeviceControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION irpSp;
NTSTATUS status;
PIOCTL_PARAMETERS params;
IOCTL_PARAMETERS LocalParam;
PIOCTL_PARAMETERS_32 params32;
//
// Get a pointer to the current parameters for this request. The
// information is contained in the current stack location.
//
irpSp = IoGetCurrentIrpStackLocation(Irp);
//
// Case on the device control code
//
switch (irpSp->Parameters.DeviceIoControl.IoControlCode) {
#ifdef _WIN64
case IOCTL_REGISTER_32:
params32 = (PIOCTL_PARAMETERS_32)
(Irp->AssociatedIrp.SystemBuffer);
if (irpSp->Parameters.DeviceIoControl.InputBufferLength <
sizeof(IOCTL_PARAMETERS_32)) {
status = STATUS_INVALID_PARAMETER;
} else {
LocalParam.Addr = params32->Addr;
LocalParam.Handle = params32->Handle;
LocalParam.Length = params32->Length;
/* Handle the ioctl here */
status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
}
break;
#endif
case IOCTL_REGISTER:
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;
break;
//
// Unrecognized device control request
//
default:
Irp->IoStatus.Information = 0;
status = STATUS_INVALID_PARAMETER;
break;
}
//
// If status is pending, mark the IRP pending and start the
// request in a cancelable state. Otherwise, complete the IRP.
//
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(status);
}
Schulung
Modul
Troubleshoot device driver failures - Training
This module focuses on the role of device drivers and troubleshooting problems that pertain to them.