From 0c4428ca0692ce3bb5d82fe5488548d9dff6a8fc Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 7 Oct 2012 08:43:54 +0000 Subject: [PATCH] [WIN32K][USER32] Chnge return type of ClientLoadLibrary to BOOL. Previously it returned HMODULE in both the load and unload case, being a meaningless value in the latter case. All users of this function were using it as a boolean parameter only. svn path=/trunk/; revision=57507 --- reactos/win32ss/user/ntuser/callback.c | 15 ++-- reactos/win32ss/user/ntuser/callback.h | 7 +- reactos/win32ss/user/ntuser/hook.c | 20 +++--- reactos/win32ss/user/user32/windows/hook.c | 83 ++++++++++++---------- 4 files changed, 65 insertions(+), 60 deletions(-) diff --git a/reactos/win32ss/user/ntuser/callback.c b/reactos/win32ss/user/ntuser/callback.c index 295f0205bd0..4d84db4a410 100644 --- a/reactos/win32ss/user/ntuser/callback.c +++ b/reactos/win32ss/user/ntuser/callback.c @@ -78,7 +78,7 @@ IntCleanupThreadCallbacks(PTHREADINFO W32Thread) ListEntry); /* Free memory */ - ExFreePool(Mem); + ExFreePoolWithTag(Mem, USERTAG_CALLBACK); } } @@ -115,7 +115,8 @@ IntRestoreTebWndCallback (HWND hWnd, PWND pWnd, PVOID pActCtx) /* FUNCTIONS *****************************************************************/ /* Calls ClientLoadLibrary in user32 */ -HMODULE +BOOL +NTAPI co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, PUNICODE_STRING pstrInitFunc, BOOL Unload, @@ -126,7 +127,7 @@ co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, ULONG ArgumentLength; PCLIENT_LOAD_LIBRARY_ARGUMENTS pArguments; NTSTATUS Status; - HMODULE Result; + BOOL bResult; ULONG_PTR pLibNameBuffer = 0, pInitFuncBuffer = 0; TRACE("co_IntClientLoadLibrary: %S, %S, %d, %d\n", pstrLibName->Buffer, pstrLibName->Buffer, Unload, ApiHook); @@ -209,17 +210,17 @@ co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, _SEH2_TRY { + /* Probe and copy the usermode result data */ ProbeForRead(ResultPointer, sizeof(HMODULE), 1); - /* Simulate old behaviour: copy into our local buffer */ - Result = *(HMODULE*)ResultPointer; + bResult = *(BOOL*)ResultPointer; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { - Result = 0; + bResult = FALSE; } _SEH2_END; - return Result; + return bResult; } VOID APIENTRY diff --git a/reactos/win32ss/user/ntuser/callback.h b/reactos/win32ss/user/ntuser/callback.h index 5997134b60b..6c089a371b6 100644 --- a/reactos/win32ss/user/ntuser/callback.h +++ b/reactos/win32ss/user/ntuser/callback.h @@ -55,9 +55,10 @@ HMENU APIENTRY co_IntCallLoadMenu(HINSTANCE,PUNICODE_STRING); NTSTATUS APIENTRY co_IntClientThreadSetup(VOID); -HMODULE -co_IntClientLoadLibrary(PUNICODE_STRING strLibName, - PUNICODE_STRING strInitFunc, +BOOL +NTAPI +co_IntClientLoadLibrary(PUNICODE_STRING strLibName, + PUNICODE_STRING strInitFunc, BOOL Unload, BOOL ApiHook); diff --git a/reactos/win32ss/user/ntuser/hook.c b/reactos/win32ss/user/ntuser/hook.c index ca1201c698a..09f9a3760fc 100644 --- a/reactos/win32ss/user/ntuser/hook.c +++ b/reactos/win32ss/user/ntuser/hook.c @@ -31,7 +31,7 @@ BOOL IntLoadHookModule(int iHookID, HHOOK hHook, BOOL Unload) { PPROCESSINFO ppi; - HMODULE hmod; + BOOL bResult; ppi = PsGetCurrentProcessWin32Process(); @@ -49,26 +49,24 @@ IntLoadHookModule(int iHookID, HHOOK hHook, BOOL Unload) ppi->W32PF_flags |= W32PF_APIHOOKLOADED; /* Call ClientLoadLibrary in user32 */ - hmod = co_IntClientLoadLibrary(&strUahModule, &strUahInitFunc, Unload, TRUE); - TRACE("co_IntClientLoadLibrary returned %d\n", hmod ); - if(hmod == 0) + bResult = co_IntClientLoadLibrary(&strUahModule, &strUahInitFunc, Unload, TRUE); + TRACE("co_IntClientLoadLibrary returned %d\n", bResult ); + if (!bResult) { /* Remove the flag we set before */ ppi->W32PF_flags &= ~W32PF_APIHOOKLOADED; - return FALSE; } - return TRUE; + return bResult; } else if(Unload && (ppi->W32PF_flags & W32PF_APIHOOKLOADED)) { /* Call ClientLoadLibrary in user32 */ - hmod = co_IntClientLoadLibrary(NULL, NULL, Unload, TRUE); - if(hmod != 0) + bResult = co_IntClientLoadLibrary(NULL, NULL, Unload, TRUE); + if (bResult) { ppi->W32PF_flags &= ~W32PF_APIHOOKLOADED; - return TRUE; } - return FALSE; + return bResult; } return TRUE; @@ -500,7 +498,7 @@ co_IntCallDebugHook(PHOOK Hook, if (BadChk) { ERR("HOOK WH_DEBUG read from Debug.lParam ERROR!\n"); - ExFreePool(HooklParam); + ExFreePoolWithTag(HooklParam, TAG_HOOK); return lResult; } } diff --git a/reactos/win32ss/user/user32/windows/hook.c b/reactos/win32ss/user/user32/windows/hook.c index 31f0a447eca..e0e04f87055 100644 --- a/reactos/win32ss/user/user32/windows/hook.c +++ b/reactos/win32ss/user/user32/windows/hook.c @@ -427,104 +427,109 @@ SetWindowsHookExW( return IntSetWindowsHook(idHook, lpfn, hMod, dwThreadId, FALSE); } -HINSTANCE ClientLoadLibrary(PUNICODE_STRING pstrLibName, - PUNICODE_STRING pstrInitFunc, - BOOL Unload, - BOOL ApiHook) +static +BOOL +ClientLoadLibrary( + PUNICODE_STRING pstrLibName, + PUNICODE_STRING pstrInitFunc, + BOOL bUnload, + BOOL bApiHook) { HINSTANCE hLibrary; PVOID pInitFunction; - //NTSTATUS Status; + NTSTATUS Status; ANSI_STRING InitFuncName; - BOOL Result = FALSE; + BOOL bResult = FALSE; TRACE("ClientLoadLibrary: pid: %d, strLibraryName: %S, " - "strInitFuncName: %S, Unload: %d, ApiHook:%d\n", + "strInitFuncName: %S, bUnload: %d, bApiHook:%d\n", GetCurrentProcessId(), pstrLibName->Buffer, pstrInitFunc->Buffer, - Unload, - ApiHook); + bUnload, + bApiHook); /* Check if we have to load the module */ - if(Unload == FALSE) + if (bUnload == FALSE) { ASSERT(pstrLibName->Buffer != NULL); /* Load it */ hLibrary = LoadLibrary(pstrLibName->Buffer); - if(hLibrary == 0) + if (hLibrary == 0) { - return hLibrary; + return FALSE; } - if(ApiHook == FALSE) + if (!bApiHook) { /* There is nothing more to do for a global hook*/ - return hLibrary; + return TRUE; } /* Initialize the user api hook */ ASSERT(pstrInitFunc->Buffer); - - /*Status = */ RtlUnicodeStringToAnsiString(&InitFuncName, + Status = RtlUnicodeStringToAnsiString(&InitFuncName, pstrInitFunc, TRUE); + if (!NT_SUCCESS(Status)) + { + FreeLibrary(hLibrary); + return FALSE; + } /* Get the address of the initialization routine */ pInitFunction = GetProcAddress(hLibrary, InitFuncName.Buffer); - if(pInitFunction) + if (pInitFunction) { /* Call the initialization routine */ - Result = InitUserApiHook(hLibrary, (USERAPIHOOKPROC)pInitFunction); + bResult = InitUserApiHook(hLibrary, (USERAPIHOOKPROC)pInitFunction); } + RtlFreeAnsiString(&InitFuncName); /* In case of error unload the library */ - if(Result == FALSE) + if (bResult == FALSE) { FreeLibrary(hLibrary); - hLibrary = 0; } } else { /* Cleanup user api hook before unloading */ - if(ApiHook == TRUE) + if (bApiHook) { hLibrary = ghmodUserApiHook; - Result = ClearUserApiHook(ghmodUserApiHook); + bResult = ClearUserApiHook(ghmodUserApiHook); + /* Check if we can we unload it now */ - if(Result == FALSE) + if (!bResult) { /* Return success because we are going to free the library in EndUserApiHook*/ - return hLibrary; + return TRUE; } } else { + /* Get the library handle from the name */ hLibrary = GetModuleHandle(pstrLibName->Buffer); - Result = (hLibrary != 0); - } - - if(Result == TRUE) - { - Result = FreeLibrary(hLibrary); - if(Result == FALSE) + if (hLibrary == NULL) { - hLibrary = 0; + return FALSE; } } + + bResult = FreeLibrary(hLibrary); } - return hLibrary; + return bResult; } NTSTATUS WINAPI User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength) { - HINSTANCE Result; + BOOL bResult; PCLIENT_LOAD_LIBRARY_ARGUMENTS Argument; /* Retireve the callback parameters */ @@ -539,12 +544,12 @@ User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength) } /* Call the implementation of the callback */ - Result = ClientLoadLibrary(&Argument->strLibraryName, - &Argument->strInitFuncName, - Argument->Unload, - Argument->ApiHook); + bResult = ClientLoadLibrary(&Argument->strLibraryName, + &Argument->strInitFuncName, + Argument->Unload, + Argument->ApiHook); - return ZwCallbackReturn(&Result, sizeof(HINSTANCE), STATUS_SUCCESS); + return ZwCallbackReturn(&bResult, sizeof(HINSTANCE), STATUS_SUCCESS); } NTSTATUS WINAPI