Skip to content

Commit a4d1f6c

Browse files
CoffeeFluxlambdageek
authored andcommitted
CreateNLSocket and CloseNLSocket should return gpointer (mono#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 <[email protected]>
1 parent b8ea873 commit a4d1f6c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

support/nl.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ value_to_name (value2name_t *tbl, int value)
163163
}
164164
#endif /* NL_DEBUG */
165165

166-
int
166+
gpointer
167167
CreateNLSocket (void)
168168
{
169169
int sock;
@@ -177,22 +177,22 @@ CreateNLSocket (void)
177177
ret |= O_NONBLOCK;
178178
ret = fcntl (sock, F_SETFL, ret);
179179
if (ret < 0)
180-
return -1;
180+
return GINT_TO_POINTER (-1);
181181
}
182182

183183
memset (&sa, 0, sizeof (sa));
184184
if (sock < 0)
185-
return -1;
185+
return GINT_TO_POINTER (-1);
186186
sa.nl_family = AF_NETLINK;
187187
sa.nl_pid = getpid ();
188188
sa.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_NOTIFY;
189189
/* RTNLGRP_IPV4_IFADDR | RTNLGRP_IPV6_IFADDR
190190
* RTMGRP_LINK */
191191

192192
if (bind (sock, (struct sockaddr *) &sa, sizeof (sa)) < 0)
193-
return -1;
193+
return GINT_TO_POINTER (-1);
194194

195-
return sock;
195+
return GINT_TO_POINTER (sock);
196196
}
197197

198198
int
@@ -359,10 +359,10 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size)
359359
return result;
360360
}
361361

362-
int
362+
gpointer
363363
CloseNLSocket (gpointer sock)
364364
{
365-
return close (GPOINTER_TO_INT (sock));
365+
return GINT_TO_POINTER (close (GPOINTER_TO_INT (sock)));
366366
}
367367
#else
368368
int
@@ -377,16 +377,16 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size)
377377
return 0;
378378
}
379379

380-
int
380+
gpointer
381381
CreateNLSocket (void)
382382
{
383-
return -1;
383+
return GINT_TO_POINTER (-1);
384384
}
385385

386-
int
386+
gpointer
387387
CloseNLSocket (gpointer sock)
388388
{
389-
return -1;
389+
return GINT_TO_POINTER (-1);
390390
}
391391
#endif /* linux/netlink.h + linux/rtnetlink.h */
392392

support/nl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <glib.h>
44

55
G_BEGIN_DECLS
6-
int CreateNLSocket (void);
6+
gpointer CreateNLSocket (void);
77
int ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size);
8-
int CloseNLSocket (gpointer sock);
8+
gpointer CloseNLSocket (gpointer sock);
99
G_END_DECLS
1010

1111
#endif

0 commit comments

Comments
 (0)