diff --git a/src/pipeline/PipelineEmscriptenModule.ts b/src/pipeline/PipelineEmscriptenModule.ts index efbde812e..a151334b9 100644 --- a/src/pipeline/PipelineEmscriptenModule.ts +++ b/src/pipeline/PipelineEmscriptenModule.ts @@ -12,6 +12,8 @@ interface PipelineEmscriptenModule extends EmscriptenModule { writeArrayToMemory: typeof writeArrayToMemory; writeAsciiToMemory: typeof writeAsciiToMemory; AsciiToString: (ptr: number) => string; + stackSave: () => number; + stackRestore: (ptr: number) => void; resetModuleStdout: () => void; resetModuleStderr: () => void; diff --git a/src/pipeline/internal/runPipelineEmscripten.ts b/src/pipeline/internal/runPipelineEmscripten.ts index d797138af..fcaad3484 100644 --- a/src/pipeline/internal/runPipelineEmscripten.ts +++ b/src/pipeline/internal/runPipelineEmscripten.ts @@ -291,6 +291,7 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args: pipelineModule.resetModuleStdout() pipelineModule.resetModuleStderr() + const stackPtr = pipelineModule.stackSave() let returnValue = 0 try { returnValue = pipelineModule.callMain(args.slice()) @@ -308,6 +309,8 @@ function runPipelineEmscripten (pipelineModule: PipelineEmscriptenModule, args: } } throw exception + } finally { + pipelineModule.stackRestore(stackPtr) } const stdout = pipelineModule.getModuleStdout() const stderr = pipelineModule.getModuleStderr()