failed to park: Os { code: 66, kind: Uncategorized, message: "Bad device type." }
xNxExOx opened this issue · 4 comments
Version
$ cargo tree | grep tokio
│ └── tokio-util v0.7.3
│ ├── tokio v1.19.2
├── tokio v1.19.2 (*)
├── tokio-rustls v0.23.4
│ ├── tokio v1.19.2 (*)
├── tokio-util v0.7.3 (*)
Platform
MINGW64_NT-10.0-19044 DESKTOP-ITVHNK7 3.0.7-338.x86_64 2019-11-21 23:07 UTC x86_64 Msys
but targeting nightly-i686-pc-windows-msvc
Description
Connecting to server panic under wine.
I tried this code:
info!("forge_connect");
let address: SocketAddr = "127.0.0.1:7401".parse().unwrap();
let socket = match tokio::net::TcpStream::connect(address).await {
Ok(s) => s,
Err(e) => {
error!("launcher connecting error 1: {}", e);
this.disconnect();
return false;
}
};
info!("TcpStream connect OK");
result handling in this code is not relevant because it does not get that far 😞
I expected to see this happen:
connection to the server
Instead, this happened:
it panicked between the two logs
failed to park: Os { code: 66, kind: Uncategorized, message: "Bad device type." }', C:\Users\xxxku\.cargo\registry\src\github.com-1285ae84e5963aae\tokio-1.19.2\src\runtime\basic_scheduler.rs:321:31`
This seems to be the part of the trace where things go wrong:
Wine Log
2270.619:00e4:00e8:Call ntdll.NtCreateFile(039b6d38,00100000,00c0e840,039b6d40,00000000,00000000,74522e6c00000003,6572697500000001,456b636f00000000,00000000,00000000) ret=00a3f1f3
2270.619:00e4:00e8:trace:file:NtCreateFile handle=0x39b6d38 access=00100000 name=L"\\Device\\Afd\\Mio" objattr=00000000 root=(nil) sec=(nil) io=0x39b6d40 alloc_size=(nil) attr=00000000 sharing=00000003 disp=1 options=00000000 ea=(nil).0x00000000
2270.621:00e4:00e8:Ret ntdll.NtCreateFile() retval=00000000 ret=00a3f1f3
2270.621:00e4:00e8:Call KERNEL32.CreateIoCompletionPort(0000007c,00000060,00000002,00000000) ret=00a3e94d
2270.621:00e4:00e8:trace:sync:CreateIoCompletionPort (000000000000007C, 0000000000000060, 00000002, 00000000)
2270.621:00e4:00e8:Call ntdll.NtSetInformationFile(0000007c,039b6b20,039b6b10,00000010,0000001e) ret=7b0768ad
2270.621:00e4:00e8:trace:file:NtSetInformationFile (0x7c,0x39b6b20,0x39b6b10,0x00000010,0x0000001e)
2270.621:00e4:00e8:Ret ntdll.NtSetInformationFile() retval=00000000 ret=7b0768ad
2270.621:00e4:00e8:Ret KERNEL32.CreateIoCompletionPort() retval=00000060 ret=00a3e94d
2270.621:00e4:00e8:Call KERNEL32.SetFileCompletionNotificationModes(0000007c,00000002) ret=00a3f562
2270.621:00e4:00e8:trace:file:NtSetInformationFile (0x7c,0x39b6bd0,0x39b6bcc,0x00000004,0x00000029)
2270.622:00e4:00e8:Ret KERNEL32.SetFileCompletionNotificationModes() retval=00000001 ret=00a3f562
2270.622:00e4:00e8:Call ntdll.RtlAllocateHeap(03ad0000,00000000,00000018) ret=00a26eab
2270.622:00e4:00e8:trace:heap:RtlAllocateHeap heap 0000000003AD0000, flags 0, size 0x18, return 0000000003B58FD0, status 0.
2270.622:00e4:00e8:Ret ntdll.RtlAllocateHeap() retval=03b58fd0 ret=00a26eab
2270.622:00e4:00e8:Call ntdll.RtlAllocateHeap(03ad0000,00000000,00000020) ret=00a26eab
2270.622:00e4:00e8:trace:heap:RtlAllocateHeap heap 0000000003AD0000, flags 0, size 0x20, return 0000000003B59020, status 0.
2270.622:00e4:00e8:Ret ntdll.RtlAllocateHeap() retval=03b59020 ret=00a26eab
2270.622:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b34940) ret=00a4223d
2270.622:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B34940
2270.622:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=00a4223d
2270.622:00e4:00e8:Call ntdll.memset(039b6f38,00000000,00000020) ret=00a40b0b
2270.622:00e4:00e8:Ret ntdll.memset() retval=039b6f38 ret=00a40b0b
2270.622:00e4:00e8:Call ws2_32.WSAIoctl(00000074,48000022,00000000,00000000,039b6e38,00000008,039b6e44,00000000,00000000) ret=00a32314
2270.622:00e4:00e8:trace:winsock:WSAIoctl socket 0x74, _WSAIOR(IOC_WS2, 34), in_buff 0000000000000000, in_size 0, out_buff 00000000039B6E38, out_size 0x8, ret_size 00000000039B6E44, overlapped 0000000000000000, completion 0000000000000000
2270.622:00e4:00e8:Call ntdll.NtDeviceIoControlFile(00000074,00000078,00000000,00000000,039b6bb0,00120348,039b6c90,00000004,00000000,100000000) ret=1ec2bb236
2270.622:00e4:00e8:trace:file:NtDeviceIoControlFile (0x74,0x78,(nil),(nil),0x39b6bb0,0x00120348,0x39b6c90,0x00000004,(nil),0x00000000)
2270.622:00e4:00e8:trace:winsock:sock_ioctl handle 0x74, code 0x120348, in_buffer 0x39b6c90, in_size 4, out_buffer (nil), out_size 0
2270.628:00e4:00e8:Ret ntdll.NtDeviceIoControlFile() retval=00000000 ret=1ec2bb236
2270.628:00e4:00e8:trace:winsock:server_ioctl_sock status 0.
2270.628:00e4:00e8:Call ntdll.RtlNtStatusToDosErrorNoTeb(00000000) ret=1ec2bb1c5
2270.628:00e4:00e8:Ret ntdll.RtlNtStatusToDosErrorNoTeb() retval=00000000 ret=1ec2bb1c5
2270.628:00e4:00e8:Ret ws2_32.WSAIoctl() retval=00000000 ret=00a32314
2270.628:00e4:00e8:Call ntdll.memcpy(039b72c8,039b6ff0,00000060) ret=00a313b8
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b72c8 ret=00a313b8
2270.628:00e4:00e8:Call ntdll.memcpy(039b7048,039b72c8,00000060) ret=00a568cd
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7048 ret=00a568cd
2270.628:00e4:00e8:Call ntdll.memcpy(039b70a8,039b7048,00000060) ret=00a568e5
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b70a8 ret=00a568e5
2270.628:00e4:00e8:Call ntdll.memcpy(039b7260,039b70a8,00000060) ret=00a56901
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7260 ret=00a56901
2270.628:00e4:00e8:Call ntdll.memcpy(039b7328,039b7260,00000060) ret=00a321de
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7328 ret=00a321de
2270.628:00e4:00e8:Call ntdll.memcpy(039b71f8,039b7328,00000060) ret=00a321f9
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b71f8 ret=00a321f9
2270.628:00e4:00e8:Call ntdll.memcpy(039b7030,039b71f8,00000060) ret=00a3d066
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7030 ret=00a3d066
2270.628:00e4:00e8:Call ntdll.memcpy(039b70b8,039b7030,00000060) ret=00a3d081
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b70b8 ret=00a3d081
2270.628:00e4:00e8:Call ntdll.memcpy(039b6fd0,039b70b8,00000060) ret=00a3d099
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b6fd0 ret=00a3d099
2270.628:00e4:00e8:Call ntdll.memcpy(039b7198,039b6fd0,00000060) ret=00a3d0e8
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7198 ret=00a3d0e8
2270.628:00e4:00e8:Call ntdll.memcpy(039b7098,039b7188,00000070) ret=00a5003a
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7098 ret=00a5003a
2270.628:00e4:00e8:Call ntdll.RtlAllocateHeap(03ad0000,00000000,00000080) ret=00a26eab
2270.628:00e4:00e8:trace:heap:RtlAllocateHeap heap 0000000003AD0000, flags 0, size 0x80, return 0000000003B59070, status 0.
2270.628:00e4:00e8:Ret ntdll.RtlAllocateHeap() retval=03b59070 ret=00a26eab
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b59080) ret=00a421cd
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=00a421cd
2270.628:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b59080) ret=00a4223d
2270.628:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B59080
2270.628:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=00a4223d
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b34908) ret=00a421cd
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=00a421cd
2270.628:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b34908) ret=00a4223d
2270.628:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B34908
2270.628:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=00a4223d
2270.628:00e4:00e8:Call ntdll.RtlAllocateHeap(03ad0000,00000000,00000020) ret=00a26eab
2270.628:00e4:00e8:trace:heap:RtlAllocateHeap heap 0000000003AD0000, flags 0, size 0x20, return 0000000003B59120, status 0.
2270.628:00e4:00e8:Ret ntdll.RtlAllocateHeap() retval=03b59120 ret=00a26eab
2270.628:00e4:00e8:Call ntdll.memcpy(039b7da8,039b7b68,00000028) ret=008f845d
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7da8 ret=008f845d
2270.628:00e4:00e8:Call ntdll.memcpy(039b7ca8,039b7da8,00000028) ret=009a87dd
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7ca8 ret=009a87dd
2270.628:00e4:00e8:Call ntdll.memcpy(039b7cd0,039b7ca8,00000028) ret=009a87f2
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7cd0 ret=009a87f2
2270.628:00e4:00e8:Call ntdll.memcpy(039b7d78,039b7cd0,00000028) ret=009a880b
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7d78 ret=009a880b
2270.628:00e4:00e8:Call ntdll.memcpy(039b7de8,039b7d78,00000028) ret=00920f9a
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7de8 ret=00920f9a
2270.628:00e4:00e8:Call ntdll.memcpy(039b7d48,039b7de8,00000028) ret=00920fb2
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7d48 ret=00920fb2
2270.628:00e4:00e8:Call ntdll.memcpy(039b7e38,039b7d48,00000028) ret=00920fca
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7e38 ret=00920fca
2270.628:00e4:00e8:Call ntdll.memcpy(039b7e10,039b7e38,00000028) ret=00920fe5
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7e10 ret=00920fe5
2270.628:00e4:00e8:Call ntdll.memcpy(039b7f58,039b7e10,00000028) ret=00921001
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7f58 ret=00921001
2270.628:00e4:00e8:Call ntdll.memcpy(039b7e08,039b7f58,00000028) ret=009a91ed
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7e08 ret=009a91ed
2270.628:00e4:00e8:Call ntdll.memcpy(039b7e30,039b7e08,00000028) ret=009a9202
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7e30 ret=009a9202
2270.628:00e4:00e8:Call ntdll.memcpy(039b7f28,039b7e30,00000028) ret=009a921b
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039b7f28 ret=009a921b
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b583a8) ret=0091d33d
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=0091d33d
2270.628:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b583a8) ret=0091d3ad
2270.628:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B583A8
2270.628:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=0091d3ad
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b43820) ret=0091d33d
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=0091d33d
2270.628:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b43820) ret=0091d3ad
2270.628:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B43820
2270.628:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=0091d3ad
2270.628:00e4:00e8:Call ntdll.memcpy(039c88b8,03b43d78,00000250) ret=009b5ada
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c88b8 ret=009b5ada
2270.628:00e4:00e8:Call ntdll.memcpy(039c8b08,039c88b8,00000250) ret=009b5af2
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8b08 ret=009b5af2
2270.628:00e4:00e8:Call ntdll.memcpy(039c8d68,039c8b08,00000250) ret=009b5b0d
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8d68 ret=009b5b0d
2270.628:00e4:00e8:Call ntdll.memcpy(039c97f8,039c8d68,00000250) ret=009b5b25
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c97f8 ret=009b5b25
2270.628:00e4:00e8:Call ntdll.memcpy(039c9008,039c92b0,00000250) ret=009b3a2f
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c9008 ret=009b3a2f
2270.628:00e4:00e8:Call ntdll.memcpy(03b43d78,039c9008,00000250) ret=009b9864
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=03b43d78 ret=009b9864
2270.628:00e4:00e8:Call ntdll.memcpy(039c95a8,039c97f8,00000250) ret=0095b584
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c95a8 ret=0095b584
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b42fe0) ret=0091d33d
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=0091d33d
2270.628:00e4:00e8:Call ntdll.RtlReleaseSRWLockExclusive(03b42fe0) ret=0091d3ad
2270.628:00e4:00e8:trace:sync:RtlWakeAddressAll 0000000003B42FE0
2270.628:00e4:00e8:Ret ntdll.RtlReleaseSRWLockExclusive() retval=ffffffff ret=0091d3ad
2270.628:00e4:00e8:Call ntdll.memcpy(039c8b80,039c95e0,00000028) ret=009b65ca
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8b80 ret=009b65ca
2270.628:00e4:00e8:Call ntdll.memcpy(039c8ba8,039c8b80,00000028) ret=009b65df
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8ba8 ret=009b65df
2270.628:00e4:00e8:Call ntdll.memcpy(039c8be0,039c8ba8,00000028) ret=009b65f7
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8be0 ret=009b65f7
2270.628:00e4:00e8:Call ntdll.memcpy(039c8de0,039c8be0,00000028) ret=009b660f
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8de0 ret=009b660f
2270.628:00e4:00e8:Call ntdll.memcpy(039c95e0,039c8c50,00000028) ret=009b9264
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c95e0 ret=009b9264
2270.628:00e4:00e8:Call ntdll.memcpy(039c8db8,039c8de0,00000028) ret=0095b413
2270.628:00e4:00e8:Ret ntdll.memcpy() retval=039c8db8 ret=0095b413
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b34908) ret=00a421cd
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=00a421cd
2270.628:00e4:00e8:Call ntdll.RtlAcquireSRWLockExclusive(03b59080) ret=00a421cd
2270.628:00e4:00e8:Ret ntdll.RtlAcquireSRWLockExclusive() retval=00000001 ret=00a421cd
2270.628:00e4:00e8:Call ntdll.NtDeviceIoControlFile(0000007c,00000000,00000000,03b59080,03b59090,00012024,03b590a0,00000020,03b590a0,00000020) ret=00a3e668
2270.628:00e4:00e8:trace:file:NtDeviceIoControlFile (0x7c,(nil),(nil),0x3b59080,0x3b59090,0x00012024,0x3b590a0,0x00000020,0x3b590a0,0x00000020)
2270.628:00e4:00e8:trace:winsock:sock_ioctl handle 0x7c, code 0x12024, in_buffer 0x3b590a0, in_size 32, out_buffer 0x3b590a0, out_size 32
2270.630:00e4:00e8:Ret ntdll.NtDeviceIoControlFile() retval=c00000cb ret=00a3e668
2270.630:00e4:00e8:Call ntdll.RtlNtStatusToDosError(c00000cb) ret=00a3e693
2270.630:00e4:00e8:Ret ntdll.RtlNtStatusToDosError() retval=00000042 ret=00a3e693
Notice how NtDeviceIoControlFile
returns c00000cb
, which is the error that surfaces as the panic. It also seems to be the L"\\Device\\Afd\\Mio"
file that causes problems. But according to the mio developers, this is a tokio specific problem, so it might be a call in between that configures that file in a particular way in tokio.
Alright, so I've looked a bit into the source code:
NtDeviceIoControlFile
is defined here: dlls/ntdll/unix/file.c#L5700-L5741
The switch case looks at what the file type is, by looking at the bits above the 16th bit of the code. The code is 0x12024
, so that's 0x1
, i.e. FILE_DEVICE_BEEP
, which gets us into sock_ioctl
.
Which we have here: dlls/ntdll/unix/socket.c#L1222
This switches on the full code. According to the mio source code, that's IOCTL_AFD_POLL
: mio src/sys/windows/afd.rs#L80-L91
So that leads us to this branch of the switch: dlls/ntdll/unix/socket.c#L1279-L1281
which returns STATUS_BAD_DEVICE_TYPE
. However that is actually caught by the NtDeviceIoControlFile
function here: dlls/ntdll/unix/file.c#L5735-L5737
where the ioctl seems to be delegated to the server_ioctl_file
instead: dlls/ntdll/unix/file.c#L4875-L4918
This function seems to basically just delegate the call to the wineserver
. So let's look for the equivalent in the server's code.
This one was not that easy to track down, but we basically end up at sock_ioctl
in the server, as it also handles the IOCTL_AFD_POLL
: server/sock.c#L2171
This was a little to complicated, so I grepped for the error code in the whole server folder, to see where it could even come from. There is only one place: server/fd.c#L1744
This is a function for creating a dummy file descriptor that isn't backed by the real file system. It seems like they store an error there in case someone tries to access the actual file descriptor and it's invalid. Which is done in the get_unix_fd
function here: server/fd.c#L2111-L2116
And if we now come back to our sock_ioctl
function in the server, we can see a call to get_unix_fd
that would then error out this way: server/sock.c#L2178
However the condition:
if (code != IOCTL_AFD_WINE_CREATE && (unix_fd = get_unix_fd( fd )) < 0)
is very interesting as it seems like the only way the server even allows coming into here with an artificial file is with an internal IOCTL_AFD_WINE_CREATE
code that likely fixes up the file descriptor so you can properly poll on it.
What's interesting here is that this is indeed an internal code they use to communicate from some other public function to properly create an AFD file descriptor. Let's see what that is.
We end up in WSASocketW
: dlls/ws2_32/socket.c#L3664
This seems to be the only way wine ever accepts creating an AFD file descriptor. Let's see if our logs contain that call... and no, they don't.
(Take all of this with a grain of salt)
So this does indeed seem like the bug is indeed in mio and wine wasn't ever supported, despite their docs and contributors claiming so.
@CryZe It seems to work now under Wine 7.13. They added handling for IOCTL_AFD_POLL
in the condition you pointed out here server/sock.c#L2142
Closing as a bug in wine.