Skip to content

Commit 5157eba

Browse files
committed
Replace some problematic platform specific codepaths with intrinsics in runtime. (case 1022228)
1 parent f1f0587 commit 5157eba

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

mcs/class/System/System.Net.NetworkInformation/IPGlobalProperties.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ public override string DomainName {
163163
}
164164
#endif
165165

166+
#if UNITY
167+
sealed class UnixNoLibCIPGlobalProperties : UnixIPGlobalProperties
168+
{
169+
public override string DomainName {
170+
get {
171+
return String.Empty;
172+
}
173+
}
174+
}
175+
#endif
176+
166177
// It expects /proc/net/snmp (or /usr/compat/linux/proc/net/snmp),
167178
// formatted like:
168179
// http://www.linuxdevcenter.com/linux/2000/11/16/example5.html

mcs/class/System/System/Platform.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ private static void CheckOS() {
7979
}
8080
#endif
8181

82+
// UNITY: runtime replaces this with intrinsic
8283
public static bool IsMacOS {
8384
get {
8485
if (!checkedOS)
8586
#if UNITY
8687
try {
8788
CheckOS();
8889
}
89-
catch (DllNotFoundException e) {
90+
catch (DllNotFoundException) {
9091
// libc does not exist, so this is not MacOS
9192
isMacOS = false;
9293
}
@@ -97,6 +98,7 @@ public static bool IsMacOS {
9798
}
9899
}
99100

101+
// UNITY: runtime replaces this with intrinsic
100102
public static bool IsFreeBSD {
101103
get {
102104
if (!checkedOS)

mcs/class/referencesource/System/net/System/Net/NetworkInformation/IPGlobalProperties.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ namespace System.Net.NetworkInformation
1212

1313
public abstract class IPGlobalProperties
1414
{
15+
#if UNITY
16+
// defaults to false, but may be replaced by intrinsic in runtime
17+
static bool PlatformNeedsLibCWorkaround { get; }
18+
#endif
19+
1520
public static IPGlobalProperties GetIPGlobalProperties()
1621
{
1722
#if MONODROID
@@ -21,6 +26,10 @@ public static IPGlobalProperties GetIPGlobalProperties()
2126
#elif MONO
2227
switch (Environment.OSVersion.Platform) {
2328
case PlatformID.Unix:
29+
#if UNITY
30+
if (PlatformNeedsLibCWorkaround)
31+
return new UnixNoLibCIPGlobalProperties();
32+
#endif
2433
MibIPGlobalProperties impl = null;
2534
if (Directory.Exists (MibIPGlobalProperties.ProcDir)) {
2635
impl = new MibIPGlobalProperties (MibIPGlobalProperties.ProcDir);

mono/mini/method-to-ir.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5780,6 +5780,34 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
57805780
if (mono_type_is_native_blittable (arg0))
57815781
return mini_emit_memory_load (cfg, arg0, args [0], 0, 0);
57825782
}
5783+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
5784+
!strcmp (cmethod->klass->name_space, "System") &&
5785+
!strcmp (cmethod->klass->name, "Platform") &&
5786+
!strcmp (cmethod->name, "get_IsMacOS")) {
5787+
#if defined(TARGET_OSX)
5788+
EMIT_NEW_ICONST (cfg, ins, 1);
5789+
#else
5790+
EMIT_NEW_ICONST (cfg, ins, 0);
5791+
#endif
5792+
return ins;
5793+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
5794+
!strcmp (cmethod->klass->name_space, "System") &&
5795+
!strcmp (cmethod->klass->name, "Platform") &&
5796+
!strcmp (cmethod->name, "get_IsFreeBSD")) {
5797+
#if defined(__FreeBSD__)
5798+
EMIT_NEW_ICONST (cfg, ins, 1);
5799+
#else
5800+
EMIT_NEW_ICONST (cfg, ins, 0);
5801+
#endif
5802+
return ins;
5803+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
5804+
!strcmp (cmethod->klass->name_space, "System.Net.NetworkInformation") &&
5805+
!strcmp (cmethod->klass->name, "IPGlobalProperties") &&
5806+
!strcmp (cmethod->name, "get_PlatformNeedsLibCWorkaround")) {
5807+
#if defined(HOST_ANDROID)
5808+
EMIT_NEW_ICONST (cfg, ins, 1);
5809+
return ins;
5810+
#endif
57835811
}
57845812

57855813
#ifdef MONO_ARCH_SIMD_INTRINSICS

0 commit comments

Comments
 (0)