public MonoOnlyFactAttribute(string reason) { if (!MonoHelpers.IsRunningOnMono()) { Skip = reason; } }
public static TCompilation VerifyEmitDiagnostics <TCompilation>(this TCompilation c, IEnumerable <ResourceDescription> manifestResources, params DiagnosticDescription[] expected) where TCompilation : Compilation { var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); c.Emit(new MemoryStream(), pdbStream: pdbStream, manifestResources: manifestResources).Diagnostics.Verify(expected); return(c); }
public static TCompilation VerifyEmitDiagnostics <TCompilation>(this TCompilation c, EmitOptions options, params DiagnosticDescription[] expected) where TCompilation : Compilation { var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options).Diagnostics.Verify(expected); return(c); }
public ClrOnlyFactAttribute(ClrOnlyReason reason = ClrOnlyReason.Unknown) { Reason = reason; if (MonoHelpers.IsRunningOnMono()) { Skip = GetSkipReason(Reason); } }
public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid) { // This API isn't available on Mono hence we must use reflection to access it. Debug.Assert(!MonoHelpers.IsRunningOnMono()); var getRuntimeInterfaceAsObject = typeof(RuntimeEnvironment).GetMethod("GetRuntimeInterfaceAsObject", BindingFlags.Public | BindingFlags.Static); return(getRuntimeInterfaceAsObject.Invoke(null, new object[] { clsid, riid })); }
public static ImmutableArray <Diagnostic> GetEmitDiagnostics <TCompilation>( this TCompilation c, EmitOptions options = null, IEnumerable <ResourceDescription> manifestResources = null) where TCompilation : Compilation { var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); return(c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options, manifestResources: manifestResources).Diagnostics); }
internal static EmitOutput?EmitCompilationCore( Compilation compilation, IEnumerable <ResourceDescription> manifestResources, DiagnosticBag diagnostics, CompilationTestData testData, EmitOptions emitOptions ) { using (var executableStream = new MemoryStream()) { var pdb = default(ImmutableArray <byte>); var assembly = default(ImmutableArray <byte>); var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream(); EmitResult result; try { result = compilation.Emit( executableStream, metadataPEStream: null, pdbStream: pdbStream, xmlDocumentationStream: null, win32Resources: null, manifestResources: manifestResources, options: emitOptions, debugEntryPoint: null, sourceLinkStream: null, embeddedTexts: null, testData: testData, cancellationToken: default(CancellationToken)); } finally { if (pdbStream != null) { pdb = pdbStream.ToImmutable(); pdbStream.Dispose(); } } diagnostics.AddRange(result.Diagnostics); assembly = executableStream.ToImmutable(); if (result.Success) { return(new EmitOutput(assembly, pdb)); } return(null); } }
private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath, bool metadataOnly) { if (MonoHelpers.IsRunningOnMono()) { // PEverify is currently unsupported on Mono hence return an empty // set of messages return(new string[0]); } lock (s_guard) { GCHandle pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned); try { IntPtr buffer = pinned.AddrOfPinnedObject(); ICLRValidator validator = (ICLRValidator)GetRuntimeInterfaceAsObject(s_clsIdClrRuntimeHost, typeof(ICLRRuntimeHost).GUID); ValidationErrorHandler errorHandler = new ValidationErrorHandler(validator); IMetaDataDispenser dispenser = (IMetaDataDispenser)GetRuntimeInterfaceAsObject(s_clsIdCorMetaDataDispenser, typeof(IMetaDataDispenser).GUID); // the buffer needs to be pinned during validation Guid riid = typeof(IMetaDataImport).GUID; object metaDataImport = null; if (assemblyPath != null) { dispenser.OpenScope(assemblyPath, CorOpenFlags.ofRead, ref riid, out metaDataImport); } else { dispenser.OpenScopeOnMemory(buffer, (uint)peImage.Length, CorOpenFlags.ofRead, ref riid, out metaDataImport); } IMetaDataValidate metaDataValidate = (IMetaDataValidate)metaDataImport; metaDataValidate.ValidatorInit(CorValidatorModuleType.ValidatorModuleTypePE, errorHandler); metaDataValidate.ValidateMetaData(); if (!metadataOnly) { validator.Validate(errorHandler, (uint)domainId, ValidatorFlags.VALIDATOR_EXTRA_VERBOSE, ulMaxError: 10, token: 0, fileName: assemblyPath, pe: buffer, ulSize: (uint)peImage.Length); } return(errorHandler.GetOutput()); } finally { pinned.Free(); } } }
private void AssemblyLoad(object sender, AssemblyLoadEventArgs args) { var assembly = args.LoadedAssembly; // ModuleResolve needs to be hooked up for the main assembly once its loaded. // We won't get an AssemblyResolve event for the main assembly so we need to do it here. if (_mainMvids.Contains(assembly.ManifestModule.ModuleVersionId) && _loadedAssemblies.Add(assembly)) { if (!MonoHelpers.IsRunningOnMono()) { assembly.ModuleResolve += ModuleResolve; } } }
private static RuntimeData GetOrCreateRuntimeData(IEnumerable <ModuleData> modules) { // Mono doesn't support AppDomains to the degree we use them for our tests and as a result many of // the checks are disabled. Create an instance in this domain since it's not actually used. if (MonoHelpers.IsRunningOnMono()) { return(new RuntimeData(new RuntimeAssemblyManager(), null)); } var data = TryGetCachedRuntimeData(modules); if (data != null) { return(data); } return(CreateRuntimeData()); }
public void Dispose() { // clean up our handlers, so that they don't accumulate AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve; AppDomain.CurrentDomain.AssemblyLoad -= AssemblyLoad; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= ReflectionOnlyAssemblyResolve; foreach (var assembly in _loadedAssemblies) { if (!MonoHelpers.IsRunningOnMono()) { assembly.ModuleResolve -= ModuleResolve; } } //EDMAURER Some RuntimeAssemblyManagers are created via reflection in an AppDomain of our creation. //Sometimes those AppDomains are not released. I don't fully understand how that appdomain roots //a RuntimeAssemblyManager, but according to heap dumps, it does. Even though the appdomain is not //unloaded, its RuntimeAssemblyManager is explicitly disposed. So make sure that it cleans up this //memory hog - the modules dictionary. _fullNameToAssemblyDataMap.Clear(); _mvidToAssemblyDataMap.Clear(); }
private Assembly GetAssembly(string fullName, bool reflectionOnly) { AssemblyData data; if (!_fullNameToAssemblyDataMap.TryGetValue(fullName, out data)) { return(null); } Assembly assembly; switch (data.Kind) { case Kind.Assembly: assembly = data.Assembly; if (reflectionOnly && !assembly.ReflectionOnly) { assembly = Assembly.ReflectionOnlyLoad(assembly.FullName); } break; case Kind.ModuleData: assembly = _assemblyCache.GetOrLoad(data.ModuleData, reflectionOnly); break; default: throw new InvalidOperationException(); } if (!MonoHelpers.IsRunningOnMono()) { assembly.ModuleResolve += ModuleResolve; } _loadedAssemblies.Add(assembly); return(assembly); }