mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-01 21:53:58 +00:00
nsi: Cache nsi device handle.
This commit is contained in:
parent
64c6819553
commit
b8fa6de2c2
|
@ -30,9 +30,34 @@
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(nsi);
|
WINE_DEFAULT_DEBUG_CHANNEL(nsi);
|
||||||
|
|
||||||
|
static HANDLE nsi_device = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved)
|
||||||
|
{
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
DisableThreadLibraryCalls( hinst );
|
||||||
|
break;
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
if (nsi_device != INVALID_HANDLE_VALUE) CloseHandle( nsi_device );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static inline HANDLE get_nsi_device( void )
|
static inline HANDLE get_nsi_device( void )
|
||||||
{
|
{
|
||||||
return CreateFileW( L"\\\\.\\Nsi", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
|
HANDLE device;
|
||||||
|
|
||||||
|
if (nsi_device == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
device = CreateFileW( L"\\\\.\\Nsi", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
|
||||||
|
if (device != INVALID_HANDLE_VALUE
|
||||||
|
&& InterlockedCompareExchangePointer( &nsi_device, device, INVALID_HANDLE_VALUE ) != INVALID_HANDLE_VALUE)
|
||||||
|
CloseHandle( device );
|
||||||
|
}
|
||||||
|
return nsi_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD WINAPI NsiAllocateAndGetTable( DWORD unk, const NPI_MODULEID *module, DWORD table, void **key_data, DWORD key_size,
|
DWORD WINAPI NsiAllocateAndGetTable( DWORD unk, const NPI_MODULEID *module, DWORD table, void **key_data, DWORD key_size,
|
||||||
|
@ -140,11 +165,7 @@ DWORD WINAPI NsiEnumerateObjectsAllParametersEx( struct nsi_enumerate_all_ex *pa
|
||||||
(params->key_size + params->rw_size + params->dynamic_size + params->static_size) * params->count;
|
(params->key_size + params->rw_size + params->dynamic_size + params->static_size) * params->count;
|
||||||
|
|
||||||
out = heap_alloc( out_size );
|
out = heap_alloc( out_size );
|
||||||
if (!out)
|
if (!out) return ERROR_OUTOFMEMORY;
|
||||||
{
|
|
||||||
CloseHandle( device );
|
|
||||||
return ERROR_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
in.module = *params->module;
|
in.module = *params->module;
|
||||||
in.first_arg = params->first_arg;
|
in.first_arg = params->first_arg;
|
||||||
|
@ -172,7 +193,6 @@ DWORD WINAPI NsiEnumerateObjectsAllParametersEx( struct nsi_enumerate_all_ex *pa
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_free( out );
|
heap_free( out );
|
||||||
CloseHandle( device );
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -256,7 +276,6 @@ DWORD WINAPI NsiGetAllParametersEx( struct nsi_get_all_parameters_ex *params )
|
||||||
err:
|
err:
|
||||||
heap_free( out );
|
heap_free( out );
|
||||||
heap_free( in );
|
heap_free( in );
|
||||||
CloseHandle( device );
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,11 +312,7 @@ DWORD WINAPI NsiGetParameterEx( struct nsi_get_parameter_ex *params )
|
||||||
if (device == INVALID_HANDLE_VALUE) return GetLastError();
|
if (device == INVALID_HANDLE_VALUE) return GetLastError();
|
||||||
|
|
||||||
in = heap_alloc( in_size );
|
in = heap_alloc( in_size );
|
||||||
if (!in)
|
if (!in) return ERROR_OUTOFMEMORY;
|
||||||
{
|
|
||||||
err = ERROR_OUTOFMEMORY;
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
in->module = *params->module;
|
in->module = *params->module;
|
||||||
in->first_arg = params->first_arg;
|
in->first_arg = params->first_arg;
|
||||||
in->table = params->table;
|
in->table = params->table;
|
||||||
|
@ -309,9 +324,7 @@ DWORD WINAPI NsiGetParameterEx( struct nsi_get_parameter_ex *params )
|
||||||
if (!DeviceIoControl( device, IOCTL_NSIPROXY_WINE_GET_PARAMETER, in, in_size, params->data, params->data_size, &received, NULL ))
|
if (!DeviceIoControl( device, IOCTL_NSIPROXY_WINE_GET_PARAMETER, in, in_size, params->data, params->data_size, &received, NULL ))
|
||||||
err = GetLastError();
|
err = GetLastError();
|
||||||
|
|
||||||
err:
|
|
||||||
heap_free( in );
|
heap_free( in );
|
||||||
CloseHandle( device );
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue