[PATCH v3 0/1] MR1626: kernelbase: Workaround for linux-side redirection.
Patch from @bernhardu Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51813 ``` 1016195.340:0114:0118:Call KERNEL32.GetFileType(00000014) ret=1022e621 1016195.340:0114:0118:Call ntdll.NtQueryVolumeInformationFile(00000014,0060f598,0060f590,00000008,00000004) ret=7b01f4a5 1016195.340:0114:0118:Ret ntdll.NtQueryVolumeInformationFile() retval=00000000 ret=7b01f4a5 1016195.340:0114:0118:Ret KERNEL32.GetFileType() retval=00000001 ret=1022e621 1016195.340:0114:0118:Call KERNEL32.GetFileInformationByHandle(00000014,0060f608) ret=1022e6ac 1016195.340:0114:0118:Call ntdll.NtQueryInformationFile(00000014,0060f508,0060f528,00000068,00000012) ret=7b01eacc 1016195.340:0114:0118:trace:file:NtQueryInformationFile (0x14,0x60f508,0x60f528,0x00000068,0x00000012) 1016195.340:0114:0118:Ret ntdll.NtQueryInformationFile() retval=c0000024 ret=7b01eacc 1016195.340:0114:0118:Call ntdll.RtlNtStatusToDosError(c0000024) ret=7b01eae3 1016195.340:0114:0118:Ret ntdll.RtlNtStatusToDosError() retval=00000006 ret=7b01eae3 1016195.340:0114:0118:Ret KERNEL32.GetFileInformationByHandle() retval=00000000 ret=1022e6ac ``` Allocation of the fd structure, fd->unix_name is set to NULL: ``` 1697 fd->unix_name = NULL; #0 alloc_fd_object () at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/fd.c:1697 #1 0x000056259dd386d8 in create_anonymous_fd (fd_user_ops=fd_user_ops(a)entry=0x56259dda4900 <file_fd_ops>, unix_fd=unix_fd(a)entry=28, user=user(a)entry=0x56259f42db70, options=options(a)entry=32) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/fd.c:2074 #2 0x000056259dd3b477 in create_file_for_fd (fd=28, access=1074790400, sharing=sharing(a)entry=3) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/file.c:152 #3 0x000056259dd3b874 in req_alloc_file_handle (req=0x56259f27b768, reply=0x7ffc518872e0) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/file.c:730 #4 0x000056259dd594b3 in call_req_handler (thread=thread(a)entry=0x56259f27b620) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/request.c:309 ``` Because unix_name is not set no file information get returned: ``` 2780 if (fd->unix_name) #0 req_get_handle_unix_name (req=<optimized out>, reply=0x7ffc518872e0) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/fd.c:2780 #1 0x000056259dd594b3 in call_req_handler (thread=thread(a)entry=0x56259f432020) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/server/request.c:309 ... #0 wine_server_call (req_ptr=0x62fac0) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/dlls/ntdll/unix/server.c:286 #1 0xf7b98514 in server_get_unix_name (handle=handle(a)entry=0x14, unix_name=unix_name(a)entry=0x62fb94) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/dlls/ntdll/unix/file.c:1776 #2 0xf7ba3b1f in NtQueryInformationFile (handle=0x14, io=0x60f568, ptr=0x60f588, len=104, class=FileAllInformation) at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/dlls/ntdll/unix/file.c:4177 #3 0xf7bbd679 in __wine_syscall_dispatcher () at /home/bernhard/data/entwicklung/2021/wine/wine-git/wine-git/dlls/ntdll/unix/signal_i386.c:153 ... ``` https://github.com/python/cpython/blob/99fcf1505218464c489d419d4500f126b6d6d... https://github.com/python/cpython/blob/99fcf1505218464c489d419d4500f126b6d6d... -- v3: kernelbase: Workaround for linux-side redirection. https://gitlab.winehq.org/wine/wine/-/merge_requests/1626
From: Bernhard Ubelacker <bernhardu(a)mailbox.org> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51813 ---- 1016195.340:0114:0118:Call KERNEL32.GetFileType(00000014) ret=1022e621 1016195.340:0114:0118:Call ntdll.NtQueryVolumeInformationFile(00000014,0060f598,0060f590,00000008,00000004) ret=7b01f4a5 1016195.340:0114:0118:Ret ntdll.NtQueryVolumeInformationFile() retval=00000000 ret=7b01f4a5 1016195.340:0114:0118:Ret KERNEL32.GetFileType() retval=00000001 ret=1022e621 1016195.340:0114:0118:Call KERNEL32.GetFileInformationByHandle(00000014,0060f608) ret=1022e6ac 1016195.340:0114:0118:Call ntdll.NtQueryInformationFile(00000014,0060f508,0060f528,00000068,00000012) ret=7b01eacc 1016195.340:0114:0118:trace:file:NtQueryInformationFile (0x14,0x60f508,0x60f528,0x00000068,0x00000012) 1016195.340:0114:0118:Ret ntdll.NtQueryInformationFile() retval=c0000024 ret=7b01eacc 1016195.340:0114:0118:Call ntdll.RtlNtStatusToDosError(c0000024) ret=7b01eae3 1016195.340:0114:0118:Ret ntdll.RtlNtStatusToDosError() retval=00000006 ret=7b01eae3 1016195.340:0114:0118:Ret KERNEL32.GetFileInformationByHandle() retval=00000000 ret=1022e6ac Allocation of the fd structure, fd->unix_name is set to NULL: 1697 fd->unix_name = NULL; Because unix_name is not set no file information get returned: 2780 if (fd->unix_name) ... ... https://github.com/python/cpython/blob/99fcf1505218464c489d419d4500f126b6d6d... https://github.com/python/cpython/blob/99fcf1505218464c489d419d4500f126b6d6d... --- dlls/kernelbase/file.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c index ac04388acde..badb769edcd 100644 --- a/dlls/kernelbase/file.c +++ b/dlls/kernelbase/file.c @@ -2926,9 +2926,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetFileInformationByHandle( HANDLE file, BY_HANDLE FILE_ALL_INFORMATION all_info; IO_STATUS_BLOCK io; NTSTATUS status; + DWORD mode; status = NtQueryInformationFile( file, &io, &all_info, sizeof(all_info), FileAllInformation ); if (status == STATUS_BUFFER_OVERFLOW) status = STATUS_SUCCESS; + if (status == STATUS_OBJECT_TYPE_MISMATCH && GetFileType(file) == FILE_TYPE_DISK && !GetConsoleMode(file, &mode)) + { + ERR("Workaround for redirection at unix side. Bug#51813\n"); + memset(info, 0, sizeof(*info)); + return TRUE; + } if (!set_ntstatus( status )) return FALSE; info->dwFileAttributes = all_info.BasicInformation.FileAttributes; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/1626
- indeed python print does not work inside cmd: `wine python -c 'print(4)'` works, but `wine cmd /C "python -c 'print(4)'"` does not print anything, but wine cmd /C "python -V" works, investigating... - ok, I added the GetConsoleMode check for that case -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18244
hmm I did not expect GetConsoleMode to fail: another shell console quirk :-( maybe would this work better: ``` #include "condrv.h" .... /* detect shell console handle, and don't return an error */ if (status == STATUS_OBJECT_TYPE_MISMATCH) { IO_STATUS_BLOCK io; if (!NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io, IOCTL_CONDRV_IS_UNIX, NULL, 0, NULL, 0 )) { WARN("Workaround for redirection at unix side.\n"); memset(info, 0, sizeof(*info)); return TRUE; } } ``` -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18259
@eric the problem in cmd I mentioned was a syntax error about the quotes, else `wine cmd /C "python -c print(4)"` works fine, so does redirecting to a file what did you mean by failing when running in shell console ? if its unrelated to GetFileInformationByHandle it could be treated separately from this MR -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18261
On Thu Dec 1 15:22:03 2022 +0000, Michel Zou wrote:
@eric the problem in cmd I mentioned was a syntax error about the quotes, else `wine cmd /C "python -c print(4)"` works fine, so does redirecting to a file what did you mean by failing when running in shell console ? if its unrelated to GetFileInformationByHandle it could be treated separately from this MR by shell console I mean the mode where wine is using unix's shell console as input / output handles for the running wine program their file type is FILE_TYPE_DISK (as mapped to a unix fd) unlike 'real' console handles (which type is FILE_TYPE_CHAR)
running 'wine foo.exe' from unix shell command line will use shell console running 'wine wineconsole foo.exe' from unix shell will run foo.exe with fully pledged console handles HTH -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18263
On Thu Dec 1 16:31:44 2022 +0000, eric pouech wrote:
hmm I did not expect GetConsoleMode to fail: another shell console quirk :-( maybe would this work better: ``` #include "condrv.h" .... /* detect shell console handle, and don't return an error */ if (status == STATUS_OBJECT_TYPE_MISMATCH) { IO_STATUS_BLOCK io; if (!NtDeviceIoControlFile( handle, NULL, NULL, NULL, &io, IOCTL_CONDRV_IS_UNIX, NULL, 0, NULL, 0 )) { WARN("Workaround for redirection at unix side.\n"); memset(info, 0, sizeof(*info)); return TRUE; } } ``` no, it does not go into the `if (!NtDeviceIoControlFile...)` condition
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18273
On Thu Dec 1 15:22:03 2022 +0000, eric pouech wrote:
by shell console I mean the mode where wine is using unix's shell console as input / output handles for the running wine program their file type is FILE_TYPE_DISK (as mapped to a unix fd) unlike 'real' console handles (which type is FILE_TYPE_CHAR) running 'wine foo.exe' from unix shell command line will use shell console running 'wine wineconsole foo.exe' from unix shell will run foo.exe with fully pledged console handles HTH indeed `wine wineconsole python -V` returns 0 but does not print anything
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18274
On Thu Dec 1 16:31:43 2022 +0000, Michel Zou wrote:
no, it does not go into the `if (!NtDeviceIoControlFile...)` condition could describe which command you use to test this?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18292
On Thu Dec 1 16:52:13 2022 +0000, Michel Zou wrote:
indeed `wine wineconsole python -V` returns 0 but does not print anything wait, that's not specific to python, I cannot make it work with a simple C printf executable either perhaps, when running with wineconsole, a window appears, but closes immediately (as it closes when child program terminates)
if its the case, running with 'wine wineconsole cmd' will open a new console window, in which you can launch your programs -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18293
On Thu Dec 1 18:23:19 2022 +0000, eric pouech wrote:
could describe which command you use to test this? still with the python example, but I should have mentioned that I was using wine inside a docker image not on bare metal, maybe that adds an extra layer of complexity
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18298
On Thu Dec 1 18:27:01 2022 +0000, eric pouech wrote:
perhaps, when running with wineconsole, a window appears, but closes immediately (as it closes when child program terminates) if its the case, running with 'wine wineconsole cmd' will open a new console window, in which you can launch your programs oh, right, I dont have an X server inside my docker image so maybe that's why it doesnt show up
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18299
On Fri Dec 2 12:42:11 2022 +0000, Michel Zou wrote:
oh, right, with docker I should not expect to see anything then yes wineconsole requires a graphical driver (like x11) does the attached patch works better?
[patch](/uploads/89a9f6cabd5e3a9a15f4720861e2f526/patch) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18461
On Fri Dec 2 16:56:36 2022 +0000, eric pouech wrote:
yes wineconsole requires a graphical driver (like x11) does the attached patch works better? [patch](/uploads/89a9f6cabd5e3a9a15f4720861e2f526/patch) "wine wineconsole python" runs fine, I can type commands, printf stuff etc...
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18488
your patch fixes the issue, I close this MR and let you submit it -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626#note_18550
This merge request was closed by Michel Zou. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/1626
participants (3)
-
Bernhard Ubelacker -
eric pouech (@epo) -
Michel Zou (@xantares)