Commit 306d71c3 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Support incrementing the module refcount in GetModuleHandleEx.

parent 447fda52
...@@ -501,6 +501,12 @@ BOOL WINAPI GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module ) ...@@ -501,6 +501,12 @@ BOOL WINAPI GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
{ {
NTSTATUS status = STATUS_SUCCESS; NTSTATUS status = STATUS_SUCCESS;
HMODULE ret; HMODULE ret;
ULONG magic;
/* if we are messing with the refcount, grab the loader lock */
if ((flags & GET_MODULE_HANDLE_EX_FLAG_PIN) ||
!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
LdrLockLoaderLock( 0, NULL, &magic );
if (!name) if (!name)
{ {
...@@ -515,21 +521,24 @@ BOOL WINAPI GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module ) ...@@ -515,21 +521,24 @@ BOOL WINAPI GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
{ {
UNICODE_STRING wstr; UNICODE_STRING wstr;
RtlInitUnicodeString( &wstr, name ); RtlInitUnicodeString( &wstr, name );
status = LdrGetDllHandle( 0, 0, &wstr, &ret ); status = LdrGetDllHandle( NULL, 0, &wstr, &ret );
} }
if (status != STATUS_SUCCESS) if (status == STATUS_SUCCESS)
{ {
SetLastError( RtlNtStatusToDosError( status ) ); if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN)
return FALSE; FIXME( "should pin refcount for %p\n", ret );
else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
LdrAddRefDll( 0, ret );
} }
else SetLastError( RtlNtStatusToDosError( status ) );
if ((flags & GET_MODULE_HANDLE_EX_FLAG_PIN) || if ((flags & GET_MODULE_HANDLE_EX_FLAG_PIN) ||
!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)) !(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
FIXME( "should update refcount, flags %x\n", flags ); LdrUnlockLoaderLock( 0, magic );
if (module) *module = ret; if (module) *module = ret;
return TRUE; return (status == STATUS_SUCCESS);
} }
/*********************************************************************** /***********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment