kernelbase: Don't use LdrLockLoaderLock() in GetModuleHandleExW().
Signed-off-by: Paul Gofman <pgofman@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7ddd79b8f5
commit
4e50b6179f
|
@ -373,10 +373,9 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExA( DWORD flags, LPCSTR name, HMOD
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
|
BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
|
||||||
{
|
{
|
||||||
NTSTATUS status = STATUS_SUCCESS;
|
|
||||||
HMODULE ret = NULL;
|
HMODULE ret = NULL;
|
||||||
ULONG_PTR magic;
|
NTSTATUS status;
|
||||||
BOOL lock;
|
void *dummy;
|
||||||
|
|
||||||
if (!module)
|
if (!module)
|
||||||
{
|
{
|
||||||
|
@ -394,36 +393,32 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMO
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we are messing with the refcount, grab the loader lock */
|
if (name && !(flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
|
||||||
lock = (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) || !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT);
|
{
|
||||||
if (lock) LdrLockLoaderLock( 0, NULL, &magic );
|
UNICODE_STRING wstr;
|
||||||
|
ULONG ldr_flags = 0;
|
||||||
|
|
||||||
if (!name)
|
if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN)
|
||||||
{
|
ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_PIN;
|
||||||
ret = NtCurrentTeb()->Peb->ImageBaseAddress;
|
if (flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)
|
||||||
}
|
ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
|
||||||
else if (flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
|
|
||||||
{
|
RtlInitUnicodeString( &wstr, name );
|
||||||
void *dummy;
|
status = LdrGetDllHandleEx( ldr_flags, NULL, NULL, &wstr, &ret );
|
||||||
if (!(ret = RtlPcToFileHeader( (void *)name, &dummy ))) status = STATUS_DLL_NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UNICODE_STRING wstr;
|
ret = name ? RtlPcToFileHeader( (void *)name, &dummy ) : NtCurrentTeb()->Peb->ImageBaseAddress;
|
||||||
RtlInitUnicodeString( &wstr, name );
|
|
||||||
status = LdrGetDllHandle( NULL, 0, &wstr, &ret );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status == STATUS_SUCCESS)
|
if (ret)
|
||||||
{
|
{
|
||||||
if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN)
|
if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
|
||||||
LdrAddRefDll( LDR_ADDREF_DLL_PIN, ret );
|
status = LdrAddRefDll( flags & GET_MODULE_HANDLE_EX_FLAG_PIN ? LDR_ADDREF_DLL_PIN : 0, ret );
|
||||||
else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
|
else
|
||||||
LdrAddRefDll( 0, ret );
|
status = STATUS_SUCCESS;
|
||||||
|
} else status = STATUS_DLL_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lock) LdrUnlockLoaderLock( 0, magic );
|
|
||||||
|
|
||||||
*module = ret;
|
*module = ret;
|
||||||
return set_ntstatus( status );
|
return set_ntstatus( status );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue