Author: tkreuzer Date: Sun Oct 7 08:43:54 2012 New Revision: 57507
URL: http://svn.reactos.org/svn/reactos?rev=57507&view=rev Log: [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.
Modified: trunk/reactos/win32ss/user/ntuser/callback.c trunk/reactos/win32ss/user/ntuser/callback.h trunk/reactos/win32ss/user/ntuser/hook.c trunk/reactos/win32ss/user/user32/windows/hook.c
Modified: trunk/reactos/win32ss/user/ntuser/callback.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/callbac... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/callback.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/callback.c [iso-8859-1] Sun Oct 7 08:43:54 2012 @@ -78,7 +78,7 @@ ListEntry);
/* Free memory */ - ExFreePool(Mem); + ExFreePoolWithTag(Mem, USERTAG_CALLBACK); } }
@@ -115,7 +115,8 @@ /* FUNCTIONS *****************************************************************/
/* Calls ClientLoadLibrary in user32 */ -HMODULE +BOOL +NTAPI co_IntClientLoadLibrary(PUNICODE_STRING pstrLibName, PUNICODE_STRING pstrInitFunc, BOOL Unload, @@ -126,7 +127,7 @@ 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 @@
_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
Modified: trunk/reactos/win32ss/user/ntuser/callback.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/ntuser/callbac... ============================================================================== --- trunk/reactos/win32ss/user/ntuser/callback.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/ntuser/callback.h [iso-8859-1] Sun Oct 7 08:43:54 2012 @@ -55,9 +55,10 @@
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);
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] Sun Oct 7 08:43:54 2012 @@ -31,7 +31,7 @@ IntLoadHookModule(int iHookID, HHOOK hHook, BOOL Unload) { PPROCESSINFO ppi; - HMODULE hmod; + BOOL bResult;
ppi = PsGetCurrentProcessWin32Process();
@@ -49,26 +49,24 @@ 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 @@ if (BadChk) { ERR("HOOK WH_DEBUG read from Debug.lParam ERROR!\n"); - ExFreePool(HooklParam); + ExFreePoolWithTag(HooklParam, TAG_HOOK); return lResult; } }
Modified: trunk/reactos/win32ss/user/user32/windows/hook.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/user/user32/windows... ============================================================================== --- trunk/reactos/win32ss/user/user32/windows/hook.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/user/user32/windows/hook.c [iso-8859-1] Sun Oct 7 08:43:54 2012 @@ -427,104 +427,109 @@ 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 @@ }
/* Call the implementation of the callback */ - Result = ClientLoadLibrary(&Argument->strLibraryName, - &Argument->strInitFuncName, - Argument->Unload, - Argument->ApiHook); - - return ZwCallbackReturn(&Result, sizeof(HINSTANCE), STATUS_SUCCESS); + bResult = ClientLoadLibrary(&Argument->strLibraryName, + &Argument->strInitFuncName, + Argument->Unload, + Argument->ApiHook); + + return ZwCallbackReturn(&bResult, sizeof(HINSTANCE), STATUS_SUCCESS); }
NTSTATUS WINAPI