update isolate integrity

This commit is contained in:
prixod
2025-11-04 23:22:11 +04:00
parent 44cb179cf5
commit ffd0de446d
7 changed files with 64 additions and 111 deletions

View File

@@ -42,7 +42,7 @@ public class CppCompilationServiceIsolate : ICompilationService
try
{
await File.WriteAllTextAsync(sourceFilePath, sourceCode);
return await CompileFileInIsolateAsync(sourceFilePath, executablePath, version);
return await CompileFileAsync(sourceFilePath, executablePath, version);
}
catch (Exception ex)
{
@@ -55,10 +55,15 @@ public class CppCompilationServiceIsolate : ICompilationService
}
}
private async Task<CompilationResult> CompileFileInIsolateAsync(
/// <summary>
/// Compile a C++ source file to an executable using Isolate sandbox
/// </summary>
public async Task<CompilationResult> CompileFileAsync(
string sourceFilePath,
string outputExecutablePath,
string? version = null)
string? version = null,
IEnumerable<string>? includeDirectories = null,
IEnumerable<string>? additionalFlags = null)
{
int boxId = -1;
@@ -75,8 +80,8 @@ public class CppCompilationServiceIsolate : ICompilationService
var boxDir = $"/var/local/lib/isolate/{boxId}/box";
var sourceFileName = Path.GetFileName(sourceFilePath);
var boxSourcePath = Path.Combine(boxDir, sourceFileName);
var boxOutputName = "solution";
var boxOutputPath = Path.Combine(boxDir, boxOutputName);
var outputFileName = Path.GetFileName(outputExecutablePath);
var boxOutputPath = Path.Combine(boxDir, outputFileName);
File.Copy(sourceFilePath, boxSourcePath, overwrite: true);
@@ -86,9 +91,28 @@ public class CppCompilationServiceIsolate : ICompilationService
// Build compiler arguments
var arguments = new List<string>(compilerFlags);
// Add include directories
if (includeDirectories != null)
{
foreach (var includeDir in includeDirectories.Where(d => !string.IsNullOrWhiteSpace(d)))
{
arguments.Add($"-I{includeDir}");
}
}
// Add additional flags
if (additionalFlags != null)
{
foreach (var flag in additionalFlags.Where(f => !string.IsNullOrWhiteSpace(f)))
{
arguments.Add(flag);
}
}
arguments.Add($"/box/{sourceFileName}");
arguments.Add("-o");
arguments.Add($"/box/{boxOutputName}");
arguments.Add($"/box/{outputFileName}");
// Prepare stderr output file for compiler messages
var stderrFilePath = Path.Combine(boxDir, "compile_stderr.txt");