Author: jimtabor
Date: Sat May 11 19:33:40 2013
New Revision: 59000
URL:
http://svn.reactos.org/svn/reactos?rev=59000&view=rev
Log:
[Win32k]
- Thread ID to Thread Information.
Modified:
trunk/reactos/win32ss/user/ntuser/hook.c
trunk/reactos/win32ss/user/ntuser/misc.c
trunk/reactos/win32ss/user/ntuser/ntstubs.c
trunk/reactos/win32ss/user/ntuser/userfuncs.h
Modified: trunk/reactos/win32ss/user/ntuser/hook.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/hook.c…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/hook.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/hook.c [iso-8859-1] Sat May 11 19:33:40 2013
@@ -1456,7 +1456,6 @@
UNICODE_STRING ModuleName;
NTSTATUS Status;
HHOOK Handle;
- PETHREAD Thread = NULL;
PTHREADINFO pti, ptiHook = NULL;
DECLARE_RETURN(HHOOK);
@@ -1491,14 +1490,12 @@
RETURN( NULL);
}
- if (!NT_SUCCESS(PsLookupThreadByThreadId((HANDLE)(DWORD_PTR) ThreadId,
&Thread)))
+ if ( !(ptiHook = IntTID2PTI( (HANDLE)ThreadId )))
{
ERR("Invalid thread id 0x%x\n", ThreadId);
EngSetLastError(ERROR_INVALID_PARAMETER);
RETURN( NULL);
}
-
- ptiHook = Thread->Tcb.Win32Thread;
if ( ptiHook->rpdesk != pti->rpdesk) // gptiCurrent->rpdesk)
{
@@ -1507,7 +1504,7 @@
RETURN( NULL);
}
- if (Thread->ThreadsProcess != PsGetCurrentProcess())
+ if (ptiHook->ppi != pti->ppi)
{
if ( !Mod &&
(HookId == WH_GETMESSAGE ||
@@ -1674,6 +1671,9 @@
}
Hook->ModuleName.Length = ModuleName.Length;
+ //// FIXME: Need to load from user32 to verify hMod before calling hook with hMod
set!!!!
+ //// Mod + offPfn == new HookProc Justin Case module is from another process.
+ FIXME("NtUserSetWindowsHookEx Setting process hMod instance
addressing.\n");
/* Make proc relative to the module base */
Hook->offPfn = (ULONG_PTR)((char *)HookProc - (char *)Mod);
}
@@ -1685,7 +1685,6 @@
CLEANUP:
TRACE("Leave NtUserSetWindowsHookEx, ret=%i\n",_ret_);
- if (Thread) ObDereferenceObject(Thread);
UserLeave();
END_CLEANUP;
}
Modified: trunk/reactos/win32ss/user/ntuser/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/misc.c…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/misc.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/misc.c [iso-8859-1] Sat May 11 19:33:40 2013
@@ -2,12 +2,54 @@
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Win32k subsystem
* PURPOSE: Miscellaneous User functions
- * FILE: subsystems/win32/win32k/ntuser/misc.c
+ * FILE: win32ss/user/ntuser/misc.c
* PROGRAMER: Ge van Geldorp (ge(a)gse.nl)
*/
#include <win32k.h>
DBG_DEFAULT_CHANNEL(UserMisc);
+
+/*
+ * Test the Thread to verify and validate it. Hard to the core tests are required.
+ */
+PTHREADINFO
+FASTCALL
+IntTID2PTI(HANDLE id)
+{
+ NTSTATUS Status;
+ PETHREAD Thread;
+ PTHREADINFO pti;
+ Status = PsLookupThreadByThreadId(id, &Thread);
+ if (!NT_SUCCESS(Status))
+ {
+ return NULL;
+ }
+ if (PsIsThreadTerminating(Thread))
+ {
+ ObDereferenceObject(Thread);
+ return NULL;
+ }
+ pti = PsGetThreadWin32Thread(Thread);
+ if (!pti)
+ {
+ ObDereferenceObject(Thread);
+ return NULL;
+ }
+ // Validate and verify!
+ _SEH2_TRY
+ {
+ if (pti->TIF_flags & TIF_INCLEANUP) pti = NULL;
+ if (pti && !(pti->TIF_flags & TIF_GUITHREADINITIALIZED)) pti =
NULL;
+ if (PsGetThreadId(Thread) != id) pti = NULL;
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ pti = NULL;
+ }
+ _SEH2_END
+ ObDereferenceObject(Thread);
+ return pti;
+}
SHORT
FASTCALL
Modified: trunk/reactos/win32ss/user/ntuser/ntstubs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/ntstub…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/ntstubs.c [iso-8859-1] Sat May 11 19:33:40 2013
@@ -29,30 +29,21 @@
IN BOOL fAttach)
{
NTSTATUS Status;
- PETHREAD Thread, ThreadTo;
PTHREADINFO pti, ptiTo;
BOOL Ret = FALSE;
UserEnterExclusive();
ERR("Enter NtUserAttachThreadInput %s\n",(fAttach ? "TRUE" :
"FALSE" ));
- Status = PsLookupThreadByThreadId((HANDLE)idAttach, &Thread);
- if (!NT_SUCCESS(Status))
+
+ pti = IntTID2PTI((HANDLE)idAttach);
+ ptiTo = IntTID2PTI((HANDLE)idAttachTo);
+
+ if ( !pti || !ptiTo )
{
+ ERR("AttachThreadInput pti or ptiTo NULL.\n");
EngSetLastError(ERROR_INVALID_PARAMETER);
goto Exit;
}
- Status = PsLookupThreadByThreadId((HANDLE)idAttachTo, &ThreadTo);
- if (!NT_SUCCESS(Status))
- {
- EngSetLastError(ERROR_INVALID_PARAMETER);
- ObDereferenceObject(Thread);
- goto Exit;
- }
-
- pti = PsGetThreadWin32Thread(Thread);
- ptiTo = PsGetThreadWin32Thread(ThreadTo);
- ObDereferenceObject(Thread);
- ObDereferenceObject(ThreadTo);
Status = UserAttachThreadInput( pti, ptiTo, fAttach);
if (!NT_SUCCESS(Status))
Modified: trunk/reactos/win32ss/user/ntuser/userfuncs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/userfu…
==============================================================================
--- trunk/reactos/win32ss/user/ntuser/userfuncs.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/user/ntuser/userfuncs.h [iso-8859-1] Sat May 11 19:33:40 2013
@@ -87,6 +87,7 @@
VOID FASTCALL IntSetWindowState(PWND, UINT);
VOID FASTCALL IntClearWindowState(PWND, UINT);
+PTHREADINFO FASTCALL IntTID2PTI(HANDLE);
/*************** MESSAGE.C ***************/