diff --git a/src/alloy/backend/ivm/ivm_function.cc b/src/alloy/backend/ivm/ivm_function.cc index e5ee570e8..84e31507f 100644 --- a/src/alloy/backend/ivm/ivm_function.cc +++ b/src/alloy/backend/ivm/ivm_function.cc @@ -103,8 +103,11 @@ void IVMFunction::OnBreakpointHit(ThreadState* thread_state, IntCode* i) { int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) { // Setup register file on stack. + const size_t max_stack_alloc = 16 * 1024; size_t register_file_size = register_count_ * sizeof(Register); - Register* register_file = (Register*)alloca(register_file_size); + Register* register_file = (Register*)( + register_file_size >= max_stack_alloc ? + xe_malloc(register_file_size) : alloca(register_file_size)); Memory* memory = thread_state->memory(); @@ -148,5 +151,9 @@ int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) { } } + if (register_file_size >= max_stack_alloc) { + xe_free(register_file); + } + return 0; }