提交 6c587a58 编写于 作者: R Ryan Lucia 提交者: ramanbs-rythmos

CreateNLSocket and CloseNLSocket should return gpointer (#15408)

In managed, these functions are used as `static external IntPtr`. This means that previously on arm64 the top bits of the return value were garbage. A comparison with 64-bit -1 like in LinuxNetworkChange.EnsureSocket would never be true, which was causing us to hit other assertions in the runtime.
Co-authored-by: NAleksey Kliger <alklig@microsoft.com>
上级 1ffd4e7b
...@@ -163,7 +163,7 @@ value_to_name (value2name_t *tbl, int value) ...@@ -163,7 +163,7 @@ value_to_name (value2name_t *tbl, int value)
} }
#endif /* NL_DEBUG */ #endif /* NL_DEBUG */
int gpointer
CreateNLSocket (void) CreateNLSocket (void)
{ {
int sock; int sock;
...@@ -177,12 +177,12 @@ CreateNLSocket (void) ...@@ -177,12 +177,12 @@ CreateNLSocket (void)
ret |= O_NONBLOCK; ret |= O_NONBLOCK;
ret = fcntl (sock, F_SETFL, ret); ret = fcntl (sock, F_SETFL, ret);
if (ret < 0) if (ret < 0)
return -1; return GINT_TO_POINTER (-1);
} }
memset (&sa, 0, sizeof (sa)); memset (&sa, 0, sizeof (sa));
if (sock < 0) if (sock < 0)
return -1; return GINT_TO_POINTER (-1);
sa.nl_family = AF_NETLINK; sa.nl_family = AF_NETLINK;
sa.nl_pid = getpid (); sa.nl_pid = getpid ();
sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_NOTIFY; sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_NOTIFY;
...@@ -190,9 +190,9 @@ CreateNLSocket (void) ...@@ -190,9 +190,9 @@ CreateNLSocket (void)
* RTMGRP_LINK */ * RTMGRP_LINK */
if (bind (sock, (struct sockaddr *) &sa, sizeof (sa)) < 0) if (bind (sock, (struct sockaddr *) &sa, sizeof (sa)) < 0)
return -1; return GINT_TO_POINTER (-1);
return sock; return GINT_TO_POINTER (sock);
} }
int int
...@@ -359,10 +359,10 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size) ...@@ -359,10 +359,10 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size)
return result; return result;
} }
int gpointer
CloseNLSocket (gpointer sock) CloseNLSocket (gpointer sock)
{ {
return close (GPOINTER_TO_INT (sock)); return GINT_TO_POINTER (close (GPOINTER_TO_INT (sock)));
} }
#else #else
int int
...@@ -377,16 +377,16 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size) ...@@ -377,16 +377,16 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size)
return 0; return 0;
} }
int gpointer
CreateNLSocket (void) CreateNLSocket (void)
{ {
return -1; return GINT_TO_POINTER (-1);
} }
int gpointer
CloseNLSocket (gpointer sock) CloseNLSocket (gpointer sock)
{ {
return -1; return GINT_TO_POINTER (-1);
} }
#endif /* linux/netlink.h + linux/rtnetlink.h */ #endif /* linux/netlink.h + linux/rtnetlink.h */
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
#include <glib.h> #include <glib.h>
G_BEGIN_DECLS G_BEGIN_DECLS
int CreateNLSocket (void); gpointer CreateNLSocket (void);
int ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size); int ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size);
int CloseNLSocket (gpointer sock); gpointer CloseNLSocket (gpointer sock);
G_END_DECLS G_END_DECLS
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册