From 0630823944c6131a7138124eb3e5b3a0e0fa69a2 Mon Sep 17 00:00:00 2001 From: Joachim Henze Date: Sun, 30 Jul 2023 21:52:28 +0200 Subject: [PATCH] [0.4.11][NTUSER] NtUserWaitForInputIdle: Fix unhandled exception BSOD 0x1E, and tweaks Backport the following commits: 0.4.15-dev-6397-g 6b7efb331c0cd20c8610cd24d5e7221cff59969a [NTUSER] co_IntSendMessageWithCallBack: Formatting only, no functional changes 0.4.15-dev-6227-g c7e4c3a8e9d921233c1731ef64c388ed40b15fcb [NTUSER] NtUserWaitForInputIdle: Fix unhandled exception BSOD 0x1E CORE-18728 CORE-19014 (#5391) 0.4.15-dev-697-g 9f428f5522c9a6a4ec8cf19f7f0c543c944b9483 [NTUSER] Demote ERR to TRACE, also some minor corrections (#3132) win32k.sys master GCC8.4.0dbg RosBEWin2.2.0 3.477.504 win32k.sys 0.4.14 GCC4.7.2dbg RosBEWin2.1.6 2.904.064 -> 2.904.064 win32k.sys 0.4.13 GCC4.7.2dbg RosBEWin2.1.6 2.895.872 -> 2.895.872 win32k.sys 0.4.12 GCC4.7.2dbg RosBEWin2.1.6 2.887.680 -> 2.887.680 win32k.sys 0.4.11 GCC4.7.2dbg RosBEWin2.1.6 2.867.200 -> 2.867.200 win32k.sys 0.4.10 GCC4.7.2dbg RosBEWin2.1.6 2.863.104 -> 2.863.104 win32k.sys 0.4. 9 GCC4.7.2dbg RosBEWin2.1.6 2.834.432 -> 2.834.432 win32k.sys 0.4. 8 GCC4.7.2dbg RosBEWin2.1.6 2.830.336 -> 2.830.336 win32k.sys 0.4. 7 GCC4.7.2dbg RosBEWin2.1.6 2.830.336 -> 2.830.336 --- win32ss/user/ntuser/message.c | 85 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/win32ss/user/ntuser/message.c b/win32ss/user/ntuser/message.c index 97fb0389afd..81bcab97628 100644 --- a/win32ss/user/ntuser/message.c +++ b/win32ss/user/ntuser/message.c @@ -2,7 +2,6 @@ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS Win32k subsystem * PURPOSE: Messages - * FILE: win32ss/user/ntuser/message.c * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net) */ @@ -788,7 +787,7 @@ static LRESULT handle_internal_message( PWND pWnd, UINT msg, WPARAM wparam, LPAR } case WM_ASYNC_DESTROYWINDOW: { - ERR("WM_ASYNC_DESTROYWINDOW\n"); + TRACE("WM_ASYNC_DESTROYWINDOW\n"); if (pWnd->style & WS_CHILD) return co_UserFreeWindow(pWnd, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE); else @@ -1705,12 +1704,12 @@ co_IntSendMessageNoWait(HWND hWnd, LPARAM lParam) { ULONG_PTR Result = 0; - return co_IntSendMessageWithCallBack( hWnd, - Msg, - wParam, - lParam, - NULL, - 0, + return co_IntSendMessageWithCallBack(hWnd, + Msg, + wParam, + lParam, + NULL, + 0, &Result); } /* MSDN: @@ -1721,7 +1720,7 @@ co_IntSendMessageNoWait(HWND hWnd, process the message and the sender will free the memory before it is used. */ LRESULT FASTCALL -co_IntSendMessageWithCallBack( HWND hWnd, +co_IntSendMessageWithCallBack(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, @@ -1742,7 +1741,7 @@ co_IntSendMessageWithCallBack( HWND hWnd, if (!(Window = UserGetWindowObject(hWnd))) { - TRACE("SendMessageWithCallBack: Invalid handle 0x%p!\n",hWnd); + TRACE("SendMessageWithCallBack: Invalid handle 0x%p\n",hWnd); RETURN(FALSE); } @@ -1751,29 +1750,26 @@ co_IntSendMessageWithCallBack( HWND hWnd, if (Window->state & WNDS_DESTROYED) { /* FIXME: last error? */ - ERR("Attempted to send message to window %p that is being destroyed!\n", hWnd); + ERR("Attempted to send message to window %p that is being destroyed\n", hWnd); RETURN(FALSE); } Win32Thread = PsGetCurrentThreadWin32Thread(); - if (Win32Thread == NULL || - Win32Thread->TIF_flags & TIF_INCLEANUP) - { + if (Win32Thread == NULL || Win32Thread->TIF_flags & TIF_INCLEANUP) RETURN(FALSE); - } ptiSendTo = IntSendTo(Window, Win32Thread, Msg); if (Msg & 0x80000000 && !ptiSendTo) { - if (Win32Thread->TIF_flags & TIF_INCLEANUP) RETURN( FALSE); + if (Win32Thread->TIF_flags & TIF_INCLEANUP) RETURN(FALSE); - TRACE("SMWCB: Internal Message!\n"); - Result = (ULONG_PTR)handle_internal_message( Window, Msg, wParam, lParam ); - if (uResult) *uResult = Result; - RETURN( TRUE); + TRACE("SMWCB: Internal Message\n"); + Result = (ULONG_PTR)handle_internal_message(Window, Msg, wParam, lParam); + if (uResult) *uResult = Result; + RETURN(TRUE); } /* See if this message type is present in the table */ @@ -1788,14 +1784,14 @@ co_IntSendMessageWithCallBack( HWND hWnd, if (!lParamBufferSize) lParamBufferSize = -1; } - if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, !!ptiSendTo))) + if (!NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, !!ptiSendTo))) { ERR("Failed to pack message parameters\n"); - RETURN( FALSE); + RETURN(FALSE); } /* If it can be sent now, then send it. */ - if ( !ptiSendTo ) + if (!ptiSendTo) { if (Win32Thread->TIF_flags & TIF_INCLEANUP) { @@ -1804,9 +1800,9 @@ co_IntSendMessageWithCallBack( HWND hWnd, RETURN(FALSE); } - IntCallWndProc( Window, hWnd, Msg, wParam, lParam); + IntCallWndProc(Window, hWnd, Msg, wParam, lParam); - if ( Window->state & WNDS_SERVERSIDEWINDOWPROC ) + if (Window->state & WNDS_SERVERSIDEWINDOWPROC) { TRACE("SMWCB: Server Side Window Procedure\n"); switch(Window->fnid) @@ -1815,28 +1811,28 @@ co_IntSendMessageWithCallBack( HWND hWnd, DoCallBack = !DesktopWindowProc(Window, Msg, wParam, lParamPacked, (LRESULT*)&Result); break; case FNID_MESSAGEWND: - DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result); + DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam, (LRESULT*)&Result); break; case FNID_MENU: - DoCallBack = !PopupMenuWndProc( Window, Msg, wParam, lParam,(LRESULT*)&Result); + DoCallBack = !PopupMenuWndProc(Window, Msg, wParam, lParam, (LRESULT*)&Result); break; } } if (DoCallBack) - Result = (ULONG_PTR)co_IntCallWindowProc( Window->lpfnWndProc, - !Window->Unicode, - hWnd, - Msg, - wParam, - lParamPacked, - lParamBufferSize ); + Result = (ULONG_PTR)co_IntCallWindowProc(Window->lpfnWndProc, + !Window->Unicode, + hWnd, + Msg, + wParam, + lParamPacked, + lParamBufferSize); if(uResult) { *uResult = Result; } - IntCallWndProcRet( Window, hWnd, Msg, wParam, lParam, (LRESULT *)uResult); + IntCallWndProcRet(Window, hWnd, Msg, wParam, lParam, (LRESULT *)uResult); if (CompletionCallback) { @@ -1848,9 +1844,9 @@ co_IntSendMessageWithCallBack( HWND hWnd, } } - if ( !ptiSendTo) + if (!ptiSendTo) { - if (! NT_SUCCESS(UnpackParam(lParamPacked, Msg, wParam, lParam, FALSE))) + if (!NT_SUCCESS(UnpackParam(lParamPacked, Msg, wParam, lParam, FALSE))) { ERR("Failed to unpack message parameters\n"); } @@ -1859,8 +1855,8 @@ co_IntSendMessageWithCallBack( HWND hWnd, if(!(Message = AllocateUserMessage(FALSE))) { - ERR("MsqSendMessage(): Not enough memory to allocate a message"); - RETURN( FALSE); + ERR("Failed to allocate message\n"); + RETURN(FALSE); } Message->Msg.hwnd = hWnd; @@ -1871,7 +1867,7 @@ co_IntSendMessageWithCallBack( HWND hWnd, Message->lResult = 0; Message->QS_Flags = 0; Message->ptiReceiver = ptiSendTo; - Message->ptiSender = NULL; // mjmartin, you are right! This is null. + Message->ptiSender = NULL; Message->ptiCallBackSender = Win32Thread; Message->CompletionCallback = CompletionCallback; Message->CompletionCallbackContext = CompletionCallbackContext; @@ -1881,9 +1877,9 @@ co_IntSendMessageWithCallBack( HWND hWnd, Message->flags = SMF_RECEIVERFREE; if (Msg & 0x80000000) // Higher priority event message! - InsertHeadList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry); + InsertHeadList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry); else - InsertTailList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry); + InsertTailList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry); MsqWakeQueue(ptiSendTo, QS_SENDMESSAGE, TRUE); RETURN(TRUE); @@ -3102,14 +3098,12 @@ NtUserWaitForInputIdle( IN HANDLE hProcess, Timeout.QuadPart = (LONGLONG) dwMilliseconds * (LONGLONG) -10000; KeStackAttachProcess(&Process->Pcb, &ApcState); - W32Process->W32PF_flags |= W32PF_WAITFORINPUTIDLE; for (pti = W32Process->ptiList; pti; pti = pti->ptiSibling) { pti->TIF_flags |= TIF_WAITFORINPUTIDLE; pti->pClientInfo->dwTIFlags = pti->TIF_flags; } - KeUnstackDetachProcess(&ApcState); TRACE("WFII: ppi %p\n", W32Process); @@ -3168,12 +3162,15 @@ NtUserWaitForInputIdle( IN HANDLE hProcess, while (TRUE); WaitExit: + KeStackAttachProcess(&Process->Pcb, &ApcState); for (pti = W32Process->ptiList; pti; pti = pti->ptiSibling) { pti->TIF_flags &= ~TIF_WAITFORINPUTIDLE; pti->pClientInfo->dwTIFlags = pti->TIF_flags; } W32Process->W32PF_flags &= ~W32PF_WAITFORINPUTIDLE; + KeUnstackDetachProcess(&ApcState); + IntDereferenceProcessInfo(W32Process); ObDereferenceObject(Process); UserLeave();