Merge pull request #2422 from akoeplinger/environment-is64bitoperatingsystem
authorJoão Matos <joao@tritao.eu>
Wed, 13 Jan 2016 01:55:01 +0000 (01:55 +0000)
committerJoão Matos <joao@tritao.eu>
Wed, 13 Jan 2016 01:55:01 +0000 (01:55 +0000)
[corlib] Properly implement Environment.Is64BitOperatingSystem

mcs/class/corlib/System/Environment.cs
mono/metadata/icall-def.h
mono/metadata/icall.c

index 99e35c2fe7c5c9744b7d73e0d795fe95392c933d..ba03204a083f1d5dfa90ed7cc399345cb4fb2748 100644 (file)
@@ -896,8 +896,11 @@ namespace System {
                        throw new NotImplementedException ();
                }
 
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               extern static bool GetIs64BitOperatingSystem ();
+
                public static bool Is64BitOperatingSystem {
-                       get { return IntPtr.Size == 8; } // FIXME: is this good enough?
+                       get { return GetIs64BitOperatingSystem (); }
                }
 
                public static int SystemPageSize {
index a98091bc5a9ffc0fc5a9789a8bda0408d1e454ff..24e91c83ceacc0e36f14890b3657ebf4bae65495 100644 (file)
@@ -228,6 +228,7 @@ ICALL_TYPE(ENV, "System.Environment", ENV_1)
 ICALL(ENV_1, "Exit", ves_icall_System_Environment_Exit)
 ICALL(ENV_2, "GetCommandLineArgs", mono_runtime_get_main_args)
 ICALL(ENV_3, "GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames)
+ICALL(ENV_31, "GetIs64BitOperatingSystem", ves_icall_System_Environment_GetIs64BitOperatingSystem)
 ICALL(ENV_4, "GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives )
 ICALL(ENV_5, "GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path)
 ICALL(ENV_51, "GetNewLine", ves_icall_System_Environment_get_NewLine)
index 06b2c57a759b7010a4bd92f16ecc04cef9814301..cc0d7c957fe09e9e73df56fe94edbd18a5d4ab67 100644 (file)
 #include "decimal-ms.h"
 #include "number-ms.h"
 
+#if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
+#include <sys/utsname.h>
+#endif
+
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
 ICALL_EXPORT MonoReflectionAssembly* ves_icall_System_Reflection_Assembly_GetCallingAssembly (void);
@@ -5880,6 +5884,28 @@ ves_icall_System_Environment_get_NewLine (void)
 #endif
 }
 
+ICALL_EXPORT MonoBoolean
+ves_icall_System_Environment_GetIs64BitOperatingSystem (void)
+{
+#if SIZEOF_VOID_P == 8
+       return TRUE;
+#else
+#ifdef HOST_WIN32
+       gboolean isWow64Process = FALSE;
+       if (IsWow64Process (GetCurrentProcess (), &isWow64Process)) {
+               return (MonoBoolean)isWow64Process;
+       }
+#elif defined(HAVE_SYS_UTSNAME_H)
+       struct utsname name;
+
+       if (uname (&name) >= 0) {
+               return strcmp (name.machine, "x86_64") == 0 || strncmp (name.machine, "aarch64", 7) == 0 || strncmp (name.machine, "ppc64", 5) == 0;
+       }
+#endif
+       return FALSE;
+#endif
+}
+
 ICALL_EXPORT MonoString *
 ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
 {