private Ref.Assembly Resolve(object sender, ResolveEventArgs args) { if (!args.Name.StartsWith(assemblyNamePrefix)) { return(null); } DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (this) { if (args.Name == dynamicAssemblyName.GetDisplayName()) { return(dynamicModule != null ? dynamicModule.Assembly : null); } if (dynamicModule != null && dynamicModule.Assembly == args.RequestingAssembly || fallBackAssemblies != null && fallBackAssemblies.Contains(args.RequestingAssembly)) { int comma = args.Name.IndexOf(','); return(ResolveNoLock(args.Name.Substring(0, (comma != -1) ? comma : args.Name.Length))); } } return(null); }
/// <summary> /// Gets the syntax node represented the structure of this trivia, if any. The HasStructure property can be used to /// determine if this trivia has structure. /// </summary> /// /// <returns> /// A CSharpSyntaxNode derived from StructuredTriviaSyntax, with the structured view of this trivia node. /// If this trivia node does not have structure, returns null. /// </returns> /// /// <remarks> /// Some types of trivia have structure that can be accessed as additional syntax nodes. /// These forms of trivia include: /// directives, where the structure describes the structure of the directive. /// documentation comments, where the structure describes the XML structure of the comment. /// skipped tokens, where the structure describes the tokens that were skipped by the parser. /// </remarks> public override SyntaxNode GetStructure(Microsoft.CodeAnalysis.SyntaxTrivia trivia) { if (trivia.HasStructure) { var parent = trivia.Token.Parent; if (parent != null) { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment SyntaxNode structure; var structsInParent = structuresTable.GetOrCreateValue(parent); lock (structsInParent) { if (!structsInParent.TryGetValue(trivia, out structure)) { structure = CSharp.Syntax.StructuredTriviaSyntax.Create(trivia); structsInParent.Add(trivia, structure); } } return(structure); } else { return(CSharp.Syntax.StructuredTriviaSyntax.Create(trivia)); } } return(null); }
/// <summary> /// Called by compactTimer. /// </summary> private static void CompactCacheOfModules() { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment // Do one pass through the moduleKeys list int originalCount = -1; for (int current = 0; ; current++) { // Compact modules, one module per lock // Lock our cache lock (Guard) { if (originalCount == -1) { originalCount = moduleKeys.Count; } if (moduleKeys.Count > current) { CachedModule cachedModule; FileKey key = moduleKeys[current]; if (modulesFromFiles.TryGetValue(key, out cachedModule)) { if (cachedModule.Metadata.IsNull()) { // Module has been collected modulesFromFiles.Remove(key); moduleKeys.RemoveAt(current); current--; } } else { // Key is not found. Shouldn't ever get here! System.Diagnostics.Debug.Assert(false); moduleKeys.RemoveAt(current); current--; } } if (moduleKeys.Count <= current + 1) { // no more modules to process if (originalCount > moduleKeys.Count) { moduleKeys.TrimExcess(); } return; } } Thread.Yield(); } }
/// <summary> /// Called by compactTimer. /// </summary> private static void CompactCacheOfAnalyzers() { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment // Do one pass through the analyzerAssemblyKeys list int originalCount = -1; for (int current = 0; ; current++) { // Compact analyzer assemblies, one assembly per lock // Lock our cache lock (Guard) { if (originalCount == -1) { originalCount = analyzerAssemblyKeys.Count; } if (analyzerAssemblyKeys.Count > current) { CachedAnalyzers cahedAnalyzers; FileKey key = analyzerAssemblyKeys[current]; if (analyzersFromFiles.TryGetValue(key, out cahedAnalyzers)) { if (!cahedAnalyzers.Analyzers.IsAlive) { // Analyzers has been collected analyzersFromFiles.Remove(key); analyzerAssemblyKeys.RemoveAt(current); current--; } } else { // Key is not found. Shouldn't ever get here! System.Diagnostics.Debug.Assert(false); analyzerAssemblyKeys.RemoveAt(current); current--; } } if (analyzerAssemblyKeys.Count <= current + 1) { // no more assemblies to process if (originalCount > analyzerAssemblyKeys.Count) { analyzerAssemblyKeys.TrimExcess(); } return; } } Thread.Yield(); } }
private Ref.Assembly Resolve(string simpleName) { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (this) { return(ResolveNoLock(simpleName)); } }
internal bool ContainsAssembly(string simpleName) { if (mapping == null) { return(false); } DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (this) { return(mapping.ContainsKey(simpleName)); } }
/// <summary> /// Called by compactTimer to compact the cache. /// </summary> private static void CompactCache(Object state) { if (compactTimerIsOn == no) { return; } // Prevent execution in parallel. if (Interlocked.CompareExchange(ref compactInProgress, yes, no) != no) { return; } try { int currentCollectionCount = GetCollectionCount(); if (currentCollectionCount == compactCollectionCount) { // Nothing was collected since we compacted caches last time. return; } CompactCacheOfAssemblies(); CompactCacheOfModules(); CompactCacheOfAnalyzers(); compactCollectionCount = currentCollectionCount; DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (Guard) { if (!(AnyAssembliesCached() || AnyModulesCached() || AnyAnalyzerAssembliesCached())) { // Stop the timer compactTimerIsOn = no; compactTimer.Change(Timeout.Infinite, Timeout.Infinite); } } } finally { System.Diagnostics.Debug.Assert(compactInProgress == yes); compactInProgress = no; } }
internal void AddFallBackAssembly(Ref.Assembly assembly) { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (this) { if (fallBackAssemblies == null) { Debug.Assert(mapping == null); fallBackAssemblies = new HashSet <Ref.Assembly>(); mapping = new Dictionary <string, Ref.Assembly>(); } fallBackAssemblies.Add(assembly); mapping[assembly.GetName().Name] = assembly; } }
internal RefEmit.ModuleBuilder GetOrCreateDynamicModule() { if (dynamicModule == null) { DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment lock (this) { if (dynamicModule == null) { dynamicModule = CreateDynamicModule( #if DEBUG EnableAssemblySave ? RefEmit.AssemblyBuilderAccess.RunAndSave : #endif RefEmit.AssemblyBuilderAccess.Run, dynamicAssemblyName, UncollectibleModuleFileName); } } } return(dynamicModule); }
internal Microsoft.Cci.IFieldReference CreateDataField(byte[] data) { Debug.Assert(!IsFrozen); Microsoft.Cci.ITypeReference type = this.proxyTypes.GetOrAdd((uint)data.Length, size => GetStorageStruct(size)); DebuggerUtilities.CallBeforeAcquiringLock(); //see method comment var block = new MetadataBlock(data); //This object may be accessed concurrently //it is not expected to have a lot of contention here so we will just use lock //if it becomes an issue we can switch to lock-free data structures. lock (this.mappedFields) { var name = GenerateDataFieldName(this.mappedFields.Count); var newField = new MappedField(name, this, type, block); this.mappedFields.Add(newField); return(newField); } }
public static async Task Play(ServerModel server, Window window) { string adressData; bool hasAc = false; try { if (Directory.Exists(Path.GetDirectoryName(Settings.PathToSkympClientSettings)) && File.Exists(Settings.PathToSkympClientSettings)) { File.SetAttributes(Settings.PathToSkympClientSettings, FileAttributes.Normal); } SetServer(server); string adress = server.Address; adressData = server.AddressData; object gameData = await Account.GetSession(adress); if (gameData == null) { return; } try { string res = await Net.RequestHttp($"http://{adressData}/SkyEye", "GET", false, null); if (res == "true") { hasAc = true; } } catch (Exception) { } if (hasAc) { ResultInitModel res = await SkyEye.AntiCheat.Init(Settings.UserId, Settings.UserName, ((JObject)gameData)["session"].ToObject <string>()); if (!res.Success) { NotifyController.Show(res.Message); return; } } SetSession(gameData); } catch (JsonSerializationException) { NotifyController.Show(Res.ErrorReadSkyMPSettings); return; } catch (JsonReaderException) { NotifyController.Show(Res.ErrorReadSkyMPSettings); return; } catch (UnauthorizedAccessException) { FileAttributes attr = new FileInfo(Settings.PathToSkympClientSettings).Attributes; Logger.Error("Play_UAException", new UnauthorizedAccessException($"UnAuthorizedAccessException: Unable to access file. Attributes: {attr}")); NotifyController.Show($"Unable to access file {Settings.PathToSkympClientSettings}"); return; } catch (Exception e) { Logger.Error("Play", e); NotifyController.Show(e); return; } if (!await SetMods(adressData)) { return; } try { window.Hide(); if (hasAc) { SkyEye.AntiCheat.Detected += ACDetected; } bool crash = await GameLauncher.StartGame(); window.Show(); if (hasAc) { SkyEye.AntiCheat.Close(); } if (crash) { Logger.ReportMetricaEvent("CrashDetected"); await Task.Delay(500); await DebuggerUtilities.ReportDmp(); } } catch { Logger.ReportMetricaEvent("HasNotAccess"); window.Show(); } finally { if (hasAc) { SkyEye.AntiCheat.Detected -= ACDetected; } } }