From: Twaik Yont <9674930+twaik@users.noreply.github.com> Remove the legacy ioctl backend startup via KeUserDispatchCallback and switch fully to the socket-based transport. A dedicated listener thread is now started directly with pthread_create, and the desktop process is tracked via an explicit in_desktop_process flag. dequeueBuffer is updated to use file descriptor passing via SCM_RIGHTS, and all handle-based duplication logic is removed. The old ioctl implementation is kept as android_ioctl_old() but is no longer used. This completes the transition away from the legacy backend startup path. Signed-off-by: Twaik Yont <9674930+twaik@users.noreply.github.com> --- dlls/wineandroid.drv/device.c | 98 +++++++---------------------------- 1 file changed, 20 insertions(+), 78 deletions(-) diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 02ccf2760cd..14fbf4c190b 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -107,7 +107,7 @@ DECL_FUNCPTR( ANativeWindowBuffer_getHardwareBuffer ); #define SYNC_IOC_WAIT _IOW('>', 0, __s32) #endif -static HANDLE thread; +static BOOL in_desktop_process; static JNIEnv *jni_env; static HWND capture_window; static HWND desktop_window; @@ -208,8 +208,6 @@ struct ioctl_android_window_pos_changed struct ioctl_android_dequeueBuffer { struct ioctl_header hdr; - DWORD pid; - HANDLE handle; int buffer_id; int generation; }; @@ -271,13 +269,7 @@ struct ioctl_android_set_cursor int bits[1]; }; - -static inline BOOL is_in_desktop_process(void) -{ - return thread != NULL; -} - -#ifdef __i386__ /* the Java VM uses %fs/%gs for its own purposes, so we need to wrap the calls */ +#if 0 /* the Java VM uses %fs/%gs for its own purposes, so we need to wrap the calls */ static WORD orig_fs, java_fs; static inline void wrap_java_call(void) { __asm__( "mov %0,%%fs" :: "r" (java_fs) ); } @@ -292,7 +284,7 @@ static inline void init_java_thread( JavaVM *java_vm ) __asm__( "mov %0,%%fs" :: "r" (orig_fs) ); } -#elif defined(__x86_64__) +#elif 0 #include <asm/prctl.h> #include <asm/unistd.h> @@ -730,7 +722,6 @@ static NTSTATUS dequeueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, if (!(win_data = get_ioctl_native_win_data( &res->hdr ))) return STATUS_INVALID_HANDLE; if (!(parent = win_data->parent)) return STATUS_DEVICE_NOT_READY; - res->handle = 0; res->buffer_id = -1; res->generation = 0; *ret_size = sizeof(*res); @@ -755,15 +746,10 @@ static NTSTATUS dequeueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, res->buffer_id = register_buffer( win_data, ahb, &is_new ); res->generation = win_data->generation; - res->handle = 0; if (is_new) { int sv[2] = { -1, -1 }; - HANDLE local = 0; - OBJECT_ATTRIBUTES attr = { .Length = sizeof(attr) }; - CLIENT_ID cid = { .UniqueProcess = UlongToHandle( res->pid ) }; - HANDLE process; if (!ahb) { @@ -777,37 +763,16 @@ static NTSTATUS dequeueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, return STATUS_UNSUCCESSFUL; } - if (NtOpenProcess( &process, PROCESS_DUP_HANDLE, &attr, &cid )) - { - close( sv[0] ); - close( sv[1] ); - wait_fence_and_close( fence ); - return STATUS_UNSUCCESSFUL; - } - - if (!wine_server_fd_to_handle( dup(sv[1]), GENERIC_READ | SYNCHRONIZE, 0, &local )) - { - NTSTATUS status = NtDuplicateObject( GetCurrentProcess(), local, process, &res->handle, 0, 0, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE ); - if (status && local) NtClose( local ); - } - - NtClose( process ); - close( sv[1] ); - - if (!res->handle) - { - close( sv[0] ); - wait_fence_and_close( fence ); - return STATUS_UNSUCCESSFUL; - } - ret = pAHardwareBuffer_sendHandleToUnixSocket( ahb, sv[0] ); close( sv[0] ); if (ret) { + close( sv[1] ); wait_fence_and_close( fence ); return android_error_to_status( ret ); } + + *reply_fd = sv[1]; } wait_fence_and_close( fence ); @@ -1110,24 +1075,11 @@ NTSTATUS android_dispatch_ioctl( void *arg ) NTSTATUS android_java_init( void *arg ) { - JavaVM *java_vm; - - if (!(java_vm = *p_java_vm)) return STATUS_UNSUCCESSFUL; /* not running under Java */ - - init_java_thread( java_vm ); - create_desktop_view(); - return STATUS_SUCCESS; + return STATUS_UNSUCCESSFUL; } NTSTATUS android_java_uninit( void *arg ) { - JavaVM *java_vm; - - if (!(java_vm = *p_java_vm)) return STATUS_UNSUCCESSFUL; /* not running under Java */ - - wrap_java_call(); - (*java_vm)->DetachCurrentThread( java_vm ); - unwrap_java_call(); return STATUS_SUCCESS; } @@ -1137,6 +1089,7 @@ static void *ioctl_thread_proc(void *arg) int listen_fd, epoll_fd; if (!(java_vm = *p_java_vm)) return NULL; /* not running under Java */ + in_desktop_process = TRUE; init_java_thread( java_vm ); create_desktop_view(); @@ -1286,18 +1239,17 @@ static void *ioctl_thread_proc(void *arg) void start_android_device(void) { - void *ret_ptr; - ULONG ret_len; - struct dispatch_callback_params params = {.callback = start_device_callback}; - if (KeUserDispatchCallback( ¶ms, sizeof(params), &ret_ptr, &ret_len )) return; - if (ret_len == sizeof(thread)) thread = *(HANDLE *)ret_ptr; + pthread_t t; + + if (pthread_create( &t, NULL, ioctl_thread_proc, NULL ) == 0) + pthread_detach( t ); } /* Client-side ioctl support */ -static int android_ioctl( enum android_ioctl code, void *in, DWORD in_size, void *out, DWORD *out_size, int *recv_fd ) +static int android_ioctl_old( enum android_ioctl code, void *in, DWORD in_size, void *out, DWORD *out_size, int *recv_fd ) { static const WCHAR deviceW[] = { '\\','D','e','v','i','c','e','\\','W','i','n','e','A','n','d','r','o','i','d', 0 }; static HANDLE device; @@ -1333,7 +1285,7 @@ static int android_ioctl( enum android_ioctl code, void *in, DWORD in_size, void return status_to_android_error( status ); } -static int android_ioctl_new( enum android_ioctl code, void *in, DWORD in_size, void *out, DWORD *out_size, int *recv_fd ) +static int android_ioctl( enum android_ioctl code, void *in, DWORD in_size, void *out, DWORD *out_size, int *recv_fd ) { static int device_fd = -1; static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -1410,35 +1362,25 @@ static int dequeueBuffer( struct ANativeWindow *window, struct ANativeWindowBuff struct native_win_wrapper *win = (struct native_win_wrapper *)window; struct ioctl_android_dequeueBuffer res = {0}; DWORD size = sizeof(res); - int ret; + int ret, buffer_fd = -1; res.hdr.hwnd = HandleToLong( win->hwnd ); res.hdr.opengl = win->opengl; - res.pid = GetCurrentProcessId(); - res.handle = 0; res.buffer_id = -1; res.generation = 0; - ret = android_ioctl( IOCTL_DEQUEUE_BUFFER, &res, size, &res, &size, NULL ); + ret = android_ioctl( IOCTL_DEQUEUE_BUFFER, &res, size, &res, &size, &buffer_fd ); if (ret) return ret; if (size < sizeof(res)) return -EINVAL; if (res.buffer_id < 0 || res.buffer_id >= NB_CACHED_BUFFERS) return -EINVAL; - if (res.handle) + if (buffer_fd != -1) { AHardwareBuffer *ahb = NULL; - int fd; - - if (wine_server_handle_to_fd( res.handle, GENERIC_READ | SYNCHRONIZE, &fd, NULL )) - { - NtClose( res.handle ); - return -EINVAL; - } - NtClose( res.handle ); - ret = pAHardwareBuffer_recvHandleFromUnixSocket( fd, &ahb ); - close( fd ); + ret = pAHardwareBuffer_recvHandleFromUnixSocket( buffer_fd, &ahb ); + close( buffer_fd ); if (ret) return ret; if (win->buffers[res.buffer_id].self) @@ -1817,7 +1759,7 @@ int ioctl_set_cursor( int id, int width, int height, */ void ANDROID_SetDesktopWindow( HWND hwnd ) { - if (!is_in_desktop_process()) + if (!in_desktop_process) return; TRACE( "%p\n", hwnd ); desktop_window = hwnd; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10569