Signed-off-by: Zebediah Figura z.figura12@gmail.com --- This is a native, undocumented ioctl which can be called on Windows TCP sockets. Unlike some others (which I intend to submit later), no known application uses this ioctl, but as it matches closely an ioctl which is useful for Wine, I have reverse-engineered and implemented it anyway.
This marks the first of several native ioctls which I have made use of when moving socket code to ntdll and wineserver. For more details on AFD reverse-engineering, please see [1].
I have not included tests for this ioctl. Unfortunately calling accept() on such a socket fails (calling the ioctl equivalent succeeds, but unfortunately this is not trivial to implement or use.) It seems likely that listen() is setting some user-mode state.
[1] https://wiki.winehq.org/AFD
include/wine/afd.h | 9 +++++++++ server/sock.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/include/wine/afd.h b/include/wine/afd.h index a711fba23a5..e890020ca88 100644 --- a/include/wine/afd.h +++ b/include/wine/afd.h @@ -24,6 +24,15 @@ #include <winioctl.h> #include "wine/server_protocol.h"
+#define IOCTL_AFD_LISTEN CTL_CODE(FILE_DEVICE_BEEP, 0x802, METHOD_NEITHER, FILE_ANY_ACCESS) + +struct afd_listen_params +{ + int unknown1; + int backlog; + int unknown2; +}; + #define IOCTL_AFD_WINE_CREATE CTL_CODE(FILE_DEVICE_NETWORK, 200, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_AFD_WINE_ACCEPT CTL_CODE(FILE_DEVICE_NETWORK, 201, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_AFD_WINE_ACCEPT_INTO CTL_CODE(FILE_DEVICE_NETWORK, 202, METHOD_BUFFERED, FILE_ANY_ACCESS) diff --git a/server/sock.c b/server/sock.c index dadcc607fbb..945895b51a4 100644 --- a/server/sock.c +++ b/server/sock.c @@ -1354,10 +1354,11 @@ static struct accept_req *alloc_accept_req( struct sock *sock, struct sock *acce static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) { struct sock *sock = get_fd_user( fd ); + int unix_fd;
assert( sock->obj.ops == &sock_ops );
- if (code != IOCTL_AFD_WINE_CREATE && get_unix_fd( fd ) < 0) return 0; + if (code != IOCTL_AFD_WINE_CREATE && (unix_fd = get_unix_fd( fd )) < 0) return 0;
switch(code) { @@ -1459,6 +1460,32 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) return 1; }
+ case IOCTL_AFD_LISTEN: + { + const struct afd_listen_params *params = get_req_data(); + + if (get_req_data_size() < sizeof(*params)) + { + set_error( STATUS_INVALID_PARAMETER ); + return 0; + } + + if (listen( unix_fd, params->backlog ) < 0) + { + set_error( sock_get_ntstatus( errno ) ); + return 0; + } + + sock->pending_events &= ~FD_ACCEPT; + sock->reported_events &= ~FD_ACCEPT; + sock->state |= FD_WINE_LISTENING; + sock->state &= ~(FD_CONNECT | FD_WINE_CONNECTED); + + /* we may already be selecting for FD_ACCEPT */ + sock_reselect( sock ); + return 0; + } + case IOCTL_AFD_WINE_ADDRESS_LIST_CHANGE: if ((sock->state & FD_WINE_NONBLOCKING) && async_is_blocking( async )) {