@@ -6,28 +6,6 @@ namespace Python.Runtime.Platform
6
6
{
7
7
class NativeCodePageHelper
8
8
{
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
-
31
9
/// <summary>
32
10
/// Initialized by InitializeNativeCodePage.
33
11
///
@@ -45,33 +23,6 @@ class NativeCodePageHelper
45
23
internal static IntPtr NativeCodePage = IntPtr . Zero ;
46
24
47
25
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
-
75
26
/// <summary>
76
27
/// Structure to describe native code.
77
28
///
@@ -108,11 +59,11 @@ public static NativeCode Active
108
59
{
109
60
get
110
61
{
111
- switch ( Machine )
62
+ switch ( RuntimeInformation . ProcessArchitecture )
112
63
{
113
- case MachineType . i386 :
64
+ case Architecture . X86 :
114
65
return I386 ;
115
- case MachineType . x86_64 :
66
+ case Architecture . X64 :
116
67
return X86_64 ;
117
68
default :
118
69
return null ;
@@ -205,14 +156,14 @@ int MAP_ANONYMOUS
205
156
{
206
157
get
207
158
{
208
- switch ( OperatingSystem )
159
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
209
160
{
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 ;
216
167
}
217
168
}
218
169
}
@@ -236,32 +187,16 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes)
236
187
}
237
188
}
238
189
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
-
254
190
internal static IMemoryMapper CreateMemoryMapper ( )
255
191
{
256
- switch ( OperatingSystem )
192
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
193
+ {
194
+ return new WindowsMemoryMapper ( ) ;
195
+ }
196
+ else
257
197
{
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 ( ) ;
265
200
}
266
201
}
267
202
0 commit comments