Author: gadamopoulos
Date: Tue Jul 12 08:34:00 2011
New Revision: 52648
URL:
http://svn.reactos.org/svn/reactos?rev=52648&view=rev
Log:
[user32]
- Convert LOADUSERAPIHOOK macro to an inline function
- Implement ClientLoadLibrary callback from win32k
Modified:
branches/GSoC_2011/ThemesSupport/dll/win32/user32/controls/scrollbar.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/include/user32.h
branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/desktop.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/dllmain.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/usrapihk.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/defwnd.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/draw.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/hook.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/nonclient.c
branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/paint.c
branches/GSoC_2011/ThemesSupport/include/reactos/win32k/callback.h
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/controls/scrollbar.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/controls/scrollbar.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/controls/scrollbar.c [iso-8859-1]
Tue Jul 12 08:34:00 2011
@@ -1482,7 +1482,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
@@ -1534,7 +1534,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
@@ -1615,7 +1615,7 @@
BOOL Hook;
INT Ret = 0;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/include/user32.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/include/user32.h [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/include/user32.h [iso-8859-1] Tue
Jul 12 08:34:00 2011
@@ -45,6 +45,11 @@
/* SEH Support with PSEH */
#include <pseh/pseh2.h>
+extern PPROCESSINFO g_ppi;
+extern ULONG_PTR g_ulSharedDelta;
+extern PSERVERINFO gpsi;
+extern BOOL gfServerProcess;
+
#define HOOKID_TO_FLAG(HookId) (1 << ((HookId) + 1))
#define ISITHOOKED(HookId) (GetWin32ClientInfo()->fsHooks & HOOKID_TO_FLAG(HookId)
||\
(GetWin32ClientInfo()->pDeskInfo &&
GetWin32ClientInfo()->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId)))
@@ -53,29 +58,37 @@
extern RTL_CRITICAL_SECTION gcsUserApiHook;
extern USERAPIHOOK guah;
+extern HINSTANCE ghmodUserApiHook;
BOOL FASTCALL BeginIfHookedUserApiHook(VOID);
BOOL FASTCALL EndUserApiHook(VOID);
BOOL FASTCALL IsInsideUserApiHook(VOID);
VOID FASTCALL ResetUserApiHook(PUSERAPIHOOK);
BOOL FASTCALL IsMsgOverride(UINT,PUAHOWP);
+BOOL WINAPI InitUserApiHook(HINSTANCE hInstance, USERAPIHOOKPROC pfn);
+BOOL WINAPI ClearUserApiHook(HINSTANCE hInstance);
-#define LOADUSERAPIHOOK \
- if (!gfServerProcess && \
- !IsInsideUserApiHook() && \
- (gpsi->dwSRVIFlags & SRVINFO_APIHOOK) && \
- !RtlIsThreadWithinLoaderCallout()) \
- { \
- NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK); \
- } \
+static __inline void LoadUserApiHook()
+{
+ if(!(gpsi->dwSRVIFlags & SRVINFO_APIHOOK))
+ return;
+
+ if(IsInsideUserApiHook())
+ return;
+
+ /* HACK! Please remove when gfServerProcess is correct */
+#if 0
+ if(gfServerProcess)
+ return;
+#endif
+ if(RtlIsThreadWithinLoaderCallout())
+ return;
+
+ NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK);
+}
/* FIXME: Use ntgdi.h then cleanup... */
LONG WINAPI GdiGetCharDimensions(HDC, LPTEXTMETRICW, LONG *);
BOOL FASTCALL IsMetaFile(HDC);
-
-extern PPROCESSINFO g_ppi;
-extern ULONG_PTR g_ulSharedDelta;
-extern PSERVERINFO gpsi;
-extern BOOL gfServerProcess;
static __inline PVOID
SharedPtrToUser(PVOID Ptr)
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/desktop.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/desktop.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/desktop.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -113,7 +113,7 @@
return RealGetSystemMetrics(nIndex);
}
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
@@ -336,7 +336,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
@@ -368,7 +368,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/dllmain.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/dllmain.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -217,6 +217,8 @@
(PVOID)User32CallLoadMenuFromKernel;
KernelCallbackTable[USER32_CALLBACK_CLIENTTHREADSTARTUP] =
(PVOID)User32CallClientThreadSetupFromKernel;
+ KernelCallbackTable[USER32_CALLBACK_CLIENTLOADLIBRARY] =
+ (PVOID)User32CallClientLoadLibraryFromKernel;
NtUserProcessConnect( NtCurrentProcess(),
&UserCon,
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/usrapihk.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/usrapihk.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/misc/usrapihk.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -318,7 +318,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/defwnd.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/defwnd.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/defwnd.c [iso-8859-1] Tue
Jul 12 08:34:00 2011
@@ -2209,7 +2209,7 @@
BOOL Hook, msgOverride = FALSE;
LRESULT Result = 0;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
if (Hook)
@@ -2242,7 +2242,7 @@
BOOL Hook, msgOverride = FALSE;
LRESULT Result = 0;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
if (Hook)
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/draw.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/draw.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/draw.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -1457,7 +1457,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/hook.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/hook.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/hook.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -425,6 +425,111 @@
DWORD dwThreadId)
{
return IntSetWindowsHook(idHook, lpfn, hMod, dwThreadId, FALSE);
+}
+
+HINSTANCE ClientLoadLibrary(PUNICODE_STRING pstrLibName,
+ PUNICODE_STRING pstrInitFunc,
+ BOOL Unload,
+ BOOL ApiHook)
+{
+ HINSTANCE hLibrary;
+ PVOID pInitFunction;
+ NTSTATUS Status;
+ ANSI_STRING InitFuncName;
+ BOOL Result = FALSE;
+
+ /* Check if we have to load the module */
+ if(Unload == FALSE)
+ {
+ ASSERT(pstrLibName->Buffer != NULL);
+
+ /* Load it */
+ hLibrary = LoadLibrary(pstrLibName->Buffer);
+ if(hLibrary == 0)
+ {
+ return hLibrary;
+ }
+
+ if(ApiHook == FALSE)
+ {
+ /* There is nothing more to do for a global hook*/
+ return hLibrary;
+ }
+
+ /* Initialize the user api hook */
+ ASSERT(pstrInitFunc->Buffer);
+
+ Status = RtlUnicodeStringToAnsiString(&InitFuncName,
+ pstrInitFunc,
+ TRUE);
+
+ /* Get the address of the initialization routine */
+ pInitFunction = GetProcAddress(hLibrary, InitFuncName.Buffer);
+ if(pInitFunction)
+ {
+ /* Call the initialization routine */
+ Result = InitUserApiHook(hLibrary, (USERAPIHOOKPROC)pInitFunction);
+ }
+ RtlFreeAnsiString(&InitFuncName);
+
+ /* In case of error unload the library */
+ if(Result == FALSE)
+ {
+ FreeLibrary(hLibrary);
+ hLibrary = 0;
+ }
+ }
+ else
+ {
+ /* Cleanup user api hook before unloading */
+ if(ApiHook == TRUE)
+ {
+ Result = ClearUserApiHook(ghmodUserApiHook);
+ hLibrary = Result ? ghmodUserApiHook : 0;
+ }
+ else
+ {
+ hLibrary = GetModuleHandle(pstrLibName->Buffer);
+ Result = (hLibrary != 0);
+ }
+
+ if(Result == TRUE)
+ {
+ Result = FreeLibrary(hLibrary);
+ if(Result == FALSE)
+ {
+ hLibrary = 0;
+ }
+ }
+ }
+
+ return hLibrary;
+}
+
+NTSTATUS WINAPI
+User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength)
+{
+ HINSTANCE Result;
+ PCLIENT_LOAD_LIBRARY_ARGUMENTS Argument;
+
+ /* Retireve the callback parameters */
+ Argument = (PCLIENT_LOAD_LIBRARY_ARGUMENTS)Arguments;
+ if(Argument->strLibraryName.Buffer != NULL)
+ {
+ Argument->strLibraryName.Buffer =
(PWCHAR)((ULONG_PTR)Argument->strLibraryName.Buffer + (ULONG_PTR)Argument);
+ }
+ if(Argument->strInitFuncName.Buffer != NULL)
+ {
+ Argument->strInitFuncName.Buffer =
(PWCHAR)((ULONG_PTR)Argument->strInitFuncName.Buffer + (ULONG_PTR)Argument);
+ }
+
+ /* Call the implementation of the callback */
+ Result = ClientLoadLibrary(&Argument->strLibraryName,
+ &Argument->strInitFuncName,
+ Argument->Unload,
+ Argument->ApiHook);
+
+ return ZwCallbackReturn(&Result, sizeof(HINSTANCE), STATUS_SUCCESS);
}
NTSTATUS WINAPI
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/nonclient.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/nonclient.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/nonclient.c [iso-8859-1] Tue
Jul 12 08:34:00 2011
@@ -1104,7 +1104,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
@@ -1148,7 +1148,7 @@
{
BOOL Hook, Ret = FALSE;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/paint.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/win…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/paint.c [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/dll/win32/user32/windows/paint.c [iso-8859-1] Tue Jul
12 08:34:00 2011
@@ -200,7 +200,7 @@
BOOL Hook;
int Ret = 0;
- LOADUSERAPIHOOK
+ LoadUserApiHook();
Hook = BeginIfHookedUserApiHook();
Modified: branches/GSoC_2011/ThemesSupport/include/reactos/win32k/callback.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/include…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/include/reactos/win32k/callback.h [iso-8859-1]
(original)
+++ branches/GSoC_2011/ThemesSupport/include/reactos/win32k/callback.h [iso-8859-1] Tue
Jul 12 08:34:00 2011
@@ -9,7 +9,8 @@
#define USER32_CALLBACK_EVENTPROC (5)
#define USER32_CALLBACK_LOADMENU (6)
#define USER32_CALLBACK_CLIENTTHREADSTARTUP (7)
-#define USER32_CALLBACK_MAXIMUM (7)
+#define USER32_CALLBACK_CLIENTLOADLIBRARY (8)
+#define USER32_CALLBACK_MAXIMUM (8)
typedef struct _WINDOWPROC_CALLBACK_ARGUMENTS
{
@@ -76,6 +77,14 @@
WCHAR MenuName[1];
} LOADMENU_CALLBACK_ARGUMENTS, *PLOADMENU_CALLBACK_ARGUMENTS;
+typedef struct _CLIENT_LOAD_LIBRARY_ARGUMENTS
+{
+ UNICODE_STRING strLibraryName;
+ UNICODE_STRING strInitFuncName;
+ BOOL Unload;
+ BOOL ApiHook;
+} CLIENT_LOAD_LIBRARY_ARGUMENTS, *PCLIENT_LOAD_LIBRARY_ARGUMENTS;
+
NTSTATUS WINAPI
User32CallWindowProcFromKernel(PVOID Arguments, ULONG ArgumentLength);
NTSTATUS WINAPI
@@ -92,5 +101,6 @@
User32CallLoadMenuFromKernel(PVOID Arguments, ULONG ArgumentLength);
NTSTATUS WINAPI
User32CallClientThreadSetupFromKernel(PVOID Arguments, ULONG ArgumentLength);
-
+NTSTATUS WINAPI
+User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength);
#endif /* __INCLUDE_USER32_CALLBACK_H */