Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class OVERLAPPED_WRONG : public OVERLAPPED
- {
- ~OVERLAPPED_WRONG() // private !!
- {
- DbgPrint("%x>%s<%p>\n", GetCurrentThreadId(), __FUNCTION__, this);
- }
- VOID IoCompletionWin32(_In_ DWORD dwErrorCode, _In_ DWORD dwNumberOfBytesTransfered)
- {
- DbgPrint("%x>%s(%x, %x)\n", GetCurrentThreadId(), __FUNCTION__, dwErrorCode, dwNumberOfBytesTransfered);
- delete this;// !!!
- }
- static VOID WINAPI IoCompletionNT(
- _In_ DWORD dwErrorCode,//really NTSTATUS
- _In_ DWORD dwNumberOfBytesTransfered,
- _Inout_ LPOVERLAPPED lpOverlapped
- )
- {
- DbgPrint("%x> !! %s(%x, %x)\n", GetCurrentThreadId(), __FUNCTION__, dwErrorCode, dwNumberOfBytesTransfered);
- static_cast<OVERLAPPED_WRONG*>(lpOverlapped)->IoCompletionWin32(RtlNtStatusToDosError(dwErrorCode), dwNumberOfBytesTransfered);
- }
- public:
- OVERLAPPED_WRONG()
- {
- Internal = STATUS_PENDING;
- InternalHigh = 0;
- hEvent = 0;
- Offset = 0, OffsetHigh = 0;
- DbgPrint("%x>%s<%p>\n", GetCurrentThreadId(), __FUNCTION__, this);
- }
- void CheckError(BOOL fOk, BOOL bSkipOnSynchronous)
- {
- CheckError(fOk ? NOERROR : GetLastError(), bSkipOnSynchronous);
- }
- void CheckError(ULONG dwErrorCode, BOOL bSkipOnSynchronous)
- {
- switch (dwErrorCode)
- {
- case ERROR_IO_PENDING:
- return;
- case NOERROR:
- if (!bSkipOnSynchronous) return;
- [[fallthrough]];
- default:
- IoCompletionWin32(dwErrorCode, (ULONG)InternalHigh);
- }
- }
- static BOOL BindIoCompletionCallback (HANDLE FileHandle)
- {
- return ::BindIoCompletionCallback(FileHandle, IoCompletionNT, 0);
- }
- };
- class OVERLAPPED_OK : public OVERLAPPED
- {
- LONG dwRefCount;
- void Release()
- {
- if (!InterlockedDecrement(&dwRefCount)) delete this;
- }
- ~OVERLAPPED_OK() // private !!
- {
- DbgPrint("%x>%s<%p>\n", GetCurrentThreadId(), __FUNCTION__, this);
- }
- VOID IoCompletionWin32(_In_ DWORD dwErrorCode, _In_ DWORD dwNumberOfBytesTransfered)
- {
- DbgPrint("%x>%s(%x, %x)\n", GetCurrentThreadId(), __FUNCTION__, dwErrorCode, dwNumberOfBytesTransfered);
- Release();
- }
- static VOID WINAPI IoCompletionNT(
- _In_ DWORD dwErrorCode,//really NTSTATUS
- _In_ DWORD dwNumberOfBytesTransfered,
- _Inout_ LPOVERLAPPED lpOverlapped
- )
- {
- DbgPrint("%x> !! %s(%x, %x)\n", GetCurrentThreadId(), __FUNCTION__, dwErrorCode, dwNumberOfBytesTransfered);
- static_cast<OVERLAPPED_OK*>(lpOverlapped)->IoCompletionWin32(RtlNtStatusToDosError(dwErrorCode), dwNumberOfBytesTransfered);
- }
- public:
- OVERLAPPED_OK() : dwRefCount(2)
- {
- Internal = STATUS_PENDING;
- InternalHigh = 0;
- hEvent = 0;
- Offset = 0, OffsetHigh = 0;
- DbgPrint("%x>%s<%p>\n", GetCurrentThreadId(), __FUNCTION__, this);
- }
- void CheckError(BOOL fOk, BOOL bSkipOnSynchronous)
- {
- CheckError(fOk ? NOERROR : GetLastError(), bSkipOnSynchronous);
- }
- void CheckError(ULONG dwErrorCode, BOOL bSkipOnSynchronous)
- {
- if (dwErrorCode != ERROR_IO_PENDING && (Internal == STATUS_PENDING || bSkipOnSynchronous))
- {
- IoCompletionWin32(dwErrorCode, (ULONG)InternalHigh);
- }
- Release();
- }
- static BOOL BindIoCompletionCallback (HANDLE FileHandle)
- {
- return ::BindIoCompletionCallback(FileHandle, IoCompletionNT, 0);
- }
- };
- #if 0
- #define OVERLAPPED_ OVERLAPPED_WRONG
- #else
- #define OVERLAPPED_ OVERLAPPED_OK
- #endif
- void LockTest(HANDLE hFile, DWORD dwReserved, bool bSkipOnSynchronous)
- {
- if (OVERLAPPED_* lpOverlapped = new OVERLAPPED_)
- {
- lpOverlapped->CheckError(
- LockFileEx(hFile, 0, dwReserved, 1, 0, lpOverlapped), bSkipOnSynchronous);
- }
- MessageBoxW(0, 0, 0, 0);
- DbgPrint("\n=============================\n");
- }
- HANDLE hFile = CreateFileW(L"c:/", FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED, 0);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- if (OVERLAPPED_::BindIoCompletionCallback(hFile))
- {
- LockTest(hFile, !0, false);//invalid value !0. error from user mode
- LockTest(hFile, 0, false);
- if (SetFileCompletionNotificationModes(hFile, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS))
- {
- LockTest(hFile, 0, true);
- }
- }
- CloseHandle(hFile);
- }
- from wrong
- cc0>OVERLAPPED_WRONG::OVERLAPPED_WRONG<000001593786E7B0>
- cc0>OVERLAPPED_WRONG::IoCompletionWin32(57, 0)
- cc0>OVERLAPPED_WRONG::~OVERLAPPED_WRONG<000001593786E7B0>
- =============================
- cc0>OVERLAPPED_WRONG::OVERLAPPED_WRONG<000001593786E7B0>
- cc0>OVERLAPPED_WRONG::IoCompletionWin32(57, 0)
- cc0>OVERLAPPED_WRONG::~OVERLAPPED_WRONG<000001593786E7B0>
- 1600> !! OVERLAPPED_WRONG::IoCompletionNT(c000000d, 0)
- 1600>OVERLAPPED_WRONG::IoCompletionWin32(57, 0)
- 1600>OVERLAPPED_WRONG::~OVERLAPPED_WRONG<000001593786E7B0>
- =============================
- cc0>OVERLAPPED_WRONG::OVERLAPPED_WRONG<000001593786E7B0>
- cc0>OVERLAPPED_WRONG::IoCompletionWin32(57, 0)
- cc0>OVERLAPPED_WRONG::~OVERLAPPED_WRONG<000001593786E7B0>
- =============================
- from ok
- 17a8>OVERLAPPED_OK::OVERLAPPED_OK<0000017190BD0F50>
- 17a8>OVERLAPPED_OK::IoCompletionWin32(57, 0)
- 17a8>OVERLAPPED_OK::~OVERLAPPED_OK<0000017190BD0F50>
- =============================
- 17a8>OVERLAPPED_OK::OVERLAPPED_OK<0000017190BD0F50>
- 1a80> !! OVERLAPPED_OK::IoCompletionNT(c000000d, 0)
- 1a80>OVERLAPPED_OK::IoCompletionWin32(57, 0)
- 1a80>OVERLAPPED_OK::~OVERLAPPED_OK<0000017190BD0F50>
- =============================
- 17a8>OVERLAPPED_OK::OVERLAPPED_OK<0000017190BD0F50>
- 17a8>OVERLAPPED_OK::IoCompletionWin32(57, 0)
- 17a8>OVERLAPPED_OK::~OVERLAPPED_OK<0000017190BD0F50>
- =============================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement