From: Twaik Yont <9674930+twaik@users.noreply.github.com> Pass the client pid explicitly in ioctl_android_dequeueBuffer and remove the extra client_id plumbing from the ioctl dispatch path. The pid is only needed for dequeueBuffer handle duplication, so there is no need to thread it through ioctl dispatch state or the Java createWindow/setParent calls. This simplifies the dispatch path and makes pid handling explicit at the single call site that requires it. 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 2eee16b2dc1..424f8a6a82e 100644 --- a/dlls/wineandroid.drv/WineActivity.java +++ b/dlls/wineandroid.drv/WineActivity.java @@ -798,7 +798,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, float scale, int pid ) + public void create_window( int hwnd, boolean is_desktop, boolean opengl, int parent, float scale ) { WineWindow win = get_window( hwnd ); if (win == null) @@ -822,7 +822,7 @@ public void destroy_window( int hwnd ) if (win != null) win.destroy(); } - public void set_window_parent( int hwnd, int parent, float scale, int pid ) + public void set_window_parent( int hwnd, int parent, float scale ) { WineWindow win = get_window( hwnd ); if (win == null) return; @@ -855,9 +855,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 float scale, final int pid ) + public void createWindow( final int hwnd, final boolean is_desktop, final boolean opengl, final int parent, final float scale ) { - runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent, scale, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { create_window( hwnd, is_desktop, opengl, parent, scale ); }} ); } public void destroyWindow( final int hwnd ) @@ -865,9 +865,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 float scale, final int pid ) + public void setParent( final int hwnd, final int parent, final float scale ) { - runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent, scale, pid ); }} ); + runOnUiThread( new Runnable() { public void run() { set_window_parent( hwnd, parent, scale ); }} ); } 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 3d77033a980..b3a502bd5cc 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -156,6 +156,7 @@ struct ioctl_android_window_pos_changed struct ioctl_android_dequeueBuffer { struct ioctl_header hdr; + DWORD pid; HANDLE handle; int buffer_id; int generation; @@ -224,12 +225,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; @@ -610,7 +605,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; @@ -619,10 +613,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", "(IZZIFI)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "createWindow", "(IZZIF)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, res->scale, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->is_desktop, res->hdr.opengl, res->parent, res->scale ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -720,7 +714,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) @@ -950,7 +944,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; @@ -958,10 +951,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", "(IIFI)V" ))) return STATUS_NOT_SUPPORTED; + if (!(object = load_java_method( &method, "setParent", "(IIF)V" ))) return STATUS_NOT_SUPPORTED; wrap_java_call(); - (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent, res->scale, pid ); + (*jni_env)->CallVoidMethod( jni_env, object, method, res->hdr.hwnd, res->parent, res->scale ); unwrap_java_call(); return STATUS_SUCCESS; } @@ -1037,8 +1030,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; @@ -1051,11 +1043,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; } @@ -1158,11 +1148,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/10569