internal static Dictionary <MachineFamily, CompilerVersionToMitigation[]> LoadCompilerDataFromConfig(PropertiesDictionary policy) { if (_compilerData == null) { _compilerData = new Dictionary <MachineFamily, CompilerVersionToMitigation[]>(); PropertiesDictionary configData = policy.GetProperty(MitigatedCompilers); foreach (var key in configData.Keys) { MachineFamily machine = (MachineFamily)Enum.Parse(typeof(MachineFamily), key); // Neaten this up. _compilerData.Add(machine, CreateSortedVersionDictionary((PropertiesDictionary)configData[key])); } } return(_compilerData); }
/// <summary> /// Get the Spectre compiler compiler mitigations available for a particular compiler version and machine type. /// </summary> internal static CompilerMitigations GetAvailableMitigations(BinaryAnalyzerContext context, ExtendedMachine machine, Version omVersion) { Dictionary <MachineFamily, CompilerVersionToMitigation[]> compilerMitigationData = LoadCompilerDataFromConfig(context.Policy); MachineFamily machineFamily = machine.GetMachineFamily(); if (!compilerMitigationData.ContainsKey(machineFamily)) { return(CompilerMitigations.None); } else { CompilerVersionToMitigation[] listOfMitigatedCompilers = compilerMitigationData[machineFamily]; for (int i = 0; i < listOfMitigatedCompilers.Length; i++) { if (omVersion >= listOfMitigatedCompilers[i].MinimalSupportedVersion && omVersion < listOfMitigatedCompilers[i].MaximumSupportedVersion) { return(listOfMitigatedCompilers[i].SupportedMitigations); } } } return(CompilerMitigations.None); }
internal static Version GetClosestCompilerVersionWithSpectreMitigations(BinaryAnalyzerContext context, ExtendedMachine machine, Version omVersion) { Dictionary <MachineFamily, CompilerVersionToMitigation[]> compilerMitigationData = LoadCompilerDataFromConfig(context.Policy); MachineFamily machineFamily = machine.GetMachineFamily(); if (!compilerMitigationData.ContainsKey(machineFamily)) { // Mitigations are not supported on this platform at all. No appropriate 'closest compiler version'. return(null); } else { CompilerVersionToMitigation[] listOfMitigatedCompilers = compilerMitigationData[machineFamily]; // If the compiler version is not supported, then either: // 1) it is earlier than any supported compiler version // 2) it is in-between two supported compiler versions (e.x. VS2017.1-4)--it is larger than some supported version numbers and smaller than others. // 3) it's greater than any of them. // We want to give users the 'next greatest' compiler version that supports the spectre mitigations--this should be the "smallest available upgrade." var previousMaximum = new Version(0, 0, 0, 0); for (int i = 0; i < listOfMitigatedCompilers.Length; i++) { if (omVersion > previousMaximum && omVersion <= listOfMitigatedCompilers[i].MinimalSupportedVersion && (listOfMitigatedCompilers[i].SupportedMitigations & (CompilerMitigations.QSpectreAvailable | CompilerMitigations.D2GuardSpecLoadAvailable)) != 0) { return(listOfMitigatedCompilers[i].MinimalSupportedVersion); } else { previousMaximum = listOfMitigatedCompilers[i].MaximumSupportedVersion; } } // If we're here, we're in situation (3)--the compiler is greater than any we recognize. We'll return the largest compiler we know supports Spectre mitigations. // With appropriate configuration (i.e. a catch-all entry with a maximum of *.*.*.* is present), we should never really hit this case. return(listOfMitigatedCompilers[listOfMitigatedCompilers.Length - 1].MinimalSupportedVersion); } }
public async Task <MachineViewModel> GetMachine(int id) { Machine machine = await _context.Machines.FindAsync(id); if (machine is null) { return(null); } var model = new MachineViewModel { Introduced = machine.Introduced, Name = machine.Name, CompanyId = machine.CompanyId, Model = machine.Model, Type = machine.Type }; Company company = await _context.Companies.FindAsync(model.CompanyId); if (company != null) { model.Company = company.Name; IQueryable <CompanyLogo> logos = _context.CompanyLogos.Where(l => l.CompanyId == company.Id); if (model.Introduced.HasValue) { model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?. Guid; } if (model.CompanyLogo is null && logos.Any()) { model.CompanyLogo = (await logos.FirstAsync())?.Guid; } } MachineFamily family = await _context.MachineFamilies.FindAsync(machine.FamilyId); if (family != null) { model.FamilyName = family.Name; model.FamilyId = family.Id; } model.Gpus = await _gpusService.GetByMachineAsync(machine.Id); model.Memory = await _context.MemoryByMachine.Where(m => m.MachineId == machine.Id). Select(m => new MemoryViewModel { Type = m.Type, Usage = m.Usage, Size = m.Size, Speed = m.Speed }).ToListAsync(); model.Processors = await _processorsService.GetByMachineAsync(machine.Id); model.SoundSynthesizers = await _soundSynthsService.GetByMachineAsync(machine.Id); model.Storage = await _context.StorageByMachine.Where(s => s.MachineId == machine.Id). Select(s => new StorageViewModel { Type = s.Type, Interface = s.Interface, Capacity = s.Capacity }).ToListAsync(); return(model); }