From 6c587a5899e7d0f45a5d0de5450d86022cd73353 Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Wed, 26 Jun 2019 15:41:11 -0400 Subject: [PATCH] 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: Aleksey Kliger --- support/nl.c | 22 +++++++++++----------- support/nl.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/support/nl.c b/support/nl.c index 88babdae391..4608700cab7 100644 --- a/support/nl.c +++ b/support/nl.c @@ -163,7 +163,7 @@ value_to_name (value2name_t *tbl, int value) } #endif /* NL_DEBUG */ -int +gpointer CreateNLSocket (void) { int sock; @@ -177,12 +177,12 @@ CreateNLSocket (void) ret |= O_NONBLOCK; ret = fcntl (sock, F_SETFL, ret); if (ret < 0) - return -1; + return GINT_TO_POINTER (-1); } memset (&sa, 0, sizeof (sa)); if (sock < 0) - return -1; + return GINT_TO_POINTER (-1); sa.nl_family = AF_NETLINK; sa.nl_pid = getpid (); sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_NOTIFY; @@ -190,9 +190,9 @@ CreateNLSocket (void) * RTMGRP_LINK */ if (bind (sock, (struct sockaddr *) &sa, sizeof (sa)) < 0) - return -1; + return GINT_TO_POINTER (-1); - return sock; + return GINT_TO_POINTER (sock); } int @@ -359,10 +359,10 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size) return result; } -int +gpointer CloseNLSocket (gpointer sock) { - return close (GPOINTER_TO_INT (sock)); + return GINT_TO_POINTER (close (GPOINTER_TO_INT (sock))); } #else int @@ -377,16 +377,16 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size) return 0; } -int +gpointer CreateNLSocket (void) { - return -1; + return GINT_TO_POINTER (-1); } -int +gpointer CloseNLSocket (gpointer sock) { - return -1; + return GINT_TO_POINTER (-1); } #endif /* linux/netlink.h + linux/rtnetlink.h */ diff --git a/support/nl.h b/support/nl.h index 4a464266382..ae9605fd487 100644 --- a/support/nl.h +++ b/support/nl.h @@ -3,9 +3,9 @@ #include G_BEGIN_DECLS -int CreateNLSocket (void); +gpointer CreateNLSocket (void); int ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size); -int CloseNLSocket (gpointer sock); +gpointer CloseNLSocket (gpointer sock); G_END_DECLS #endif -- GitLab