Reworked but still crashes

This commit is contained in:
Benjamin Höglinger-Stelzer
2018-09-30 22:19:04 +02:00
parent d64b303323
commit 31d65aa40e
4 changed files with 36 additions and 42 deletions

View File

@@ -122,7 +122,6 @@ Bus_XusbSubmitReport(
//
NTSTATUS Xusb_PreparePdo(PWDFDEVICE_INIT DeviceInit, USHORT VendorId, USHORT ProductId, PUNICODE_STRING DeviceId, PUNICODE_STRING DeviceDescription);
NTSTATUS Xusb_PrepareHardware(WDFDEVICE Device);
NTSTATUS Xusb_ReleaseHardware(WDFDEVICE Device);
NTSTATUS Xusb_AssignPdoContext(WDFDEVICE Device);
VOID Xusb_GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length);
VOID Xusb_GetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor, PPDO_DEVICE_DATA pCommon);

View File

@@ -49,6 +49,7 @@
#define HID_REPORT_TYPE_FEATURE 0x03
#define VIGEM_POOL_TAG 0x45476956 // "EGiV"
#define XUSB_POOL_TAG 'BSUX'
#define DRIVERNAME "ViGEm: "
#define MAX_HARDWARE_ID_LENGTH 0xFF
@@ -94,8 +95,7 @@ EVT_WDF_CHILD_LIST_CREATE_DEVICE Bus_EvtDeviceListCreatePdo;
EVT_WDF_CHILD_LIST_IDENTIFICATION_DESCRIPTION_COMPARE Bus_EvtChildListIdentificationDescriptionCompare;
EVT_WDF_DEVICE_PREPARE_HARDWARE Pdo_EvtDevicePrepareHardware;
EVT_WDF_DEVICE_RELEASE_HARDWARE Pdo_EvtDeviceReleaseHardware;
EVT_WDF_OBJECT_CONTEXT_CLEANUP Pdo_EvtWdfObjectContextCleanup;
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL Pdo_EvtIoInternalDeviceControl;
EVT_WDF_TIMER Xgip_SysInitTimerFunc;

View File

@@ -26,7 +26,7 @@
#pragma alloc_text(PAGE, Bus_CreatePdo)
#pragma alloc_text(PAGE, Bus_EvtDeviceListCreatePdo)
#pragma alloc_text(PAGE, Pdo_EvtDevicePrepareHardware)
#pragma alloc_text(PAGE, Pdo_EvtDeviceReleaseHardware)
#pragma alloc_text(PAGE, Pdo_EvtWdfObjectContextCleanup)
#endif
NTSTATUS Bus_EvtDeviceListCreatePdo(
@@ -262,7 +262,6 @@ NTSTATUS Bus_CreatePdo(
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
pnpPowerCallbacks.EvtDevicePrepareHardware = Pdo_EvtDevicePrepareHardware;
pnpPowerCallbacks.EvtDeviceReleaseHardware = Pdo_EvtDeviceReleaseHardware;
WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
@@ -275,6 +274,7 @@ NTSTATUS Bus_CreatePdo(
// Add common device data context
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&pdoAttributes, PDO_DEVICE_DATA);
pdoAttributes.EvtCleanupCallback = Pdo_EvtWdfObjectContextCleanup;
status = WdfDeviceCreate(&DeviceInit, &pdoAttributes, &hChild);
if (!NT_SUCCESS(status))
@@ -579,33 +579,38 @@ NTSTATUS Pdo_EvtDevicePrepareHardware(
return status;
}
//
// PDO power-down.
//
_Use_decl_annotations_
NTSTATUS
Pdo_EvtDeviceReleaseHardware(
WDFDEVICE Device,
WDFCMRESLIST ResourcesTranslated
VOID
Pdo_EvtWdfObjectContextCleanup(
WDFOBJECT Object
)
{
PPDO_DEVICE_DATA pdoData;
NTSTATUS status = STATUS_UNSUCCESSFUL;
ULONG index;
PXUSB_DEVICE_DATA xusb;
PAGED_CODE();
UNREFERENCED_PARAMETER(ResourcesTranslated);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_BUSENUM, "%!FUNC! Entry");
pdoData = PdoGetData(Device);
pdoData = PdoGetData(Object);
UNREFERENCED_PARAMETER(pdoData);
switch (pdoData->TargetType)
{
// Free XUSB resources
case Xbox360Wired:
status = Xusb_ReleaseHardware(Device);
xusb = XusbGetData(Object);
for (index = 0; index < XUSB_INIT_BLOB_COUNT; index++)
{
//
// TODO: crashes...
//
ExFreePool(xusb->InterruptInitStageBlobs[index]);
}
break;
@@ -613,9 +618,7 @@ Pdo_EvtDeviceReleaseHardware(
break;
}
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_BUSPDO, "%!FUNC! Exit with status %!STATUS!", status);
return status;
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_BUSPDO, "%!FUNC! Exit");
}
//

View File

@@ -240,21 +240,6 @@ NTSTATUS Xusb_PrepareHardware(WDFDEVICE Device)
return STATUS_SUCCESS;
}
NTSTATUS Xusb_ReleaseHardware(WDFDEVICE Device)
{
ULONG index;
PXUSB_DEVICE_DATA xusb = XusbGetData(Device);
for (index = 0; index < XUSB_INIT_BLOB_COUNT; index++)
{
if (xusb->InterruptInitStageBlobs[index])
ExFreePoolWithTag(xusb->InterruptInitStageBlobs[index], VIGEM_POOL_TAG);
}
return STATUS_SUCCESS;
}
NTSTATUS Xusb_AssignPdoContext(WDFDEVICE Device)
{
NTSTATUS status;
@@ -276,13 +261,20 @@ NTSTATUS Xusb_AssignPdoContext(WDFDEVICE Device)
xusb->Packet.Size = 0x14;
// Prepare blob storage
xusb->InterruptInitStageBlobs[0] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[1] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[2] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[3] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[4] = ExAllocatePoolWithTag(NonPagedPool, sizeof(XUSB_INTERRUPT_IN_PACKET), VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[5] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[6] = ExAllocatePoolWithTag(NonPagedPool, XUSB_INIT_STAGE_SIZE, VIGEM_POOL_TAG);
xusb->InterruptInitStageBlobs[0] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[1] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[2] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[3] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[4] = ExAllocatePoolWithTag(
NonPagedPoolNx, sizeof(XUSB_INTERRUPT_IN_PACKET), XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[5] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
xusb->InterruptInitStageBlobs[6] = ExAllocatePoolWithTag(
NonPagedPoolNx, XUSB_INIT_STAGE_SIZE, XUSB_POOL_TAG);
// Validate allocations
for (index = 0; index < XUSB_INIT_BLOB_COUNT; index++)