@@ -68,13 +68,31 @@ public struct EngineConfiguration {
6868 /// The compilation mode to use for WebAssembly modules.
6969 public var compilationMode : CompilationMode
7070
71+ /// The stack size for the virtual machine interpreter. (Default: 64KB)
72+ ///
73+ /// Note: Typically, there are three kinds of stacks in a WebAssembly execution:
74+ /// 1. The native stack, which is used for native function calls.
75+ /// 2. The interpreter stack, which is used for allocating "local"
76+ /// variables in the WebAssembly function and call frames of the
77+ /// WebAssembly-level function calls.
78+ /// 3. The shadow stack, which is used by WebAssembly programs compiled
79+ /// by LLVM-based compilers to implement pointers to local variables.
80+ /// This stack is allocated in the WebAssembly memory space by
81+ /// wasm-ld, so the interpreter does not care about it.
82+ ///
83+ /// The stack size here refers to the second stack, the interpreter stack
84+ /// size, so you may need to increase this value if you see
85+ /// "call stack exhausted" ``Trap`` errors thrown by the interpreter.
86+ public var stackSize : Int
87+
7188 /// Initializes a new instance of `EngineConfiguration`.
7289 /// - Parameter threadingModel: The threading model to use for the virtual
7390 /// machine interpreter. If `nil`, the default threading model for the
7491 /// current platform will be used.
75- public init ( threadingModel: ThreadingModel ? = nil , compilationMode: CompilationMode = . lazy) {
92+ public init ( threadingModel: ThreadingModel ? = nil , compilationMode: CompilationMode = . lazy, stackSize : Int ? = nil ) {
7693 self . threadingModel = threadingModel ?? . defaultForCurrentPlatform
7794 self . compilationMode = compilationMode
95+ self . stackSize = stackSize ?? ( 1 << 16 )
7896 }
7997}
8098
0 commit comments