@@ -6,28 +6,6 @@ namespace Python.Runtime.Platform
66{
77 class NativeCodePageHelper
88 {
9- /// <summary>
10- /// Gets the operating system as reported by python's platform.system().
11- /// </summary>
12- public static OperatingSystemType OperatingSystem { get ; private set ; }
13-
14- /// <summary>
15- /// Gets the operating system as reported by python's platform.system().
16- /// </summary>
17- [ Obsolete ]
18- public static string OperatingSystemName => PythonEngine . Platform ;
19-
20- /// <summary>
21- /// Gets the machine architecture as reported by python's platform.machine().
22- /// </summary>
23- public static MachineType Machine { get ; private set ; } /* set in Initialize using python's platform.machine */
24-
25- /// <summary>
26- /// Gets the machine architecture as reported by python's platform.machine().
27- /// </summary>
28- [ Obsolete ]
29- public static string MachineName { get ; private set ; }
30-
319 /// <summary>
3210 /// Initialized by InitializeNativeCodePage.
3311 ///
@@ -45,33 +23,6 @@ class NativeCodePageHelper
4523 internal static IntPtr NativeCodePage = IntPtr . Zero ;
4624
4725
48- static readonly Dictionary < string , OperatingSystemType > OperatingSystemTypeMapping = new Dictionary < string , OperatingSystemType > ( )
49- {
50- { "Windows" , OperatingSystemType . Windows } ,
51- { "Darwin" , OperatingSystemType . Darwin } ,
52- { "Linux" , OperatingSystemType . Linux } ,
53- } ;
54-
55- /// <summary>
56- /// Map lower-case version of the python machine name to the processor
57- /// type. There are aliases, e.g. x86_64 and amd64 are two names for
58- /// the same thing. Make sure to lower-case the search string, because
59- /// capitalization can differ.
60- /// </summary>
61- static readonly Dictionary < string , MachineType > MachineTypeMapping = new Dictionary < string , MachineType > ( )
62- {
63- [ "i386" ] = MachineType . i386 ,
64- [ "i686" ] = MachineType . i386 ,
65- [ "x86" ] = MachineType . i386 ,
66- [ "x86_64" ] = MachineType . x86_64 ,
67- [ "amd64" ] = MachineType . x86_64 ,
68- [ "x64" ] = MachineType . x86_64 ,
69- [ "em64t" ] = MachineType . x86_64 ,
70- [ "armv7l" ] = MachineType . armv7l ,
71- [ "armv8" ] = MachineType . armv8 ,
72- [ "aarch64" ] = MachineType . aarch64 ,
73- } ;
74-
7526 /// <summary>
7627 /// Structure to describe native code.
7728 ///
@@ -108,11 +59,11 @@ public static NativeCode Active
10859 {
10960 get
11061 {
111- switch ( Machine )
62+ switch ( RuntimeInformation . ProcessArchitecture )
11263 {
113- case MachineType . i386 :
64+ case Architecture . X86 :
11465 return I386 ;
115- case MachineType . x86_64 :
66+ case Architecture . X64 :
11667 return X86_64 ;
11768 default :
11869 return null ;
@@ -205,14 +156,14 @@ int MAP_ANONYMOUS
205156 {
206157 get
207158 {
208- switch ( OperatingSystem )
159+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
209160 {
210- case OperatingSystemType . Darwin :
211- return 0x1000 ;
212- case OperatingSystemType . Linux :
213- return 0x20 ;
214- default :
215- throw new NotImplementedException ( $ "mmap is not supported on { OperatingSystemName } " ) ;
161+ return 0x20 ;
162+ }
163+ else
164+ {
165+ // OSX, FreeBSD
166+ return 0x1000 ;
216167 }
217168 }
218169 }
@@ -236,32 +187,16 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes)
236187 }
237188 }
238189
239- /// <summary>
240- /// Initializes the data about platforms.
241- ///
242- /// This must be the last step when initializing the runtime:
243- /// GetManagedString needs to have the cached values for types.
244- /// But it must run before initializing anything outside the runtime
245- /// because those rely on the platform data.
246- /// </summary>
247- public static void InitializePlatformData ( )
248- {
249- MachineName = SystemInfo . GetArchitecture ( ) ;
250- Machine = SystemInfo . GetMachineType ( ) ;
251- OperatingSystem = SystemInfo . GetSystemType ( ) ;
252- }
253-
254190 internal static IMemoryMapper CreateMemoryMapper ( )
255191 {
256- switch ( OperatingSystem )
192+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
193+ {
194+ return new WindowsMemoryMapper ( ) ;
195+ }
196+ else
257197 {
258- case OperatingSystemType . Darwin :
259- case OperatingSystemType . Linux :
260- return new UnixMemoryMapper ( ) ;
261- case OperatingSystemType . Windows :
262- return new WindowsMemoryMapper ( ) ;
263- default :
264- throw new NotImplementedException ( $ "No support for { OperatingSystemName } ") ;
198+ // Linux, OSX, FreeBSD
199+ return new UnixMemoryMapper ( ) ;
265200 }
266201 }
267202
0 commit comments