Author: gadamopoulos Date: Thu Oct 28 17:14:29 2010 New Revision: 49331
URL: http://svn.reactos.org/svn/reactos?rev=49331&view=rev Log: [win32k] message.c: - Don't use RETURN macro - Correctly use SEH. Use _SEH2_YIELD
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/message.c
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/message.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntu... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/message.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/message.c [iso-8859-1] Thu Oct 28 17:14:29 2010 @@ -1868,9 +1868,6 @@ PTHREADINFO pti; PUSER_MESSAGE_QUEUE Queue; DWORD Result; - DECLARE_RETURN(DWORD); - - DPRINT("Enter IntGetQueueStatus\n");
pti = PsGetCurrentThreadWin32Thread(); Queue = pti->MessageQueue; @@ -1881,19 +1878,17 @@ Queue->ChangedBits = 0; }
- RETURN(Result); - -CLEANUP: - DPRINT("Leave IntGetQueueStatus, ret=%i\n",_ret_); - END_CLEANUP; + return Result; }
BOOL APIENTRY IntInitMessagePumpHook() { - if (((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->pcti) - { - ((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->pcti->dwcPumpHook++; + PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); + + if (pti->pcti) + { + pti->pcti->dwcPumpHook++; return TRUE; } return FALSE; @@ -1902,13 +1897,15 @@ BOOL APIENTRY IntUninitMessagePumpHook() { - if (((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->pcti) - { - if (((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->pcti->dwcPumpHook <= 0) + PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); + + if (pti->pcti) + { + if (pti->pcti->dwcPumpHook <= 0) { return FALSE; } - ((PTHREADINFO)PsGetCurrentThread()->Tcb.Win32Thread)->pcti->dwcPumpHook--; + pti->pcti->dwcPumpHook--; return TRUE; } return FALSE; @@ -1922,17 +1919,15 @@ WPARAM wParam, LPARAM lParam) { - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserPostMessage\n"); + BOOL ret; + UserEnterExclusive();
- RETURN( UserPostMessage(hWnd, Msg, wParam, lParam)); - -CLEANUP: - DPRINT("Leave NtUserPostMessage, ret=%i\n",_ret_); + ret = UserPostMessage(hWnd, Msg, wParam, lParam); + UserLeave(); - END_CLEANUP; + + return ret; }
BOOL APIENTRY @@ -1941,20 +1936,15 @@ WPARAM wParam, LPARAM lParam) { - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserPostThreadMessage\n"); + BOOL ret; + UserEnterExclusive();
- RETURN( UserPostThreadMessage( idThread, - Msg, - wParam, - lParam)); - -CLEANUP: - DPRINT("Leave NtUserPostThreadMessage, ret=%i\n",_ret_); + ret = UserPostThreadMessage( idThread, Msg, wParam, lParam); + UserLeave(); - END_CLEANUP; + + return ret; }
DWORD APIENTRY @@ -1979,31 +1969,34 @@ { DOSENDMESSAGE dsm; LRESULT Result; - DECLARE_RETURN(BOOL);
DPRINT("Enter NtUserSendMessageTimeout\n"); - UserEnterExclusive();
dsm.uFlags = uFlags; dsm.uTimeout = uTimeout; + + UserEnterExclusive(); + Result = co_IntDoSendMessage(hWnd, Msg, wParam, lParam, &dsm, UnsafeInfo); + + UserLeave(); + if(uResult != NULL && Result != 0) { - NTSTATUS Status; - - Status = MmCopyToCaller(uResult, &dsm.Result, sizeof(ULONG_PTR)); - if(!NT_SUCCESS(Status)) - { - SetLastWin32Error(ERROR_INVALID_PARAMETER); - RETURN( FALSE); - } - } - RETURN( Result); - -CLEANUP: - DPRINT("Leave NtUserSendMessageTimeout, ret=%i\n",_ret_); - UserLeave(); - END_CLEANUP; + _SEH2_TRY + { + ProbeForWrite(uResult, sizeof(ULONG_PTR), 1); + RtlCopyMemory(uResult, &dsm.Result, sizeof(ULONG_PTR)); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER);; + Result = FALSE; + } + _SEH2_END; + } + + return Result; }
LRESULT APIENTRY @@ -2013,34 +2006,30 @@ LPARAM lParam, PNTUSERSENDMESSAGEINFO UnsafeInfo ) { - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserSendMessage\n"); + BOOL ret; + UserEnterExclusive();
- RETURN(co_IntDoSendMessage(Wnd, Msg, wParam, lParam, NULL, UnsafeInfo)); - -CLEANUP: - DPRINT("Leave NtUserSendMessage, ret=%i\n",_ret_); + ret = co_IntDoSendMessage(Wnd, Msg, wParam, lParam, NULL, UnsafeInfo); + UserLeave(); - END_CLEANUP; + + return ret; } //////////
BOOL APIENTRY NtUserWaitMessage(VOID) { - DECLARE_RETURN(BOOL); - - DPRINT("EnterNtUserWaitMessage\n"); + BOOL ret; + UserEnterExclusive();
- RETURN(co_IntWaitMessage(NULL, 0, 0)); - -CLEANUP: - DPRINT("Leave NtUserWaitMessage, ret=%i\n",_ret_); + ret = co_IntWaitMessage(NULL, 0, 0); + UserLeave(); - END_CLEANUP; + + return ret; }
@@ -2067,10 +2056,8 @@ PWND Window = NULL; PMSGMEMORY MsgMemoryEntry; PVOID UserMem; - UINT Size; + ULONG Size; USER_MESSAGE Msg; - DECLARE_RETURN(BOOL); - // USER_REFERENCE_ENTRY Ref;
DPRINT("Enter NtUserGetMessage\n"); UserEnterExclusive(); @@ -2078,7 +2065,8 @@ /* Validate input */ if (hWnd && !(Window = UserGetWindowObject(hWnd))) { - RETURN(-1); + UserLeave(); + return -1; }
// if (Window) UserRefObjectCo(Window, &Ref); @@ -2092,65 +2080,71 @@ do { GotMessage = co_IntPeekMessage(&Msg, Window, MsgFilterMin, MsgFilterMax, PM_REMOVE); - if (GotMessage) - { - Info.Msg = Msg.Msg; - /* See if this message type is present in the table */ - MsgMemoryEntry = FindMsgMemory(Info.Msg.message); - if (NULL == MsgMemoryEntry) - { - /* Not present, no copying needed */ - Info.LParamSize = 0; - } - else - { - /* Determine required size */ - Size = MsgMemorySize(MsgMemoryEntry, Info.Msg.wParam, - Info.Msg.lParam); - /* Allocate required amount of user-mode memory */ - Info.LParamSize = Size; - UserMem = NULL; - Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem, 0, - &Info.LParamSize, MEM_COMMIT, PAGE_READWRITE); - - if (! NT_SUCCESS(Status)) - { - SetLastNtError(Status); - RETURN( (BOOL) -1); - } - /* Transfer lParam data to user-mode mem */ - Status = MmCopyToCaller(UserMem, (PVOID) Info.Msg.lParam, Size); - if (! NT_SUCCESS(Status)) - { - ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID *) &UserMem, - &Info.LParamSize, MEM_DECOMMIT); - SetLastNtError(Status); - RETURN( (BOOL) -1); - } - Info.Msg.lParam = (LPARAM) UserMem; - } - Status = MmCopyToCaller(UnsafeInfo, &Info, sizeof(NTUSERGETMESSAGEINFO)); + + if (!GotMessage && !co_IntWaitMessage(Window, MsgFilterMin, MsgFilterMax)) + { + UserLeave(); + return -1; + } + } + while (! GotMessage); + + UserLeave(); + + Info.Msg = Msg.Msg; + /* See if this message type is present in the table */ + MsgMemoryEntry = FindMsgMemory(Info.Msg.message); + + _SEH2_TRY + { + ProbeForWrite(UnsafeInfo, sizeof(NTUSERGETMESSAGEINFO), 1); + RtlCopyMemory(UnsafeInfo, &Info, sizeof(NTUSERGETMESSAGEINFO)); + + if (NULL == MsgMemoryEntry) + { + /* Not present, no copying needed */ + Info.LParamSize = 0; + } + else + { + /* Determine required size */ + Size = MsgMemorySize(MsgMemoryEntry, Info.Msg.wParam, Info.Msg.lParam); + + /* Allocate required amount of user-mode memory */ + Status = ZwAllocateVirtualMemory(NtCurrentProcess(), + &UserMem, + 0, + &Size, + MEM_COMMIT, + PAGE_READWRITE); if (! NT_SUCCESS(Status)) { SetLastNtError(Status); - RETURN( (BOOL) -1); - } - } - else if (! co_IntWaitMessage(Window, MsgFilterMin, MsgFilterMax)) - { - RETURN( (BOOL) -1); - } - } - while (! GotMessage); - - RETURN( WM_QUIT != Info.Msg.message); - -CLEANUP: - // if (Window) UserDerefObjectCo(Window); - - DPRINT("Leave NtUserGetMessage\n"); - UserLeave(); - END_CLEANUP; + _SEH2_YIELD(return (BOOL) -1); + } + + /* Transfer lParam data to user-mode mem */ + ProbeForWrite(UserMem, Size, 1); + RtlCopyMemory(UserMem, (PVOID)Info.Msg.lParam, Size); + + Info.LParamSize = Size; + Info.Msg.lParam = (LPARAM) UserMem; + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + + if(UserMem != NULL) + { + ZwFreeVirtualMemory(NtCurrentProcess(), &UserMem, &Size, MEM_RELEASE); + } + + _SEH2_YIELD(return (BOOL) -1); + } + _SEH2_END; + + return (Info.Msg.message != WM_QUIT ); }
@@ -2161,21 +2155,21 @@ UINT MsgFilterMax) { MSG Msg; - BOOL Ret = FALSE; - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserGetMessage\n"); + BOOL Ret; + + if ( (MsgFilterMin|MsgFilterMax) & ~WM_MAXIMUM ) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + return FALSE; + } + + RtlZeroMemory(&Msg, sizeof(MSG)); + UserEnterExclusive();
- if ( (MsgFilterMin|MsgFilterMax) & ~WM_MAXIMUM ) - { - SetLastWin32Error(ERROR_INVALID_PARAMETER); - RETURN( Ret); - } - - RtlZeroMemory(&Msg, sizeof(MSG)); - Ret = co_IntGetPeekMessage(&Msg, hWnd, MsgFilterMin, MsgFilterMax, PM_REMOVE, TRUE); + + UserLeave();
if (Ret) { @@ -2191,12 +2185,8 @@ } _SEH2_END; } - RETURN( Ret); - -CLEANUP: - DPRINT("Leave NtUserGetMessage\n"); - UserLeave(); - END_CLEANUP; + + return Ret; }
BOOL APIENTRY @@ -2207,16 +2197,14 @@ UINT RemoveMsg) { NTSTATUS Status; - BOOL Present; + BOOL Ret; NTUSERGETMESSAGEINFO Info; PWND Window; PMSGMEMORY MsgMemoryEntry; - PVOID UserMem; - UINT Size; + PVOID UserMem = NULL; + ULONG Size; USER_MESSAGE Msg; - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserPeekMessage\n"); + UserEnterExclusive();
if (hWnd == (HWND)-1 || hWnd == (HWND)0x0000FFFF || hWnd == (HWND)0xFFFFFFFF) @@ -2227,7 +2215,8 @@ { if (!(Window = UserGetWindowObject(hWnd))) { - RETURN(-1); + UserLeave(); + return -1; } } else @@ -2241,58 +2230,66 @@ MsgFilterMax = 0; }
- Present = co_IntPeekMessage(&Msg, Window, MsgFilterMin, MsgFilterMax, RemoveMsg); - if (Present) - { - + Ret = co_IntPeekMessage(&Msg, Window, MsgFilterMin, MsgFilterMax, RemoveMsg); + + UserLeave(); + + if (Ret) + { Info.Msg = Msg.Msg; /* See if this message type is present in the table */ MsgMemoryEntry = FindMsgMemory(Info.Msg.message); - if (NULL == MsgMemoryEntry) - { - /* Not present, no copying needed */ - Info.LParamSize = 0; - } - else - { - /* Determine required size */ - Size = MsgMemorySize(MsgMemoryEntry, Info.Msg.wParam, - Info.Msg.lParam); - /* Allocate required amount of user-mode memory */ - Info.LParamSize = Size; - UserMem = NULL; - Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &UserMem, 0, - &Info.LParamSize, MEM_COMMIT, PAGE_READWRITE); - if (! NT_SUCCESS(Status)) - { - SetLastNtError(Status); - RETURN( (BOOL) -1); - } - /* Transfer lParam data to user-mode mem */ - Status = MmCopyToCaller(UserMem, (PVOID) Info.Msg.lParam, Size); - if (! NT_SUCCESS(Status)) - { - ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID *) &UserMem, - &Info.LParamSize, MEM_RELEASE); - SetLastNtError(Status); - RETURN( (BOOL) -1); - } - Info.Msg.lParam = (LPARAM) UserMem; - } - Status = MmCopyToCaller(UnsafeInfo, &Info, sizeof(NTUSERGETMESSAGEINFO)); - if (! NT_SUCCESS(Status)) - { - SetLastNtError(Status); - RETURN( (BOOL) -1); - } - } - - RETURN( Present); - -CLEANUP: - DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_); - UserLeave(); - END_CLEANUP; + + _SEH2_TRY + { + ProbeForWrite(UnsafeInfo, sizeof(NTUSERGETMESSAGEINFO), 1); + RtlCopyMemory(UnsafeInfo, &Info, sizeof(NTUSERGETMESSAGEINFO)); + + if (NULL == MsgMemoryEntry) + { + /* Not present, no copying needed */ + Info.LParamSize = 0; + } + else + { + /* Determine required size */ + Size = MsgMemorySize(MsgMemoryEntry, Info.Msg.wParam, Info.Msg.lParam); + + /* Allocate required amount of user-mode memory */ + Status = ZwAllocateVirtualMemory(NtCurrentProcess(), + &UserMem, + 0, + &Size, + MEM_COMMIT, + PAGE_READWRITE); + if (! NT_SUCCESS(Status)) + { + SetLastNtError(Status); + _SEH2_YIELD(return (BOOL) -1); + } + + /* Transfer lParam data to user-mode mem */ + ProbeForWrite(UserMem, Size, 1); + RtlCopyMemory(UserMem, (PVOID)Info.Msg.lParam, Size); + + Info.LParamSize = Size; + Info.Msg.lParam = (LPARAM) UserMem; + } + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + Ret = (BOOL) -1; + + if(UserMem != NULL) + { + ZwFreeVirtualMemory(NtCurrentProcess(), &UserMem, &Size, MEM_RELEASE); + } + } + _SEH2_END; + } + + return Ret; }
BOOL APIENTRY @@ -2303,21 +2300,21 @@ UINT RemoveMsg) { MSG Msg; - BOOL Ret = FALSE; - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserPeekMessage\n"); + BOOL Ret; + + if ( RemoveMsg & PM_BADMSGFLAGS ) + { + SetLastWin32Error(ERROR_INVALID_FLAGS); + return FALSE; + } + + RtlZeroMemory(&Msg, sizeof(MSG)); + UserEnterExclusive();
- if ( RemoveMsg & PM_BADMSGFLAGS ) - { - SetLastWin32Error(ERROR_INVALID_FLAGS); - RETURN( Ret); - } - - RtlZeroMemory(&Msg, sizeof(MSG)); - Ret = co_IntGetPeekMessage(&Msg, hWnd, MsgFilterMin, MsgFilterMax, RemoveMsg, FALSE); + + UserLeave();
if (Ret) { @@ -2333,49 +2330,39 @@ } _SEH2_END; } - RETURN( Ret); - -CLEANUP: - DPRINT("Leave NtUserPeekMessage, ret=%i\n",_ret_); - UserLeave(); - END_CLEANUP; + + return Ret; }
BOOL APIENTRY NtUserCallMsgFilter( LPMSG lpmsg, INT code) { - BOOL BadChk = FALSE, Ret = FALSE; + BOOL Ret = FALSE; MSG Msg; - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserCallMsgFilter\n"); + + _SEH2_TRY + { + ProbeForRead(lpmsg, sizeof(MSG), 1); + RtlCopyMemory( &Msg, lpmsg, sizeof(MSG)); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + UserEnterExclusive(); - if (lpmsg) - { - _SEH2_TRY - { - ProbeForRead(lpmsg, sizeof(MSG), 1); - RtlCopyMemory( &Msg, lpmsg, sizeof(MSG)); - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - BadChk = TRUE; - } - _SEH2_END; + + if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)&Msg)) + { + Ret = TRUE; } else - RETURN( FALSE); - - if (BadChk) RETURN( FALSE); - - if ( co_HOOK_CallHooks( WH_SYSMSGFILTER, code, 0, (LPARAM)&Msg)) - { - Ret = TRUE; - } - else { Ret = co_HOOK_CallHooks( WH_MSGFILTER, code, 0, (LPARAM)&Msg); } + + UserLeave();
_SEH2_TRY { @@ -2384,26 +2371,19 @@ } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - BadChk = TRUE; + Ret = FALSE; } _SEH2_END; - if (BadChk) RETURN( FALSE); - RETURN( Ret) - -CLEANUP: - DPRINT("Leave NtUserCallMsgFilter. ret=%i\n", _ret_); - UserLeave(); - END_CLEANUP; + + return Ret; }
LRESULT APIENTRY NtUserDispatchMessage(PMSG UnsafeMsgInfo) { LRESULT Res = 0; - BOOL Hit = FALSE; MSG SafeMsg;
- UserEnterExclusive(); _SEH2_TRY { ProbeForRead(UnsafeMsgInfo, sizeof(MSG), 1); @@ -2412,11 +2392,13 @@ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { SetLastNtError(_SEH2_GetExceptionCode()); - Hit = TRUE; + _SEH2_YIELD(return FALSE); } _SEH2_END;
- if (!Hit) Res = IntDispatchMessage(&SafeMsg); + UserEnterExclusive(); + + Res = IntDispatchMessage(&SafeMsg);
UserLeave(); return Res; @@ -2426,26 +2408,28 @@ BOOL APIENTRY NtUserTranslateMessage(LPMSG lpMsg, UINT flags) { - NTSTATUS Status; MSG SafeMsg; - DECLARE_RETURN(BOOL); - - DPRINT("Enter NtUserTranslateMessage\n"); + BOOL Ret; + + _SEH2_TRY + { + ProbeForRead(lpMsg, sizeof(MSG), 1); + RtlCopyMemory(&SafeMsg, lpMsg, sizeof(MSG)); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + SetLastNtError(_SEH2_GetExceptionCode()); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + UserEnterExclusive();
- Status = MmCopyFromCaller(&SafeMsg, lpMsg, sizeof(MSG)); - if(!NT_SUCCESS(Status)) - { - SetLastNtError(Status); - RETURN( FALSE); - } - - RETURN( IntTranslateKbdMessage(&SafeMsg, flags)); - -CLEANUP: - DPRINT("Leave NtUserTranslateMessage: ret=%i\n",_ret_); + Ret = IntTranslateKbdMessage(&SafeMsg, flags); + UserLeave(); - END_CLEANUP; + + return Ret; }
BOOL APIENTRY @@ -2459,7 +2443,6 @@ { LRESULT lResult = 0; BOOL Ret = FALSE; - BOOL BadChk = FALSE; PWND Window = NULL; USER_REFERENCE_ENTRY Ref;
@@ -2501,10 +2484,10 @@ } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - BadChk = TRUE; + Ret = FALSE; + _SEH2_YIELD(break); } _SEH2_END; - if (BadChk) break; } else break; @@ -2531,7 +2514,7 @@ { co_IntSendMessageTimeout( HWND_BROADCAST, Msg, - wParam, + wParam, lParam, SMTO_NOTIMEOUTIFNOTHUNG, 2000, @@ -2657,7 +2640,7 @@ } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - BadChk = TRUE; + Ret = FALSE; } _SEH2_END; } @@ -2668,7 +2651,7 @@
UserLeave();
- return BadChk ? FALSE : Ret; + return Ret; }
#define INFINITE 0xFFFFFFFF