Fix sporadic failures in MonoTests.System.Net.HttpRequestStreamTest on x64 Windows.
authorlateralusX <lateralusx.github@gmail.com>
Thu, 14 Sep 2017 09:06:38 +0000 (11:06 +0200)
committerlateralusX <lateralusx.github@gmail.com>
Thu, 14 Sep 2017 09:06:38 +0000 (11:06 +0200)
MonoTests.System.Net.HttpRequestStreamTest suite has sporadic failures on Windows x64
with following exception:

System.Net.Sockets.SocketException : An operation was attempted on something that is not a socket.

This happens due to a data type and constant size mismatch. w32socket.h defines
INVALID_SOCKET and SOCKET_ERROR for all platforms. On Windows x64, SOCKET is defined
by winsock2.h as 64-bit type as well as INVALID_SOCKET constant, but above code will
define INVALID_SOCKET as a 32-bit constant value. This will in turn cause code to sporadically
fail to detect invalid sockets as returned by win32 API's. This will in turn cause the socket
exception when code continues to use socket as argument to win32 socket API’s.

Current “invalid” x64 codegen for expression:

if (sock == INVALID_SOCKET)

mov         eax,0FFFFFFFFh
cmp         rsi,rax

and with fixed defines, correct 64-bit cmp instruction:

cmp         rsi,0FFFFFFFFFFFFFFFFh

Fix makes sure we get the defines of INVALID_SOCKET and SOCKET_ERROR from winsock2.h
on Windows platforms to be consistent with define of SOCKET type.

mono/metadata/w32socket.h

index 5d5aa4adc53b472f35e448cf21e01bacc80e1829..b03ac936738b3a38ed3d8a0d430e1c160baa1ffd 100644 (file)
 
 #include <mono/metadata/object-internals.h>
 
+#ifndef HOST_WIN32
 #define INVALID_SOCKET ((SOCKET)(guint32)(~0))
 #define SOCKET_ERROR (-1)
 
-#ifndef HOST_WIN32
 typedef gint SOCKET;
 
 typedef struct {