From 427e71fee8b4849c5a092fe9c8a6a995c87062e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Tue, 21 Jan 2025 11:22:52 +0100 Subject: [PATCH] vrclient: Use templates for some unix side thunks. --- vrclient_x64/unix_private.h | 8 ++++ vrclient_x64/unix_vrclientcore_manual.cpp | 19 ++++---- vrclient_x64/unix_vrsystem_manual.cpp | 57 +++-------------------- vrclient_x64/unixlib.cpp | 41 ++++++++++------ 4 files changed, 51 insertions(+), 74 deletions(-) diff --git a/vrclient_x64/unix_private.h b/vrclient_x64/unix_private.h index 12bd7754..067947fb 100644 --- a/vrclient_x64/unix_private.h +++ b/vrclient_x64/unix_private.h @@ -36,6 +36,14 @@ extern char *vrclient_dos_to_unix_path( const char *src ); extern void vrclient_free_path( char *path ); extern unsigned int vrclient_unix_path_to_dos_path( bool api_result, const char *src, char *dst, uint32_t dst_bytes ); +#define VRCLIENT_UNIX_IMPL( iface, version, method, ... ) \ + NTSTATUS iface ## _ ## iface ## _ ## version ## _ ## method( void *args ) \ + { \ + auto params = (struct iface ## _ ## iface ## _ ## version ## _ ## method ## _params *)args; \ + auto u_iface = (struct u_ ## iface ## _ ## iface ## _ ## version *)params->u_iface; \ + return iface ## _ ## method( u_iface, params, false, ## __VA_ARGS__ ); \ + } \ + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ diff --git a/vrclient_x64/unix_vrclientcore_manual.cpp b/vrclient_x64/unix_vrclientcore_manual.cpp index 402d8289..6fb16dbd 100644 --- a/vrclient_x64/unix_vrclientcore_manual.cpp +++ b/vrclient_x64/unix_vrclientcore_manual.cpp @@ -5,18 +5,16 @@ #pragma makedep unix #endif -NTSTATUS IVRClientCore_IVRClientCore_002_Init( void *args ) +template< typename Params > +static NTSTATUS IVRClientCore_Init( u_IVRClientCore_IVRClientCore_002 *iface, Params *params, bool wow64 ) { - struct IVRClientCore_IVRClientCore_002_Init_params *params = (struct IVRClientCore_IVRClientCore_002_Init_params *)args; - struct u_IVRClientCore_IVRClientCore_002 *iface = (struct u_IVRClientCore_IVRClientCore_002 *)params->u_iface; params->_ret = (uint32_t)iface->Init( params->eApplicationType ); return 0; } -NTSTATUS IVRClientCore_IVRClientCore_003_Init( void *args ) +template< typename Iface, typename Params > +static NTSTATUS IVRClientCore_Init( Iface *iface, Params *params, bool wow64 ) { - struct IVRClientCore_IVRClientCore_003_Init_params *params = (struct IVRClientCore_IVRClientCore_003_Init_params *)args; - struct u_IVRClientCore_IVRClientCore_003 *iface = (struct u_IVRClientCore_IVRClientCore_003 *)params->u_iface; const char *startup_info = json_convert_startup_info( params->pStartupInfo ); if (!startup_info) startup_info = params->pStartupInfo; @@ -26,12 +24,15 @@ NTSTATUS IVRClientCore_IVRClientCore_003_Init( void *args ) return 0; } -NTSTATUS IVRMailbox_IVRMailbox_001_undoc3( void *args ) +template< typename Iface, typename Params > +static NTSTATUS IVRMailbox_undoc3( Iface *iface, Params *params, bool wow64 ) { - struct IVRMailbox_IVRMailbox_001_undoc3_params *params = (struct IVRMailbox_IVRMailbox_001_undoc3_params *)args; - struct u_IVRMailbox_IVRMailbox_001 *iface = (struct u_IVRMailbox_IVRMailbox_001 *)params->u_iface; char *c = json_convert_paths( params->c ); params->_ret = (uint32_t)iface->undoc3( params->a, params->b, c ); free( c ); return 0; } + +VRCLIENT_UNIX_IMPL( IVRClientCore, 002, Init ); +VRCLIENT_UNIX_IMPL( IVRClientCore, 003, Init ); +VRCLIENT_UNIX_IMPL( IVRMailbox, 001, undoc3 ); diff --git a/vrclient_x64/unix_vrsystem_manual.cpp b/vrclient_x64/unix_vrsystem_manual.cpp index ca3b34fb..8527b860 100644 --- a/vrclient_x64/unix_vrsystem_manual.cpp +++ b/vrclient_x64/unix_vrsystem_manual.cpp @@ -23,10 +23,9 @@ static uint64_t wrap_device( uint32_t type, VkInstance_T *instance, uint64_t dev return device; } -NTSTATUS IVRSystem_IVRSystem_017_GetOutputDevice( void *args ) +template< typename Iface, typename Params > +static NTSTATUS IVRSystem_GetOutputDevice( Iface *iface, Params *params, bool wow64 ) { - struct IVRSystem_IVRSystem_017_GetOutputDevice_params *params = (struct IVRSystem_IVRSystem_017_GetOutputDevice_params *)args; - struct u_IVRSystem_IVRSystem_017 *iface = (struct u_IVRSystem_IVRSystem_017 *)params->u_iface; VkInstance_T *host_instance = unwrap_instance( params->textureType, params->pInstance ); uint64_t host_device; @@ -35,50 +34,8 @@ NTSTATUS IVRSystem_IVRSystem_017_GetOutputDevice( void *args ) return 0; } -NTSTATUS IVRSystem_IVRSystem_019_GetOutputDevice( void *args ) -{ - struct IVRSystem_IVRSystem_019_GetOutputDevice_params *params = (struct IVRSystem_IVRSystem_019_GetOutputDevice_params *)args; - struct u_IVRSystem_IVRSystem_019 *iface = (struct u_IVRSystem_IVRSystem_019 *)params->u_iface; - VkInstance_T *host_instance = unwrap_instance( params->textureType, params->pInstance ); - uint64_t host_device; - - iface->GetOutputDevice( &host_device, params->textureType, host_instance ); - *params->pnDevice = wrap_device( params->textureType, params->pInstance, host_device ); - return 0; -} - -NTSTATUS IVRSystem_IVRSystem_020_GetOutputDevice( void *args ) -{ - struct IVRSystem_IVRSystem_020_GetOutputDevice_params *params = (struct IVRSystem_IVRSystem_020_GetOutputDevice_params *)args; - struct u_IVRSystem_IVRSystem_020 *iface = (struct u_IVRSystem_IVRSystem_020 *)params->u_iface; - VkInstance_T *host_instance = unwrap_instance( params->textureType, params->pInstance ); - uint64_t host_device; - - iface->GetOutputDevice( &host_device, params->textureType, host_instance ); - *params->pnDevice = wrap_device( params->textureType, params->pInstance, host_device ); - return 0; -} - -NTSTATUS IVRSystem_IVRSystem_021_GetOutputDevice( void *args ) -{ - struct IVRSystem_IVRSystem_021_GetOutputDevice_params *params = (struct IVRSystem_IVRSystem_021_GetOutputDevice_params *)args; - struct u_IVRSystem_IVRSystem_021 *iface = (struct u_IVRSystem_IVRSystem_021 *)params->u_iface; - VkInstance_T *host_instance = unwrap_instance( params->textureType, params->pInstance ); - uint64_t host_device; - - iface->GetOutputDevice( &host_device, params->textureType, host_instance ); - *params->pnDevice = wrap_device( params->textureType, params->pInstance, host_device ); - return 0; -} - -NTSTATUS IVRSystem_IVRSystem_022_GetOutputDevice( void *args ) -{ - struct IVRSystem_IVRSystem_022_GetOutputDevice_params *params = (struct IVRSystem_IVRSystem_022_GetOutputDevice_params *)args; - struct u_IVRSystem_IVRSystem_022 *iface = (struct u_IVRSystem_IVRSystem_022 *)params->u_iface; - VkInstance_T *host_instance = unwrap_instance( params->textureType, params->pInstance ); - uint64_t host_device; - - iface->GetOutputDevice( &host_device, params->textureType, host_instance ); - *params->pnDevice = wrap_device( params->textureType, params->pInstance, host_device ); - return 0; -} +VRCLIENT_UNIX_IMPL( IVRSystem, 017, GetOutputDevice ); +VRCLIENT_UNIX_IMPL( IVRSystem, 019, GetOutputDevice ); +VRCLIENT_UNIX_IMPL( IVRSystem, 020, GetOutputDevice ); +VRCLIENT_UNIX_IMPL( IVRSystem, 021, GetOutputDevice ); +VRCLIENT_UNIX_IMPL( IVRSystem, 022, GetOutputDevice ); diff --git a/vrclient_x64/unixlib.cpp b/vrclient_x64/unixlib.cpp index 1c6dfba7..55d774c8 100644 --- a/vrclient_x64/unixlib.cpp +++ b/vrclient_x64/unixlib.cpp @@ -164,9 +164,9 @@ static int parse_extensions( const char *extensions, char ***list ) return count; } -NTSTATUS vrclient_init_registry( void *args ) +template< typename Params > +static NTSTATUS vrclient_init_registry( Params *params, bool wow64 ) { - struct vrclient_init_registry_params *params = (struct vrclient_init_registry_params *)args; VkApplicationInfo app_info = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, @@ -305,9 +305,9 @@ failed: return 0; } -NTSTATUS vrclient_init( void *args ) +template< typename Params > +static NTSTATUS vrclient_init( Params *params, bool wow64 ) { - struct vrclient_init_params *params = (struct vrclient_init_params *)args; params->_ret = false; @@ -341,9 +341,9 @@ NTSTATUS vrclient_init( void *args ) return 0; } -NTSTATUS vrclient_unload( void *args ) +template< typename Params > +static NTSTATUS vrclient_unload( Params *params, bool wow64 ) { - if (!vrclient) return 0; dlclose( vrclient ); vrclient = NULL; p_HmdSystemFactory = NULL; @@ -351,24 +351,23 @@ NTSTATUS vrclient_unload( void *args ) return 0; } -NTSTATUS vrclient_HmdSystemFactory( void *args ) +template< typename Params > +static NTSTATUS vrclient_HmdSystemFactory( Params *params, bool wow64 ) { - struct vrclient_HmdSystemFactory_params *params = (struct vrclient_HmdSystemFactory_params *)args; params->_ret = p_HmdSystemFactory( params->name, params->return_code ); return 0; } -NTSTATUS vrclient_VRClientCoreFactory( void *args ) +template< typename Params > +static NTSTATUS vrclient_VRClientCoreFactory( Params *params, bool wow64 ) { - struct vrclient_VRClientCoreFactory_params *params = (struct vrclient_VRClientCoreFactory_params *)args; params->_ret = p_VRClientCoreFactory( params->name, params->return_code ); return 0; } -NTSTATUS IVRTrackedCamera_IVRTrackedCamera_001_GetVideoStreamFrame( void *args ) +template< typename Iface, typename Params > +static NTSTATUS IVRTrackedCamera_GetVideoStreamFrame( Iface *iface, Params *params, bool wow64 ) { - struct IVRTrackedCamera_IVRTrackedCamera_001_GetVideoStreamFrame_params *params = (struct IVRTrackedCamera_IVRTrackedCamera_001_GetVideoStreamFrame_params *)args; - struct u_IVRTrackedCamera_IVRTrackedCamera_001 *iface = (struct u_IVRTrackedCamera_IVRTrackedCamera_001 *)params->u_iface; *(w_CameraVideoStreamFrame_t_0914 *)params->_ret = *iface->GetVideoStreamFrame( params->nDeviceIndex ); return 0; } @@ -386,9 +385,9 @@ template<> struct hash< struct u_buffer > static pthread_mutex_t buffer_cache_lock = PTHREAD_MUTEX_INITIALIZER; static std::unordered_map< struct u_buffer, void * > buffer_cache; -NTSTATUS vrclient_get_unix_buffer( void *args ) +template< typename Params > +static NTSTATUS vrclient_get_unix_buffer( Params *params, bool wow64 ) { - struct vrclient_get_unix_buffer_params *params = (struct vrclient_get_unix_buffer_params *)args; struct cache_entry *entry; struct rb_entry *ptr; @@ -404,3 +403,15 @@ NTSTATUS vrclient_get_unix_buffer( void *args ) return 0; } + +#define VRCLIENT_UNIX_FUNC( name ) \ + NTSTATUS name( void *args ) { return name( (struct name ## _params *)args, false ); } \ + +VRCLIENT_UNIX_FUNC( vrclient_init ); +VRCLIENT_UNIX_FUNC( vrclient_init_registry ); +VRCLIENT_UNIX_FUNC( vrclient_unload ); +VRCLIENT_UNIX_FUNC( vrclient_HmdSystemFactory ); +VRCLIENT_UNIX_FUNC( vrclient_VRClientCoreFactory ); +VRCLIENT_UNIX_FUNC( vrclient_get_unix_buffer ); + +VRCLIENT_UNIX_IMPL( IVRTrackedCamera, 001, GetVideoStreamFrame );