File: runtimeenvironment.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (215 lines) | stat: -rw-r--r-- 7,841 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
/*=============================================================================
**
** Class: RuntimeEnvironment
**
**
** Purpose: Runtime information
**          
**
=============================================================================*/

using System;
using System.Text;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using Microsoft.Win32;
using System.Runtime.Versioning;
using StackCrawlMark = System.Threading.StackCrawlMark;

namespace System.Runtime.InteropServices {
[System.Runtime.InteropServices.ComVisible(true)]
#if FEATURE_CORECLR
    static
#endif
    public class RuntimeEnvironment {

#if !FEATURE_CORECLR
        // This should have been a static class, but wasn't as of v3.5.  Clearly, this is
        // broken.  We'll keep this in V4 for binary compat, but marked obsolete as error
        // so migrated source code gets fixed.  On Silverlight, this type exists but is
        // not public.
        [Obsolete("Do not create instances of the RuntimeEnvironment class.  Call the static methods directly on this type instead", true)]
        public RuntimeEnvironment()
        {
            // Should not have been instantiable - here for binary compatibility in V4.
        }
#endif
#if !MONO
        [System.Security.SecurityCritical]  // auto-generated
        [ResourceExposure(ResourceScope.Machine)]
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        internal static extern String GetModuleFileName();

        [System.Security.SecurityCritical]  // auto-generated
        [ResourceExposure(ResourceScope.Machine)]
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        internal static extern String GetDeveloperPath();

        [System.Security.SecurityCritical]  // auto-generated
        [ResourceExposure(ResourceScope.Machine)]
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        internal static extern String GetHostBindingFile();
#endif
#if !FEATURE_CORECLR && !MONO
        [System.Security.SecurityCritical]  // auto-generated
        [ResourceExposure(ResourceScope.None)]
        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
        [SuppressUnmanagedCodeSecurity]
        internal static extern void _GetSystemVersion(StringHandleOnStack retVer);
#endif //!FEATURE_CORECLR

        public static bool FromGlobalAccessCache(Assembly a)
        {
            return a.GlobalAssemblyCache;
        }
        
#if !FEATURE_CORECLR
        [System.Security.SecuritySafeCritical] // public member
#endif
        [MethodImpl (MethodImplOptions.NoInlining)]
        public static String GetSystemVersion()
        {
#if FEATURE_CORECLR || MONO

            return Assembly.GetExecutingAssembly().ImageRuntimeVersion;

#else // FEATURE_CORECLR

            String ver = null;
            _GetSystemVersion(JitHelpers.GetStringHandleOnStack(ref ver));
            return ver;

#endif // FEATURE_CORECLR

        }
        
        [System.Security.SecuritySafeCritical]  // auto-generated
        [ResourceExposure(ResourceScope.Machine)]
        [ResourceConsumption(ResourceScope.Machine)]
        public static String GetRuntimeDirectory()
        {
#if !MOBILE
            //
            // Workaround for csc hardcoded behaviour where executing mscorlib
            // location is always the first path to search for references unless
            // they have full path. Mono build is using simple assembly names for
            // references and -lib for path which is by default csc dehaviour never
            // used
            //
            var sdk = Environment.GetEnvironmentVariable ("CSC_SDK_PATH_DISABLED");
            if (sdk != null)
                return null;
#endif
            String dir = GetRuntimeDirectoryImpl();
#if MONO_FEATURE_CAS
            new FileIOPermission(FileIOPermissionAccess.PathDiscovery, dir).Demand();
#endif
            return dir;
        }

#if MONO
        static String GetRuntimeDirectoryImpl()
        {
            return Path.GetDirectoryName (typeof (object).Assembly.Location);
        }
#else
        [System.Security.SecurityCritical]  // auto-generated
        [ResourceExposure(ResourceScope.Machine)]
        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        internal static extern String GetRuntimeDirectoryImpl();
#endif
        
        // Returns the system ConfigurationFile
        public static String SystemConfigurationFile {
            [System.Security.SecuritySafeCritical]  // auto-generated
            [ResourceExposure(ResourceScope.Machine)]
            [ResourceConsumption(ResourceScope.Machine)]
            get {
#if MONO
                String path = Environment.GetMachineConfigPath ();
#else
                StringBuilder sb = new StringBuilder(Path.MAX_PATH);
                sb.Append(GetRuntimeDirectory());
                sb.Append(AppDomainSetup.RuntimeConfigurationFile);
                String path = sb.ToString();
#endif
                
#if MONO_FEATURE_CAS
                // Do security check
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
#endif
                return path;
            }
        }

#if FEATURE_COMINTEROP || MONO
#if MONO
        private static IntPtr GetRuntimeInterfaceImpl(Guid clsid, Guid riid)
        {
            throw new NotSupportedException();
        }
#else
        [System.Security.SecurityCritical]
        [ResourceExposure(ResourceScope.Process)]
        [ResourceConsumption(ResourceScope.Process)]
        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
        [SuppressUnmanagedCodeSecurity]
        private static extern IntPtr GetRuntimeInterfaceImpl(
            [In, MarshalAs(UnmanagedType.LPStruct)] Guid clsid,
            [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid);
#endif

        //
        // This function does the equivalent of calling GetInterface(clsid, riid) on the
        // ICLRRuntimeInfo representing this runtime. See MetaHost.idl for a list of
        // CLSIDs and IIDs supported by this method.
        //
        // Returns unmanaged pointer to requested interface on success. Throws
        // COMException with failed HR if there is a QI failure.
        //
        [System.Security.SecurityCritical]  // do not allow partial trust callers
        [ComVisible(false)]
        [ResourceExposure(ResourceScope.Process)]
        [ResourceConsumption(ResourceScope.Process)]
        public static IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid)
        {
            return GetRuntimeInterfaceImpl(clsid, riid);
        }

        //
        // This function does the equivalent of calling GetInterface(clsid, riid) on the
        // ICLRRuntimeInfo representing this runtime. See MetaHost.idl for a list of
        // CLSIDs and IIDs supported by this method.
        //
        // Returns an RCW to requested interface on success. Throws
        // COMException with failed HR if there is a QI failure.
        //
        [System.Security.SecurityCritical]  // do not allow partial trust callers
        [ComVisible(false)]
        [ResourceExposure(ResourceScope.Process)]
        [ResourceConsumption(ResourceScope.Process)]
        public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid)
        {
            IntPtr p = IntPtr.Zero;
            try {
                p = GetRuntimeInterfaceImpl(clsid, riid);
                return Marshal.GetObjectForIUnknown(p);
            } finally {
                if(p != IntPtr.Zero) {
                    Marshal.Release(p);
                }
            }
        }

#endif // FEATURE_COMINTEROP
    }
}