Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/kernelbase/loader.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/dlls/kernelbase/loader.c b/dlls/kernelbase/loader.c index ac463528e3c..a662305a250 100644 --- a/dlls/kernelbase/loader.c +++ b/dlls/kernelbase/loader.c @@ -375,8 +375,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO { NTSTATUS status = STATUS_SUCCESS; HMODULE ret = NULL; - ULONG_PTR magic; - BOOL lock;
if (!module) { @@ -384,10 +382,6 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO return FALSE; }
- /* if we are messing with the refcount, grab the loader lock */ - lock = (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) || !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT); - if (lock) LdrLockLoaderLock( 0, NULL, &magic ); - if (!name) { ret = NtCurrentTeb()->Peb->ImageBaseAddress; @@ -400,20 +394,26 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO else { UNICODE_STRING wstr; + ULONG ldr_flags = 0; + + if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) + ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_PIN; + if (flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT) + ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT; + RtlInitUnicodeString( &wstr, name ); - status = LdrGetDllHandle( NULL, 0, &wstr, &ret ); + status = LdrGetDllHandleEx( ldr_flags, NULL, NULL, &wstr, &ret ); + flags = GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT; }
if (status == STATUS_SUCCESS) { if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) - LdrAddRefDll( LDR_ADDREF_DLL_PIN, ret ); + status = LdrAddRefDll( LDR_ADDREF_DLL_PIN, ret ); else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)) - LdrAddRefDll( 0, ret ); + status = LdrAddRefDll( 0, ret ); }
- if (lock) LdrUnlockLoaderLock( 0, magic ); - *module = ret; return set_ntstatus( status ); }