Skip to content

Commit 19bb898

Browse files
authored
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 <alklig@microsoft.com>
1 parent 452fa3b commit 19bb898

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

mono/metadata/icall-decl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ ICALL_EXPORT gint32 ves_icall_System_IO_Compression_DeflateStreamNative_ReadZStr
211211
ICALL_EXPORT gint32 ves_icall_System_IO_Compression_DeflateStreamNative_WriteZStream (gpointer stream, gpointer buffer, gint32 length);
212212
#endif
213213
#if defined(ENABLE_MONODROID)
214-
ICALL_EXPORT gint32 ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CreateNLSocket (void);
214+
ICALL_EXPORT gpointer ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CreateNLSocket (void);
215215
ICALL_EXPORT gint32 ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size);
216-
ICALL_EXPORT gint32 ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CloseNLSocket (gpointer sock);
216+
ICALL_EXPORT gpointer ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CloseNLSocket (gpointer sock);
217217
#endif
218218

219219
#endif // __MONO_METADATA_ICALL_H__

mono/metadata/icall.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -9228,11 +9228,11 @@ ves_icall_System_Environment_get_ProcessorCount (void)
92289228

92299229
#if defined(ENABLE_MONODROID)
92309230

9231-
G_EXTERN_C gint32 CreateNLSocket (void);
9231+
G_EXTERN_C gpointer CreateNLSocket (void);
92329232
G_EXTERN_C gint32 ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size);
9233-
G_EXTERN_C gint32 CloseNLSocket (gpointer sock);
9233+
G_EXTERN_C gpointer CloseNLSocket (gpointer sock);
92349234

9235-
gint32
9235+
gpointer
92369236
ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CreateNLSocket (void)
92379237
{
92389238
return CreateNLSocket ();
@@ -9244,7 +9244,7 @@ ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_ReadEvents (gpointer
92449244
return ReadEvents (sock, buffer, count, size);
92459245
}
92469246

9247-
gint32
9247+
gpointer
92489248
ves_icall_System_Net_NetworkInformation_LinuxNetworkChange_CloseNLSocket (gpointer sock)
92499249
{
92509250
return CloseNLSocket (sock);

support/nl.c

+11-11
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
@@ -371,16 +371,16 @@ ReadEvents (gpointer sock, gpointer buffer, gint32 count, gint32 size)
371371
return 0;
372372
}
373373

374-
int
374+
gpointer
375375
CreateNLSocket (void)
376376
{
377-
return -1;
377+
return GINT_TO_POINTER (-1);
378378
}
379379

380-
int
380+
gpointer
381381
CloseNLSocket (gpointer sock)
382382
{
383-
return -1;
383+
return GINT_TO_POINTER (-1);
384384
}
385385
#endif /* linux/netlink.h + linux/rtnetlink.h */
386386

support/nl.h

+2-2
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)