From 92aa8a7d2faeb6bccb247e6a660ad54536e0a792 Mon Sep 17 00:00:00 2001 From: martin-kudlicka Date: Mon, 3 May 2021 16:14:02 +0000 Subject: [PATCH] + DeviceIoControl hang patch (https://github.com/billziss-gh/winspd/issues/10#issuecomment-824758300) --- vanilla/inc/winspd/ioctl.h | 3 +- vanilla/src/shared/ioctl.c | 20 ++++- vanilla/src/shared/stghandle.c | 49 +++++++---- vanilla/src/shared/stgunit.c | 20 ++++- vanilla/tst/winspd-tests/ioctl-test.c | 121 ++++++++++++++++++++++---- 5 files changed, 169 insertions(+), 44 deletions(-) diff --git a/vanilla/inc/winspd/ioctl.h b/vanilla/inc/winspd/ioctl.h index 1790ddf..b0dc27f 100644 --- a/vanilla/inc/winspd/ioctl.h +++ b/vanilla/inc/winspd/ioctl.h @@ -215,7 +215,8 @@ DWORD SpdIoctlTransact(HANDLE DeviceHandle, UINT32 Btl, SPD_IOCTL_TRANSACT_RSP *Rsp, SPD_IOCTL_TRANSACT_REQ *Req, - PVOID DataBuffer); + PVOID DataBuffer, + OVERLAPPED *Overlapped); DWORD SpdIoctlSetTransactProcessId(HANDLE DeviceHandle, UINT32 Btl, ULONG ProcessId); diff --git a/vanilla/src/shared/ioctl.c b/vanilla/src/shared/ioctl.c index 4533c2b..2e94d75 100644 --- a/vanilla/src/shared/ioctl.c +++ b/vanilla/src/shared/ioctl.c @@ -412,7 +412,8 @@ DWORD SpdIoctlTransact(HANDLE DeviceHandle, UINT32 Btl, SPD_IOCTL_TRANSACT_RSP *Rsp, SPD_IOCTL_TRANSACT_REQ *Req, - PVOID DataBuffer) + PVOID DataBuffer, + OVERLAPPED *Overlapped) { SPD_IOCTL_TRANSACT_PARAMS Params; DWORD BytesTransferred; @@ -452,13 +453,26 @@ DWORD SpdIoctlTransact(HANDLE DeviceHandle, * FILE_FLAG_OVERLAPPED flag we ensure that the unproductive serialization * does not happen. */ + // DeviceIoControl() can hang if lpOverlapped is NULL if (!DeviceIoControl(DeviceHandle, IOCTL_MINIPORT_PROCESS_SERVICE_IRP, &Params, sizeof Params, &Params, sizeof Params, - &BytesTransferred, 0)) + &BytesTransferred, Overlapped)) { Error = GetLastError(); - goto exit; + if (ERROR_IO_PENDING == Error) + { + if (!GetOverlappedResult(DeviceHandle, Overlapped, + &BytesTransferred, TRUE)) + { + Error = GetLastError(); + goto exit; + } + } + else + { + goto exit; + } } if (0 != Req) diff --git a/vanilla/src/shared/stghandle.c b/vanilla/src/shared/stghandle.c index c08eaaf..46a2807 100644 --- a/vanilla/src/shared/stghandle.c +++ b/vanilla/src/shared/stghandle.c @@ -278,13 +278,13 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, UINT32 Btl, SPD_IOCTL_TRANSACT_RSP *Rsp, SPD_IOCTL_TRANSACT_REQ *Req, - PVOID DataBuffer) + PVOID DataBuffer, + OVERLAPPED *Overlapped) { STORAGE_UNIT *StorageUnit = Handle; LONG Connected; ULONG DataLength; TRANSACT_MSG *Msg = 0; - OVERLAPPED Overlapped; DWORD BytesTransferred; DWORD Error; @@ -292,10 +292,6 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, (0 != Req && 0 == DataBuffer)) return ERROR_INVALID_PARAMETER; - Error = SpdOverlappedInit(&Overlapped); - if (ERROR_SUCCESS != Error) - goto exit; - AcquireSRWLockShared(&StorageUnitLock); Error = StorageUnit == StorageUnits[SPD_INDEX_FROM_BTL(Btl)] ? ERROR_SUCCESS : ERROR_FILE_NOT_FOUND; @@ -316,16 +312,16 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, { Error = WaitOverlappedResult( StorageUnit->Event, - ConnectNamedPipe(StorageUnit->Pipe, &Overlapped), - StorageUnit->Pipe, &Overlapped, &BytesTransferred); + ConnectNamedPipe(StorageUnit->Pipe, Overlapped), + StorageUnit->Pipe, Overlapped, &BytesTransferred); if (ERROR_SUCCESS == Error || ERROR_PIPE_CONNECTED == Error) { Error = WaitOverlappedResult( StorageUnit->Event, WriteFile(StorageUnit->Pipe, &StorageUnit->StorageUnitParams, sizeof StorageUnit->StorageUnitParams, - 0, &Overlapped), - StorageUnit->Pipe, &Overlapped, &BytesTransferred); + 0, Overlapped), + StorageUnit->Pipe, Overlapped, &BytesTransferred); if (ERROR_SUCCESS == Error) { StorageUnit->Connected = -StorageUnit->Connected; @@ -354,8 +350,8 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, memcpy(Msg + 1, DataBuffer, DataLength); Error = WaitOverlappedResult( StorageUnit->Event, - WriteFile(StorageUnit->Pipe, Msg, sizeof(TRANSACT_MSG) + DataLength, 0, &Overlapped), - StorageUnit->Pipe, &Overlapped, &BytesTransferred); + WriteFile(StorageUnit->Pipe, Msg, sizeof(TRANSACT_MSG) + DataLength, 0, Overlapped), + StorageUnit->Pipe, Overlapped, &BytesTransferred); if (ERROR_SUCCESS != Error) goto disconnect; } @@ -365,8 +361,8 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, Error = WaitOverlappedResult( StorageUnit->Event, ReadFile(StorageUnit->Pipe, - Msg, sizeof(TRANSACT_MSG) + StorageUnit->StorageUnitParams.MaxTransferLength, 0, &Overlapped), - StorageUnit->Pipe, &Overlapped, &BytesTransferred); + Msg, sizeof(TRANSACT_MSG) + StorageUnit->StorageUnitParams.MaxTransferLength, 0, Overlapped), + StorageUnit->Pipe, Overlapped, &BytesTransferred); if (ERROR_SUCCESS != Error) goto disconnect; @@ -418,8 +414,6 @@ static DWORD SpdStorageUnitHandleTransactPipe(HANDLE Handle, exit: MemFree(Msg); - SpdOverlappedFini(&Overlapped); - return Error; disconnect: @@ -544,12 +538,29 @@ DWORD SpdStorageUnitHandleTransact(HANDLE Handle, UINT32 Btl, SPD_IOCTL_TRANSACT_RSP *Rsp, SPD_IOCTL_TRANSACT_REQ *Req, - PVOID DataBuffer) + PVOID DataBuffer, + OVERLAPPED *Overlapped) { + OVERLAPPED TempOverlapped = { 0 }; + DWORD Error; + + if (Overlapped == NULL) + { + Error = SpdOverlappedInit(&TempOverlapped); + if (ERROR_SUCCESS != Error) + return Error; + + Overlapped = &TempOverlapped; + } + if (IsPipeHandle(Handle)) - return SpdStorageUnitHandleTransactPipe(GetPipeHandle(Handle), Btl, Rsp, Req, DataBuffer); + Error = SpdStorageUnitHandleTransactPipe(GetPipeHandle(Handle), Btl, Rsp, Req, DataBuffer, Overlapped); else - return SpdIoctlTransact(GetDeviceHandle(Handle), Btl, Rsp, Req, DataBuffer); + Error = SpdIoctlTransact(GetDeviceHandle(Handle), Btl, Rsp, Req, DataBuffer, Overlapped); + + SpdOverlappedFini(&TempOverlapped); + + return Error; } DWORD SpdStorageUnitHandleShutdown(HANDLE Handle, diff --git a/vanilla/src/shared/stgunit.c b/vanilla/src/shared/stgunit.c index e83ada9..782bb4c 100644 --- a/vanilla/src/shared/stgunit.c +++ b/vanilla/src/shared/stgunit.c @@ -28,7 +28,8 @@ DWORD SpdStorageUnitHandleTransact(HANDLE Handle, UINT32 Btl, SPD_IOCTL_TRANSACT_RSP *Rsp, SPD_IOCTL_TRANSACT_REQ *Req, - PVOID DataBuffer); + PVOID DataBuffer, + OVERLAPPED *Overlapped); DWORD SpdStorageUnitHandleShutdown(HANDLE Handle, const GUID *Guid); DWORD SpdStorageUnitHandleClose(HANDLE Handle); @@ -135,6 +136,7 @@ static DWORD WINAPI SpdStorageUnitDispatcherThread(PVOID StorageUnit0) SPD_IOCTL_TRANSACT_RSP ResponseBuf, *Response; SPD_STORAGE_UNIT_OPERATION_CONTEXT OperationContext; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DispatcherThread = 0; BOOLEAN Complete; DWORD Error; @@ -146,6 +148,10 @@ static DWORD WINAPI SpdStorageUnitDispatcherThread(PVOID StorageUnit0) goto exit; } + Error = SpdOverlappedInit(&Overlapped); + if (ERROR_SUCCESS != Error) + goto exit; + OperationContext.Request = &RequestBuf; OperationContext.Response = &ResponseBuf; OperationContext.DataBuffer = DataBuffer; @@ -165,9 +171,15 @@ static DWORD WINAPI SpdStorageUnitDispatcherThread(PVOID StorageUnit0) Response = 0; for (;;) { + if (!ResetEvent(Overlapped.hEvent)) + { + Error = GetLastError(); + goto exit; + } + memset(Request, 0, sizeof *Request); Error = SpdStorageUnitHandleTransact(StorageUnit->Handle, - StorageUnit->Btl, Response, Request, DataBuffer); + StorageUnit->Btl, Response, Request, DataBuffer, &Overlapped); if (ERROR_SUCCESS != Error) goto exit; @@ -277,6 +289,8 @@ static DWORD WINAPI SpdStorageUnitDispatcherThread(PVOID StorageUnit0) TlsSetValue(SpdStorageUnitTlsKey, 0); + SpdOverlappedFini(&Overlapped); + StorageUnit->BufferFree(DataBuffer); return Error; @@ -336,7 +350,7 @@ VOID SpdStorageUnitSendResponse(SPD_STORAGE_UNIT *StorageUnit, } Error = SpdStorageUnitHandleTransact(StorageUnit->Handle, - StorageUnit->Btl, Response, 0, DataBuffer); + StorageUnit->Btl, Response, 0, DataBuffer, NULL); if (ERROR_SUCCESS != Error) { SpdStorageUnitSetDispatcherError(StorageUnit, Error); diff --git a/vanilla/tst/winspd-tests/ioctl-test.c b/vanilla/tst/winspd-tests/ioctl-test.c index d58db87..2886ce0 100644 --- a/vanilla/tst/winspd-tests/ioctl-test.c +++ b/vanilla/tst/winspd-tests/ioctl-test.c @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -342,6 +343,7 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -352,6 +354,9 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) DataBuffer = malloc(MaxBlockCount * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -371,7 +376,9 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) ASSERT(0 != Thread); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -387,13 +394,17 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); if (5 > MaxBlockCount) { memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -409,7 +420,9 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); } @@ -419,6 +432,8 @@ static void ioctl_transact_read_dotest(ULONG MaxBlockCount) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -496,6 +511,7 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -506,6 +522,9 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) DataBuffer = malloc(MaxBlockCount * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -525,7 +544,9 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) ASSERT(0 != Thread); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -541,13 +562,17 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); if (5 > MaxBlockCount) { memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -563,7 +588,9 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); } @@ -573,6 +600,8 @@ static void ioctl_transact_write_dotest(ULONG MaxBlockCount) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -647,6 +676,7 @@ static void ioctl_transact_flush_test(void) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -657,6 +687,9 @@ static void ioctl_transact_flush_test(void) DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -677,7 +710,9 @@ static void ioctl_transact_flush_test(void) ASSERT(0 != Thread); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -689,7 +724,9 @@ static void ioctl_transact_flush_test(void) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); Error = SpdIoctlUnprovision(DeviceHandle, &StorageUnitParams.Guid); @@ -698,6 +735,8 @@ static void ioctl_transact_flush_test(void) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -776,6 +815,7 @@ static void ioctl_transact_unmap_test(void) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -786,6 +826,9 @@ static void ioctl_transact_unmap_test(void) DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -806,7 +849,9 @@ static void ioctl_transact_unmap_test(void) ASSERT(0 != Thread); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -827,7 +872,9 @@ static void ioctl_transact_unmap_test(void) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); Error = SpdIoctlUnprovision(DeviceHandle, &StorageUnitParams.Guid); @@ -836,6 +883,8 @@ static void ioctl_transact_unmap_test(void) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -905,6 +954,7 @@ static void ioctl_transact_error_test(void) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -915,6 +965,9 @@ static void ioctl_transact_error_test(void) DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -933,7 +986,9 @@ static void ioctl_transact_error_test(void) Thread = (HANDLE)_beginthreadex(0, 0, ioctl_transact_error_test_thread, (PVOID)(UINT_PTR)Btl, 0, 0); ASSERT(0 != Thread); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -953,7 +1008,9 @@ static void ioctl_transact_error_test(void) Rsp.Status.Information = 11; Rsp.Status.InformationValid = 1; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); Error = SpdIoctlUnprovision(DeviceHandle, &StorageUnitParams.Guid); @@ -962,6 +1019,8 @@ static void ioctl_transact_error_test(void) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -1014,6 +1073,7 @@ static void ioctl_transact_cancel_test(void) SPD_IOCTL_STORAGE_UNIT_PARAMS StorageUnitParams; SPD_IOCTL_TRANSACT_REQ Req; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -1024,6 +1084,9 @@ static void ioctl_transact_cancel_test(void) DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -1042,7 +1105,9 @@ static void ioctl_transact_cancel_test(void) Thread = (HANDLE)_beginthreadex(0, 0, ioctl_transact_cancel_test_thread, (PVOID)(UINT_PTR)Btl, 0, 0); ASSERT(0 != Thread); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -1058,6 +1123,8 @@ static void ioctl_transact_cancel_test(void) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE); @@ -1161,18 +1228,24 @@ static void ioctl_process_access_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) HANDLE DeviceHandle; SPD_IOCTL_TRANSACT_REQ Req; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; DWORD Error; BOOL Success; DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, 0, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, 0, 0, &Req, DataBuffer, &Overlapped); ASSERT(ERROR_ACCESS_DENIED == Error); + Error = ResetEvent(Overlapped.hEvent); + ASSERT(ERROR_SUCCESS == Error); Error = SpdIoctlUnprovision(DeviceHandle, &TestGuid); ASSERT(ERROR_ACCESS_DENIED == Error); @@ -1180,6 +1253,8 @@ static void ioctl_process_access_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); } @@ -1261,6 +1336,7 @@ static void ioctl_process_transact_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) SPD_IOCTL_TRANSACT_REQ Req; SPD_IOCTL_TRANSACT_RSP Rsp; PVOID DataBuffer = 0; + OVERLAPPED Overlapped; HANDLE DeviceHandle; UINT32 Btl; DWORD Error; @@ -1271,6 +1347,9 @@ static void ioctl_process_transact_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) DataBuffer = malloc(5 * 512); ASSERT(0 != DataBuffer); + Error = SpdOverlappedInit(&Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = SpdIoctlOpenDevice(L"" SPD_IOCTL_HARDWARE_ID, &DeviceHandle); ASSERT(ERROR_SUCCESS == Error); @@ -1280,7 +1359,9 @@ static void ioctl_process_transact_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) ASSERT(0 != Thread); memset(DataBuffer, 0, sizeof DataBuffer); - Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, 0, &Req, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); ASSERT(0 != Req.Hint); @@ -1296,12 +1377,16 @@ static void ioctl_process_transact_test_DO_NOT_RUN_FROM_COMMAND_LINE(void) Rsp.Hint = Req.Hint; Rsp.Kind = Req.Kind; - Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer); + Error = SpdIoctlTransact(DeviceHandle, Btl, &Rsp, 0, DataBuffer, &Overlapped); + ASSERT(ERROR_SUCCESS == Error); + Error = ResetEvent(Overlapped.hEvent); ASSERT(ERROR_SUCCESS == Error); Success = CloseHandle(DeviceHandle); ASSERT(Success); + SpdOverlappedFini(&Overlapped); + free(DataBuffer); WaitForSingleObject(Thread, INFINITE);