From 8f03470527bac7cf6930b5092b8e02e4d3d4118f Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Fri, 9 Feb 2024 18:20:52 -0600 Subject: [PATCH] vrclient_x64: Unload native vrclient shared library on process detach. CW-Bug-Id: #23390 --- vrclient_x64/gen_wrapper.py | 1 + vrclient_x64/unix_private.h | 1 + vrclient_x64/unixlib.cpp | 13 ++++++++++++- vrclient_x64/unixlib_generated.cpp | 1 + vrclient_x64/unixlib_generated.h | 1 + vrclient_x64/vrclient_main.c | 10 ++++++---- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/vrclient_x64/gen_wrapper.py b/vrclient_x64/gen_wrapper.py index adcd0706..d8ca678a 100755 --- a/vrclient_x64/gen_wrapper.py +++ b/vrclient_x64/gen_wrapper.py @@ -222,6 +222,7 @@ UNIX_FUNCS = [ 'vrclient_init', 'vrclient_HmdSystemFactory', 'vrclient_VRClientCoreFactory', + 'vrclient_unload', ] MANUAL_METHODS = { diff --git a/vrclient_x64/unix_private.h b/vrclient_x64/unix_private.h index d1324180..da4ebd7a 100644 --- a/vrclient_x64/unix_private.h +++ b/vrclient_x64/unix_private.h @@ -26,6 +26,7 @@ extern char *json_convert_startup_info(const char *startup_info); extern char *json_convert_paths(const char *input); extern NTSTATUS vrclient_init( void *args ); +extern NTSTATUS vrclient_unload( void *args ); extern NTSTATUS vrclient_HmdSystemFactory( void *args ); extern NTSTATUS vrclient_VRClientCoreFactory( void *args ); diff --git a/vrclient_x64/unixlib.cpp b/vrclient_x64/unixlib.cpp index 71cb5fb2..34971534 100644 --- a/vrclient_x64/unixlib.cpp +++ b/vrclient_x64/unixlib.cpp @@ -72,10 +72,11 @@ static BOOL load_vk_unwrappers( HMODULE winevulkan ) return TRUE; } +static void *vrclient; + NTSTATUS vrclient_init( void *args ) { struct vrclient_init_params *params = (struct vrclient_init_params *)args; - static void *vrclient; params->_ret = false; @@ -110,6 +111,16 @@ NTSTATUS vrclient_init( void *args ) return 0; } +NTSTATUS vrclient_unload( void *args ) +{ + if (!vrclient) return 0; + dlclose( vrclient ); + vrclient = NULL; + p_HmdSystemFactory = NULL; + p_VRClientCoreFactory = NULL; + return 0; +} + NTSTATUS vrclient_HmdSystemFactory( void *args ) { struct vrclient_HmdSystemFactory_params *params = (struct vrclient_HmdSystemFactory_params *)args; diff --git a/vrclient_x64/unixlib_generated.cpp b/vrclient_x64/unixlib_generated.cpp index b066e4bc..72b59ecb 100644 --- a/vrclient_x64/unixlib_generated.cpp +++ b/vrclient_x64/unixlib_generated.cpp @@ -10,6 +10,7 @@ extern "C" const unixlib_entry_t __wine_unix_call_funcs[] = vrclient_init, vrclient_HmdSystemFactory, vrclient_VRClientCoreFactory, + vrclient_unload, IVRApplications_IVRApplications_001_AddApplicationManifest, IVRApplications_IVRApplications_001_RemoveApplicationManifest, IVRApplications_IVRApplications_001_IsApplicationInstalled, diff --git a/vrclient_x64/unixlib_generated.h b/vrclient_x64/unixlib_generated.h index 93720fd2..9317bf69 100644 --- a/vrclient_x64/unixlib_generated.h +++ b/vrclient_x64/unixlib_generated.h @@ -28865,6 +28865,7 @@ enum unix_funcs unix_vrclient_init, unix_vrclient_HmdSystemFactory, unix_vrclient_VRClientCoreFactory, + unix_vrclient_unload, unix_IVRApplications_IVRApplications_001_AddApplicationManifest, unix_IVRApplications_IVRApplications_001_RemoveApplicationManifest, unix_IVRApplications_IVRApplications_001_IsApplicationInstalled, diff --git a/vrclient_x64/vrclient_main.c b/vrclient_x64/vrclient_main.c index 9b22f6c2..2d4b8066 100644 --- a/vrclient_x64/vrclient_main.c +++ b/vrclient_x64/vrclient_main.c @@ -28,6 +28,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(vrclient); CREATE_TYPE_INFO_VTABLE; struct compositor_data compositor_data = {0}; +static BOOL vrclient_loaded; BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved) { @@ -54,6 +55,8 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved) VRCLIENT_CALL( IVRClientCore_IVRClientCore_003_Cleanup, ¶ms ); compositor_data.client_core_linux_side = NULL; } + VRCLIENT_CALL( vrclient_unload, NULL ); + vrclient_loaded = FALSE; break; } @@ -107,7 +110,6 @@ static int load_vrclient(void) { static const WCHAR PROTON_VR_RUNTIME_W[] = {'P','R','O','T','O','N','_','V','R','_','R','U','N','T','I','M','E',0}; static const WCHAR winevulkanW[] = {'w','i','n','e','v','u','l','k','a','n','.','d','l','l',0}; - static BOOL loaded; struct vrclient_init_params params = {.winevulkan = LoadLibraryW( winevulkanW )}; WCHAR pathW[PATH_MAX]; @@ -119,7 +121,7 @@ static int load_vrclient(void) static const char append_path[] = "/bin/vrclient.so"; #endif - if (loaded) return 1; + if (vrclient_loaded) return 1; /* PROTON_VR_RUNTIME is provided by the proton setup script */ if(!GetEnvironmentVariableW(PROTON_VR_RUNTIME_W, pathW, ARRAY_SIZE(pathW))) @@ -172,10 +174,10 @@ static int load_vrclient(void) TRACE( "got openvr runtime path: %s\n", params.unix_path ); VRCLIENT_CALL( vrclient_init, ¶ms ); - if (params._ret) loaded = TRUE; + if (params._ret) vrclient_loaded = TRUE; HeapFree( GetProcessHeap(), 0, params.unix_path ); - return loaded; + return vrclient_loaded; } void *CDECL HmdSystemFactory(const char *name, int *return_code)