From: Twaik Yont <9674930+twaik@users.noreply.github.com> Pass the client pid explicitly through ioctl_android_dequeueBuffer instead of relying on thread-local driver_data propagation. The pid is only required for handle duplication in dequeueBuffer, so there is no need to thread it through the generic ioctl dispatch path or Java window management calls. This simplifies the dispatch path and makes pid usage explicit at the single call site that requires it. This also prepares the code for execution without a Wine TEB, where thread-local state and helpers like wine_server_fd_to_handle will not be available. Signed-off-by: Twaik Yont <9674930+twaik@users.noreply.github.com> --- dlls/wineandroid.drv/WineActivity.java | 12 ++++++------ dlls/wineandroid.drv/device.c | 27 +++++++++----------------- dlls/wineandroid.drv/dllmain.c | 3 +-- dlls/wineandroid.drv/unixlib.h | 8 -------- 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/dlls/wineandroid.drv/WineActivity.java b/dlls/wineandroid.drv/WineActivity.java index 3bb27c13f93..6488188b93a 100644 --- a/dlls/wineandroid.drv/WineActivity.java +++ b/dlls/wineandroid.drv/WineActivity.java @@ -782,7 +782,7 @@ public void create_desktop_view() wine_config_changed( getResources().getConfiguration().densityDpi ); } - public void create_window( int hwnd, boolean is_desktop, boolean opengl, int parent, int pid ) + public void create_window( int hwnd, boolean is_desktop, boolean opengl, int parent ) { WineWindow win = get_window( hwnd ); if (win == null) @@ -806,7 +806,7 @@ public void destroy_window( int hwnd ) if (win != null) win.destroy(); } - public void set_window_parent( int hwnd, int parent, int pid ) + public void set_window_parent( int hwnd, int parent ) { WineWindow win = get_window( hwnd ); if (win == null) return; @@ -839,9 +839,9 @@ public void createDesktopView() runOnUiThread( new Runnable() { public void run() { create_desktop_view(); }} ); } - public void createWindow( final int hwnd, final boolean is_desktop, final boolean opengl, final int parent, final int pid ) + public void createWindow( final int hwnd, final boolean is_desktop, final boolean opengl, final int parent ) { - runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent ); }} ); } public void destroyWindow( final int hwnd ) @@ -849,9 +849,9 @@ public void destroyWindow( final int hwnd ) runOnUiThread( new Runnable() { public void run() { destroy_window( hwnd ); }} ); } - public void setParent( final int hwnd, final int parent, final int pid ) + public void setParent( final int hwnd, final int parent ) { - runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent ); }} ); } public void setCursor( final int id, final int width, final int height, diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 570aab818ab..0032224560d 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -143,6 +143,7 @@ struct ioctl_android_dequeueBuffer { struct ioctl_header hdr; HANDLE handle; + DWORD pid; int buffer_id; int generation; }; @@ -209,12 +210,6 @@ static inline BOOL is_in_desktop_process(void) return thread != NULL; } -static inline DWORD current_client_id(void) -{ - DWORD client_id = NtUserGetThreadInfo()->driver_data; - return client_id ? client_id : GetCurrentProcessId(); -} - #ifdef __i386__ /* the Java VM uses %fs/%gs for its own purposes, so we need to wrap the calls */ static WORD orig_fs, java_fs; @@ -561,7 +556,6 @@ static NTSTATUS createWindow_ioctl( void *data, DWORD in_size, DWORD out_size, U jobject object; struct ioctl_android_create_window *res = data; struct native_win_data *win_data; - DWORD pid = current_client_id(); if (in_size < sizeof(*res)) return STATUS_INVALID_PARAMETER; @@ -570,10 +564,10 @@ static NTSTATUS createWindow_ioctl( void *data, DWORD in_size, DWORD out_size, U TRACE( "hwnd %08x opengl %u parent %08x\n", res->hdr.hwnd, res->hdr.opengl, res->parent ); - if (!(object = load_java_method( &method, "createWindow", "(IZZII)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "createWindow", "(IZZI)V" ))) return STATUS_NOT_SUPPORTED; wrap_java_call(); - (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->is_desktop, res->hdr.opengl, res->parent, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->is_desktop, res->hdr.opengl, res->parent ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -671,7 +665,7 @@ static NTSTATUS dequeueBuffer_ioctl( void *data, DWORD in_size, DWORD out_size, int sv[2] = { -1, -1 }; HANDLE local = 0; OBJECT_ATTRIBUTES attr = { .Length = sizeof(attr) }; - CLIENT_ID cid = { .UniqueProcess = UlongToHandle( current_client_id() ) }; + CLIENT_ID cid = { .UniqueProcess = UlongToHandle( res->pid ) }; HANDLE process; if (!ahb) @@ -901,7 +895,6 @@ static NTSTATUS setWindowParent_ioctl( void *data, DWORD in_size, DWORD out_size jobject object; struct ioctl_android_set_window_parent *res = data; struct native_win_data *win_data; - DWORD pid = current_client_id(); if (in_size < sizeof(*res)) return STATUS_INVALID_PARAMETER; @@ -909,10 +902,10 @@ static NTSTATUS setWindowParent_ioctl( void *data, DWORD in_size, DWORD out_size TRACE( "hwnd %08x parent %08x\n", res->hdr.hwnd, res->parent ); - if (!(object = load_java_method( &method, "setParent", "(III)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "setParent", "(II)V" ))) return STATUS_NOT_SUPPORTED; wrap_java_call(); - (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -988,8 +981,7 @@ static const ioctl_func ioctl_funcs[] = NTSTATUS android_dispatch_ioctl( void *arg ) { - struct ioctl_params *params = arg; - IRP *irp = params->irp; + IRP *irp = arg; IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation( irp ); DWORD code = (irpsp->Parameters.DeviceIoControl.IoControlCode - ANDROID_IOCTL(0)) >> 2; @@ -1002,11 +994,9 @@ NTSTATUS android_dispatch_ioctl( void *arg ) if (in_size >= sizeof(*header)) { irp->IoStatus.Information = 0; - NtUserGetThreadInfo()->driver_data = params->client_id; irp->IoStatus.Status = func( irp->AssociatedIrp.SystemBuffer, in_size, irpsp->Parameters.DeviceIoControl.OutputBufferLength, &irp->IoStatus.Information ); - NtUserGetThreadInfo()->driver_data = 0; } else irp->IoStatus.Status = STATUS_INVALID_PARAMETER; } @@ -1105,11 +1095,12 @@ static int dequeueBuffer( struct ANativeWindow *window, struct ANativeWindowBuff 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, sizeof(res.hdr), &res, &size ); + ret = android_ioctl( IOCTL_DEQUEUE_BUFFER, &res, size, &res, &size ); if (ret) return ret; if (size < sizeof(res)) return -EINVAL; diff --git a/dlls/wineandroid.drv/dllmain.c b/dlls/wineandroid.drv/dllmain.c index d9cd94338a0..7f6d04e83df 100644 --- a/dlls/wineandroid.drv/dllmain.c +++ b/dlls/wineandroid.drv/dllmain.c @@ -37,8 +37,7 @@ static HANDLE stop_event; static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp ) { - struct ioctl_params params = { .irp = irp, .client_id = HandleToUlong(PsGetCurrentProcessId()) }; - NTSTATUS status = ANDROID_CALL( dispatch_ioctl, ¶ms ); + NTSTATUS status = ANDROID_CALL( dispatch_ioctl, irp ); IoCompleteRequest( irp, IO_NO_INCREMENT ); return status; } diff --git a/dlls/wineandroid.drv/unixlib.h b/dlls/wineandroid.drv/unixlib.h index 46c59f8f201..39a4df58283 100644 --- a/dlls/wineandroid.drv/unixlib.h +++ b/dlls/wineandroid.drv/unixlib.h @@ -39,14 +39,6 @@ struct init_params }; -/* android_ioctl params */ -struct ioctl_params -{ - struct _IRP *irp; - DWORD client_id; -}; - - /* android_register_window params */ struct register_window_params { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10690