internal static Version GetClosestCompilerVersionWithSpectreMitigations(BinaryAnalyzerContext context, ExtendedMachine machine, Version omVersion) { var compilerMitigationData = LoadCompilerDataFromConfig(context.Policy); var machineFamily = machine.GetMachineFamily(); if (!compilerMitigationData.ContainsKey(machineFamily)) { // Mitigations are not supported on this platform at all. No appropriate 'closest compiler version'. return(null); } else { var 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." Version 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); } }
/// <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) { var compilerMitigationData = LoadCompilerDataFromConfig(context.Policy); var machineFamily = machine.GetMachineFamily(); if (!compilerMitigationData.ContainsKey(machineFamily)) { return(CompilerMitigations.None); } else { var 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); }