*/
#include <win32k.h>
+
+#include <dde.h>
+
DBG_DEFAULT_CHANNEL(UserMsg);
#define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
{ WM_SETTEXT, MMS_SIZE_LPARAMSZ, MMS_FLAG_READ },
{ WM_STYLECHANGED, sizeof(STYLESTRUCT), MMS_FLAG_READ },
{ WM_STYLECHANGING, sizeof(STYLESTRUCT), MMS_FLAG_READWRITE },
- { WM_SETTINGCHANGE, MMS_SIZE_LPARAMSZ, MMS_FLAG_READWRITE },
+ { WM_SETTINGCHANGE, MMS_SIZE_LPARAMSZ, MMS_FLAG_READ },
{ WM_COPYDATA, MMS_SIZE_SPECIAL, MMS_FLAG_READ },
{ WM_COPYGLOBALDATA, MMS_SIZE_WPARAM, MMS_FLAG_READ },
- { WM_WINDOWPOSCHANGED, sizeof(WINDOWPOS), MMS_FLAG_READ },
+ { WM_WINDOWPOSCHANGED, sizeof(WINDOWPOS), MMS_FLAG_READWRITE },
{ WM_WINDOWPOSCHANGING, sizeof(WINDOWPOS), MMS_FLAG_READWRITE },
+ { WM_SIZING, sizeof(RECT), MMS_FLAG_READWRITE },
+ { WM_MOVING, sizeof(RECT), MMS_FLAG_READWRITE },
};
static PMSGMEMORY FASTCALL
}
else if (MMS_SIZE_LPARAMSZ == MsgMemoryEntry->Size)
{
- Size = (UINT) ((wcslen((PWSTR) lParam) + 1) * sizeof(WCHAR));
+ // WM_SETTEXT and WM_SETTINGCHANGE can be null!
+ if (!lParam)
+ {
+ TRACE("lParam is NULL!\n");
+ Size = 0;
+ }
+ else
+ Size = (UINT) ((wcslen((PWSTR) lParam) + 1) * sizeof(WCHAR));
}
else if (MMS_SIZE_SPECIAL == MsgMemoryEntry->Size)
{
MsgMemoryEntry = FindMsgMemory(Msg);
- if ((!MsgMemoryEntry) || (MsgMemoryEntry->Size < 0))
+ if (!MsgMemoryEntry)
{
/* Keep previous behavior */
return STATUS_SUCCESS;
PMSGMEMORY MsgMemoryEntry;
MsgMemoryEntry = FindMsgMemory(Msg);
ASSERT(MsgMemoryEntry);
- if (MsgMemoryEntry->Size < 0)
- {
- /* Keep previous behavior */
- return STATUS_INVALID_PARAMETER;
- }
if (MsgMemoryEntry->Flags == MMS_FLAG_READWRITE)
{
/* Copy data if required */
if (0 != (MsgMemoryEntry->Flags & MMS_FLAG_READ))
{
+ TRACE("Copy Message %d from usermode buffer\n", KernelModeMsg->message);
Status = MmCopyFromCaller(KernelMem, (PVOID) UserModeMsg->lParam, Size);
if (! NT_SUCCESS(Status))
{
- ERR("Failed to copy message to kernel: invalid usermode buffer\n");
+ ERR("Failed to copy message to kernel: invalid usermode lParam buffer\n");
ExFreePoolWithTag(KernelMem, TAG_MSG);
return Status;
}
Status = MmCopyToCaller((PVOID) UserModeMsg->lParam, (PVOID) KernelModeMsg->lParam, Size);
if (! NT_SUCCESS(Status))
{
- ERR("Failed to copy message from kernel: invalid usermode buffer\n");
+ ERR("Failed to copy message from kernel: invalid usermode lParam buffer\n");
ExFreePool((PVOID) KernelModeMsg->lParam);
return Status;
}
LRESULT retval = 0;
PTHREADINFO pti;
PWND Window = NULL;
- HRGN hrgn;
BOOL DoCallBack = TRUE;
if (pMsg->hwnd)
WM_TIMER,
pMsg->wParam,
(LPARAM)Time,
- 0);
+ -1);
}
return retval;
}
pMsg->message,
pMsg->wParam,
pMsg->lParam,
- 0);
+ -1);
if (pMsg->message == WM_PAINT)
{
+ PREGION Rgn;
Window->state2 &= ~WNDS2_WMPAINTSENT;
/* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
- hrgn = IntSysCreateRectRgn( 0, 0, 0, 0 );
- co_UserGetUpdateRgn( Window, hrgn, TRUE );
- GreDeleteObject(hrgn);
+ Rgn = IntSysCreateRectpRgn( 0, 0, 0, 0 );
+ co_UserGetUpdateRgn( Window, Rgn, TRUE );
+ REGION_Delete(Rgn);
}
return retval;
}
/* Check for hardware events. */
- if ((ProcessMask & QS_MOUSE) &&
- co_MsqPeekMouseMove( pti,
- RemoveMessages,
- Window,
- MsgFilterMin,
- MsgFilterMax,
- Msg ))
- {
- return TRUE;
- }
-
if ((ProcessMask & QS_INPUT) &&
co_MsqPeekHardwareMessage( pti,
RemoveMessages,
return TRUE;
}
+ if ((ProcessMask & QS_MOUSE) &&
+ co_MsqPeekMouseMove( pti,
+ RemoveMessages,
+ Window,
+ MsgFilterMin,
+ MsgFilterMax,
+ Msg ))
+ {
+ return TRUE;
+ }
+
/* Check for sent messages again. */
while ( co_MsqDispatchOneSentMessage(pti) )
{
{
if ( ptiCur )
{
- if ( Window->head.pti->MessageQueue == ptiCur->MessageQueue )
+ if (!Window ||
+ Window->head.pti->MessageQueue == ptiCur->MessageQueue )
{
return NULL;
}
}
- return Window->head.pti;
+ return Window ? Window->head.pti : NULL;
}
BOOL FASTCALL
Window = UserGetWindowObject(Wnd);
if ( !Window )
{
- ERR("UserPostMessage: Invalid handle 0x%p!\n",Wnd);
+ ERR("UserPostMessage: Invalid handle 0x%p Msg %d!\n",Wnd,Msg);
return FALSE;
}
else
{
lParamBufferSize = MsgMemorySize(MsgMemoryEntry, wParam, lParam);
+ // If zero, do not allow callback on client side to allocate a buffer!!!!! See CORE-7695.
+ if (!lParamBufferSize) lParamBufferSize = -1;
}
if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, FALSE)))
RETURN( TRUE);
}
- if (uFlags & SMTO_ABORTIFHUNG && MsqIsHung(ptiSendTo/*Window->head.pti*/))
+ if (uFlags & SMTO_ABORTIFHUNG && MsqIsHung(ptiSendTo))
{
// FIXME: Set window hung and add to a list.
/* FIXME: Set a LastError? */
do
{
- Status = co_MsqSendMessage( ptiSendTo, //Window->head.pti,
+ Status = co_MsqSendMessage( ptiSendTo,
hWnd,
Msg,
wParam,
}
while ((STATUS_TIMEOUT == Status) &&
(uFlags & SMTO_NOTIMEOUTIFNOTHUNG) &&
- !MsqIsHung(ptiSendTo/*Window->head.pti*/)); // FIXME: Set window hung and add to a list.
+ !MsqIsHung(ptiSendTo)); // FIXME: Set window hung and add to a list.
if (STATUS_TIMEOUT == Status)
{
{
RETURN(FALSE);
}
-
+
ptiSendTo = IntSendTo(Window, Win32Thread, Msg);
if (Msg & 0x80000000 &&
else
{
lParamBufferSize = MsgMemorySize(MsgMemoryEntry, wParam, lParam);
+ if (!lParamBufferSize) lParamBufferSize = -1;
}
if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, !!ptiSendTo)))
Message->Result = 0;
Message->lResult = 0;
Message->QS_Flags = 0;
- Message->ptiReceiver = ptiSendTo; //Window->head.pti;
+ Message->ptiReceiver = ptiSendTo;
Message->ptiSender = NULL; // mjmartin, you are right! This is null.
Message->ptiCallBackSender = Win32Thread;
Message->DispatchingListEntry.Flink = NULL;
Message->QS_Flags = QS_SENDMESSAGE;
if (Msg & 0x80000000) // Higher priority event message!
- InsertHeadList(&ptiSendTo->SentMessagesListHead/*&Window->head.pti->SentMessagesListHead*/, &Message->ListEntry);
+ InsertHeadList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry);
else
- InsertTailList(&ptiSendTo->SentMessagesListHead/*&Window->head.pti->SentMessagesListHead*/, &Message->ListEntry);
- MsqWakeQueue(ptiSendTo/*Window->head.pti*/, QS_SENDMESSAGE, TRUE);
+ InsertTailList(&ptiSendTo->SentMessagesListHead, &Message->ListEntry);
+ MsqWakeQueue(ptiSendTo, QS_SENDMESSAGE, TRUE);
RETURN(TRUE);
return (LRESULT)Result;
}
-LRESULT FASTCALL
+static LRESULT FASTCALL
co_IntDoSendMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam,
PDOSENDMESSAGE dsm)
{
- //PTHREADINFO pti;
LRESULT Result = TRUE;
NTSTATUS Status;
PWND Window = NULL;
- MSG UserModeMsg;
- MSG KernelModeMsg;
+ MSG UserModeMsg, KernelModeMsg;
PMSGMEMORY MsgMemoryEntry;
+ PTHREADINFO ptiSendTo;
if (hWnd != HWND_BROADCAST && hWnd != HWND_TOPMOST)
{
ERR("co_IntDoSendMessage Window Exiting!\n");
}
- /* See if the current thread can handle the message */
- //pti = PsGetCurrentThreadWin32Thread();
+ /* See if the current thread can handle this message */
+ ptiSendTo = IntSendTo(Window, gptiCurrent, Msg);
- UserModeMsg.hwnd = hWnd;
- UserModeMsg.message = Msg;
- UserModeMsg.wParam = wParam;
- UserModeMsg.lParam = lParam;
- MsgMemoryEntry = FindMsgMemory(UserModeMsg.message);
-
- Status = CopyMsgToKernelMem(&KernelModeMsg, &UserModeMsg, MsgMemoryEntry);
- if (! NT_SUCCESS(Status))
+ // If broadcasting or sending to another thread, save the users data.
+ if (!Window || ptiSendTo )
{
- EngSetLastError(ERROR_INVALID_PARAMETER);
- return (dsm ? 0 : -1);
+ UserModeMsg.hwnd = hWnd;
+ UserModeMsg.message = Msg;
+ UserModeMsg.wParam = wParam;
+ UserModeMsg.lParam = lParam;
+ MsgMemoryEntry = FindMsgMemory(UserModeMsg.message);
+ Status = CopyMsgToKernelMem(&KernelModeMsg, &UserModeMsg, MsgMemoryEntry);
+ if (!NT_SUCCESS(Status))
+ {
+ EngSetLastError(ERROR_INVALID_PARAMETER);
+ return (dsm ? 0 : -1);
+ }
+ }
+ else
+ {
+ KernelModeMsg.hwnd = hWnd;
+ KernelModeMsg.message = Msg;
+ KernelModeMsg.wParam = wParam;
+ KernelModeMsg.lParam = lParam;
}
if (!dsm)
&dsm->Result );
}
- Status = CopyMsgToUserMem(&UserModeMsg, &KernelModeMsg);
- if (! NT_SUCCESS(Status))
+ if (!Window || ptiSendTo )
{
- EngSetLastError(ERROR_INVALID_PARAMETER);
- return(dsm ? 0 : -1);
+ Status = CopyMsgToUserMem(&UserModeMsg, &KernelModeMsg);
+ if (!NT_SUCCESS(Status))
+ {
+ EngSetLastError(ERROR_INVALID_PARAMETER);
+ return(dsm ? 0 : -1);
+ }
}
return (LRESULT)Result;
return FALSE;
}
+BOOL FASTCALL
+IntCallMsgFilter( LPMSG lpmsg, INT code)
+{
+ BOOL Ret = FALSE;
+
+ if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)lpmsg))
+ {
+ Ret = TRUE;
+ }
+ else
+ {
+ Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)lpmsg);
+ }
+ return Ret;
+}
+
/** Functions ******************************************************************/
BOOL
WPARAM wParam,
LPARAM lParam)
{
- BOOL ret;
+ BOOL ret = FALSE;
PETHREAD peThread;
PTHREADINFO pThread;
NTSTATUS Status;
((ClientInfo->CI_flags & CI_CURTHPRHOOK) ? 1 : 0),
(LPARAM)&CWP,
Hook->Proc,
- Hook->ihmod,
+ Hook->ihmod,
Hook->offPfn,
Hook->Ansi,
&Hook->ModuleName);
((ClientInfo->CI_flags & CI_CURTHPRHOOK) ? 1 : 0),
(LPARAM)&CWPR,
Hook->Proc,
- Hook->ihmod,
+ Hook->ihmod,
Hook->offPfn,
Hook->Ansi,
&Hook->ModuleName);
Status = ObReferenceObjectByHandle(hProcess,
PROCESS_QUERY_INFORMATION,
- PsProcessType,
+ *PsProcessType,
UserMode,
(PVOID*)&Process,
NULL);
TRACE("WFII: ppi %p\n", W32Process);
TRACE("WFII: waiting for %p\n", Handles[1] );
+
+ /*
+ * We must add a refcount to our current PROCESSINFO,
+ * because anything could happen (including process death) we're leaving win32k
+ */
+ IntReferenceProcessInfo(W32Process);
+
do
{
UserLeave();
pti->pClientInfo->dwTIFlags = pti->TIF_flags;
}
W32Process->W32PF_flags &= ~W32PF_WAITFORINPUTIDLE;
+ IntDereferenceProcessInfo(W32Process);
ObDereferenceObject(Process);
UserLeave();
return Status;