[user32]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 12 Jul 2011 08:34:00 +0000 (08:34 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 12 Jul 2011 08:34:00 +0000 (08:34 +0000)
- Convert LOADUSERAPIHOOK macro to an inline function
- Implement ClientLoadLibrary callback from win32k

svn path=/branches/GSoC_2011/ThemesSupport/; revision=52648

dll/win32/user32/controls/scrollbar.c
dll/win32/user32/include/user32.h
dll/win32/user32/misc/desktop.c
dll/win32/user32/misc/dllmain.c
dll/win32/user32/misc/usrapihk.c
dll/win32/user32/windows/defwnd.c
dll/win32/user32/windows/draw.c
dll/win32/user32/windows/hook.c
dll/win32/user32/windows/nonclient.c
dll/win32/user32/windows/paint.c
include/reactos/win32k/callback.h

index 5a37fa6..41f7240 100644 (file)
@@ -1482,7 +1482,7 @@ BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
@@ -1534,7 +1534,7 @@ GetScrollInfo(HWND Wnd, INT SBType, LPSCROLLINFO Info)
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
@@ -1615,7 +1615,7 @@ SetScrollInfo(HWND Wnd, int SBType, LPCSCROLLINFO Info, BOOL bRedraw)
    BOOL Hook;
    INT Ret = 0;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index f93eee6..9b94224 100644 (file)
 /* 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)))
 
 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);
+
+static __inline void LoadUserApiHook()
+{
+    if(!(gpsi->dwSRVIFlags & SRVINFO_APIHOOK))
+        return;
+
+   if(IsInsideUserApiHook())
+        return;
 
-#define LOADUSERAPIHOOK \
-   if (!gfServerProcess &&                                \
-       !IsInsideUserApiHook() &&                          \
-       (gpsi->dwSRVIFlags & SRVINFO_APIHOOK) &&           \
-       !RtlIsThreadWithinLoaderCallout())                 \
-   {                                                      \
-      NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK); \
-   }                                                      \
+   /* 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)
 {
index 1a317be..15fc95a 100644 (file)
@@ -113,7 +113,7 @@ GetSystemMetrics(int nIndex)
       return RealGetSystemMetrics(nIndex);
    }
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
@@ -336,7 +336,7 @@ SystemParametersInfoA(UINT uiAction,
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
@@ -368,7 +368,7 @@ SystemParametersInfoW(UINT uiAction,
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index b3c46ff..919cb89 100644 (file)
@@ -217,6 +217,8 @@ Init(VOID)
       (PVOID)User32CallLoadMenuFromKernel;
    KernelCallbackTable[USER32_CALLBACK_CLIENTTHREADSTARTUP] =
       (PVOID)User32CallClientThreadSetupFromKernel;
+   KernelCallbackTable[USER32_CALLBACK_CLIENTLOADLIBRARY] =
+      (PVOID)User32CallClientLoadLibraryFromKernel;
 
    NtUserProcessConnect( NtCurrentProcess(),
                          &UserCon,
index 24ebdf5..4dabbbe 100644 (file)
@@ -318,7 +318,7 @@ MDIRedrawFrame(HWND hWnd, DWORD flags)
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index e8fda2f..129fdd1 100644 (file)
@@ -2209,7 +2209,7 @@ DefWindowProcA(HWND hWnd,
    BOOL Hook, msgOverride = FALSE;
    LRESULT Result = 0;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
    if (Hook)
@@ -2242,7 +2242,7 @@ DefWindowProcW(HWND hWnd,
    BOOL Hook, msgOverride = FALSE;
    LRESULT Result = 0;
 
-   LOADUSERAPIHOOK
+  LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
    if (Hook)
index 5ecf9a5..d9c2dd6 100644 (file)
@@ -1457,7 +1457,7 @@ DrawFrameControl(HDC hDC, LPRECT rc, UINT uType, UINT uState)
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index ff982ee..40581eb 100644 (file)
@@ -427,6 +427,111 @@ SetWindowsHookExW(
   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
 User32CallHookProcFromKernel(PVOID Arguments, ULONG ArgumentLength)
 {
index 19f1825..5d3d9af 100644 (file)
@@ -1104,7 +1104,7 @@ AdjustWindowRectEx(LPRECT lpRect,
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
@@ -1148,7 +1148,7 @@ DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags)
 {
    BOOL Hook, Ret = FALSE;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index dff5f98..fd7cc57 100644 (file)
@@ -200,7 +200,7 @@ SetWindowRgn(
    BOOL Hook;
    int Ret = 0;
 
-   LOADUSERAPIHOOK
+   LoadUserApiHook();
 
    Hook = BeginIfHookedUserApiHook();
 
index 7679238..5e1cd08 100644 (file)
@@ -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 @@ typedef struct _LOADMENU_CALLBACK_ARGUMENTS
   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 @@ NTSTATUS WINAPI
 User32CallLoadMenuFromKernel(PVOID Arguments, ULONG ArgumentLength);
 NTSTATUS WINAPI
 User32CallClientThreadSetupFromKernel(PVOID Arguments, ULONG ArgumentLength);
-
+NTSTATUS WINAPI
+User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength);
 #endif /* __INCLUDE_USER32_CALLBACK_H */