Skip to content

Commit 70b7579

Browse files
author
Joshua Peterson
authored
Merge pull request #1441 from Unity-Technologies/handle-missing-libc-better
Handle platforms that don't have libc (case 1340695)
2 parents 45a309f + 8183830 commit 70b7579

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ public override string DhcpScopeName {
5757
public override string DomainName {
5858
get {
5959
byte [] bytes = new byte [256];
60-
if (getdomainname (bytes, 256) != 0)
61-
throw new NetworkInformationException ();
60+
#if UNITY
61+
try
62+
{
63+
#endif
64+
if (getdomainname (bytes, 256) != 0)
65+
throw new NetworkInformationException ();
66+
#if UNITY
67+
} catch (EntryPointNotFoundException) {
68+
return String.Empty;
69+
}
70+
#endif
6271
int len = Array.IndexOf<byte> (bytes, 0);
6372
return Encoding.ASCII.GetString (bytes, 0, len < 0 ? 256 : len);
6473
}
@@ -152,6 +161,17 @@ public override string DomainName {
152161
}
153162
#endif
154163

164+
#if UNITY
165+
sealed class UnixNoLibCIPGlobalProperties : UnixIPGlobalProperties
166+
{
167+
public override string DomainName {
168+
get {
169+
return String.Empty;
170+
}
171+
}
172+
}
173+
#endif
174+
155175
// It expects /proc/net/snmp (or /usr/compat/linux/proc/net/snmp),
156176
// formatted like:
157177
// http://www.linuxdevcenter.com/linux/2000/11/16/example5.html
@@ -389,6 +409,11 @@ public override UdpStatistics GetUdpIPv6Statistics ()
389409
}
390410

391411
internal static class UnixIPGlobalPropertiesFactoryPal {
412+
#if UNITY
413+
// defaults to false, but may be replaced by intrinsic in runtime
414+
static bool PlatformNeedsLibCWorkaround { get; }
415+
#endif
416+
392417
public static IPGlobalProperties Create ()
393418
{
394419
#if MONODROID
@@ -398,6 +423,10 @@ public static IPGlobalProperties Create ()
398423
#elif MONO
399424
switch (Environment.OSVersion.Platform) {
400425
case PlatformID.Unix:
426+
#if UNITY
427+
if (PlatformNeedsLibCWorkaround)
428+
return new UnixNoLibCIPGlobalProperties();
429+
#endif
401430
MibIPGlobalProperties impl = null;
402431
if (Directory.Exists (MibIPGlobalProperties.ProcDir)) {
403432
impl = new MibIPGlobalProperties (MibIPGlobalProperties.ProcDir);

mcs/class/System/System/Platform.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,26 @@ private static void CheckOS() {
8989
}
9090
#endif
9191

92+
// UNITY: runtime replaces this with intrinsic
9293
public static bool IsMacOS {
9394
get {
9495
if (!checkedOS)
96+
#if UNITY
97+
try {
98+
CheckOS();
99+
}
100+
catch (DllNotFoundException) {
101+
// libc does not exist, so this is not MacOS
102+
isMacOS = false;
103+
}
104+
#else
95105
CheckOS();
106+
#endif
96107
return isMacOS;
97108
}
98109
}
99110

111+
// UNITY: runtime replaces this with intrinsic
100112
public static bool IsFreeBSD {
101113
get {
102114
if (!checkedOS)

mono/mini/intrinsics.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,34 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
18981898
return ins;
18991899
}
19001900
}
1901+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
1902+
!strcmp (cmethod->klass->name_space, "System") &&
1903+
!strcmp (cmethod->klass->name, "Platform") &&
1904+
!strcmp (cmethod->name, "get_IsMacOS")) {
1905+
#if defined(TARGET_OSX)
1906+
EMIT_NEW_ICONST (cfg, ins, 1);
1907+
#else
1908+
EMIT_NEW_ICONST (cfg, ins, 0);
1909+
#endif
1910+
return ins;
1911+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
1912+
!strcmp (cmethod->klass->name_space, "System") &&
1913+
!strcmp (cmethod->klass->name, "Platform") &&
1914+
!strcmp (cmethod->name, "get_IsFreeBSD")) {
1915+
#if defined(__FreeBSD__)
1916+
EMIT_NEW_ICONST (cfg, ins, 1);
1917+
#else
1918+
EMIT_NEW_ICONST (cfg, ins, 0);
1919+
#endif
1920+
return ins;
1921+
} else if (!strcmp (cmethod->klass->image->assembly->aname.name, "System") &&
1922+
!strcmp (cmethod->klass->name_space, "System.Net.NetworkInformation") &&
1923+
!strcmp (cmethod->klass->name, "UnixIPGlobalPropertiesFactoryPal") &&
1924+
!strcmp (cmethod->name, "get_PlatformNeedsLibCWorkaround")) {
1925+
#if defined(HOST_ANDROID)
1926+
EMIT_NEW_ICONST (cfg, ins, 1);
1927+
return ins;
1928+
#endif
19011929
}
19021930

19031931
#ifdef MONO_ARCH_SIMD_INTRINSICS

0 commit comments

Comments
 (0)