Author: gadamopoulos Date: Mon Aug 8 13:31:33 2011 New Revision: 53139
URL: http://svn.reactos.org/svn/reactos?rev=53139&view=rev Log: [win32k] - Add co_MsqSendMessageAsync in order to send asynchronous normal and internal messages - Use co_MsqSendMessageAsync to load and unload api hook module - This hopefully fixes the last problems with api hooks implementation
Modified: branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/include/msgqueue.h branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/hook.c branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/msgqueue.c
Modified: branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/include/msgqueue.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/subsyste... ============================================================================== --- branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/include/msgqueue.h [iso-8859-1] (original) +++ branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/include/msgqueue.h [iso-8859-1] Mon Aug 8 13:31:33 2011 @@ -152,6 +152,18 @@ HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT uTimeout, BOOL Block, INT HookMessage, ULONG_PTR *uResult); + +BOOL FASTCALL +co_MsqSendMessageAsync(PTHREADINFO ptiReceiver, + HWND hwnd, + UINT Msg, + WPARAM wParam, + LPARAM lParam, + SENDASYNCPROC CompletionCallback, + ULONG_PTR CompletionCallbackContext, + BOOL HasPackedLParam, + INT HookMessage); + PUSER_MESSAGE FASTCALL MsqCreateMessage(LPMSG Msg); VOID FASTCALL
Modified: branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/hook.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/subsyste... ============================================================================== --- branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/hook.c [iso-8859-1] (original) +++ branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/hook.c [iso-8859-1] Mon Aug 8 13:31:33 2011 @@ -92,11 +92,10 @@ will receive the special purpose internal message. */ BOOL -IntHookModuleUnloaded(PDESKTOP pdesk, int iHookID, HHOOK hHook, BOOL Block) +IntHookModuleUnloaded(PDESKTOP pdesk, int iHookID, HHOOK hHook) { PTHREADINFO ptiCurrent; PLIST_ENTRY ListEntry; - ULONG_PTR Result; PPROCESSINFO ppiCsr;
DPRINT1("IntHookModuleUnloaded: iHookID=%d\n", iHookID); @@ -117,15 +116,15 @@ if(ptiCurrent->ppi->W32PF_flags & W32PF_APIHOOKLOADED) { DPRINT("IntHookModuleUnloaded: sending message to PID %d, ppi=0x%x\n", PsGetProcessId(ptiCurrent->ppi->peProcess), ptiCurrent->ppi); - co_MsqSendMessage( ptiCurrent->MessageQueue, - 0, - iHookID, - TRUE, - (LPARAM)hHook, - 0, - Block, - MSQ_INJECTMODULE, - &Result); + co_MsqSendMessageAsync( ptiCurrent, + 0, + iHookID, + TRUE, + (LPARAM)hHook, + NULL, + 0, + FALSE, + MSQ_INJECTMODULE); } } ListEntry = ListEntry->Flink; @@ -151,7 +150,6 @@ HWND *List; PWND DesktopWindow, pwndCurrent; ULONG i; - ULONG_PTR Result; PPROCESSINFO ppiCsr;
pti = PsGetCurrentThreadWin32Thread(); @@ -194,19 +192,15 @@ continue; }
- co_MsqSendMessage( ptiCurrent->MessageQueue, - 0, - WH_APIHOOK, - FALSE, /* load the module */ - 0, - 0, - TRUE, - MSQ_INJECTMODULE, - &Result); - if(Result == FALSE) - { - DPRINT1("Failed to inject module to process %d\n", PsGetProcessId(ptiCurrent->ppi->peProcess)); - } + co_MsqSendMessageAsync( ptiCurrent, + 0, + WH_APIHOOK, + FALSE, /* load the module */ + 0, + NULL, + 0, + FALSE, + MSQ_INJECTMODULE); } ExFreePoolWithTag(List, USERTAG_WINDOWLIST); } @@ -243,7 +237,7 @@ ReleaseCapturedUnicodeString(&strUahInitFunc, UserMode);
/* Notify all applications that the api hook module must be unloaded */ - return IntHookModuleUnloaded(pti->rpdesk, WH_APIHOOK, 0, TRUE); + return IntHookModuleUnloaded(pti->rpdesk, WH_APIHOOK, 0); }
static
Modified: branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/msgqueue.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/subsyste... ============================================================================== --- branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/msgqueue.c [iso-8859-1] (original) +++ branches/GSoC_2011/ThemesSupport/subsystems/win32/win32k/ntuser/msgqueue.c [iso-8859-1] Mon Aug 8 13:31:33 2011 @@ -1025,6 +1025,58 @@ } }
+BOOL FASTCALL +co_MsqSendMessageAsync(PTHREADINFO ptiReceiver, + HWND hwnd, + UINT Msg, + WPARAM wParam, + LPARAM lParam, + SENDASYNCPROC CompletionCallback, + ULONG_PTR CompletionCallbackContext, + BOOL HasPackedLParam, + INT HookMessage) +{ + + PTHREADINFO ptiSender; + PUSER_SENT_MESSAGE Message; + + if(!(Message = ExAllocatePoolWithTag(NonPagedPool, sizeof(USER_SENT_MESSAGE), TAG_USRMSG))) + { + DPRINT1("MsqSendMessage(): Not enough memory to allocate a message"); + return FALSE; + } + + ptiSender = PsGetCurrentThreadWin32Thread(); + + IntReferenceMessageQueue(ptiReceiver->MessageQueue); + /* Take reference on this MessageQueue if its a callback. It will be released + when message is processed or removed from target hwnd MessageQueue */ + if (CompletionCallback) + IntReferenceMessageQueue(ptiSender->MessageQueue); + + Message->Msg.hwnd = hwnd; + Message->Msg.message = Msg; + Message->Msg.wParam = wParam; + Message->Msg.lParam = lParam; + Message->CompletionEvent = NULL; + Message->Result = 0; + Message->lResult = 0; + Message->SenderQueue = NULL; + Message->CallBackSenderQueue = ptiSender->MessageQueue; + Message->DispatchingListEntry.Flink = NULL; + Message->CompletionCallback = CompletionCallback; + Message->CompletionCallbackContext = CompletionCallbackContext; + Message->HookMessage = HookMessage; + Message->HasPackedLParam = HasPackedLParam; + Message->QS_Flags = QS_SENDMESSAGE; + + InsertTailList(&ptiReceiver->MessageQueue->SentMessagesListHead, &Message->ListEntry); + MsqWakeQueue(ptiReceiver->MessageQueue, QS_SENDMESSAGE, TRUE); + IntDereferenceMessageQueue(ptiReceiver->MessageQueue); + + return TRUE; +} + NTSTATUS FASTCALL co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam,