| 45 | } |
| 46 | |
| 47 | Expect<AST::InstrView::iterator> |
| 48 | Executor::enterFunction(Runtime::StackManager &StackMgr, |
| 49 | const Runtime::Instance::FunctionInstance &Func, |
| 50 | const AST::InstrView::iterator RetIt, bool IsTailCall) { |
| 51 | // RetIt: the return position when the entered function returns. |
| 52 | |
| 53 | // Check whether interruption occurred. |
| 54 | if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) { |
| 55 | spdlog::error(ErrCode::Value::Interrupted); |
| 56 | return Unexpect(ErrCode::Value::Interrupted); |
| 57 | } |
| 58 | |
| 59 | // Get the function type for the parameter and return counts. |
| 60 | const auto &FuncType = Func.getFuncType(); |
| 61 | const uint32_t ArgsN = static_cast<uint32_t>(FuncType.getParamTypes().size()); |
| 62 | const uint32_t RetsN = |
| 63 | static_cast<uint32_t>(FuncType.getReturnTypes().size()); |
| 64 | |
| 65 | // For the exception handler, remove the inactive handlers caused by the |
| 66 | // branches. |
| 67 | if (likely(RetIt)) { |
| 68 | StackMgr.removeInactiveHandler(RetIt - 1); |
| 69 | } |
| 70 | |
| 71 | if (Func.isHostFunction()) { |
| 72 | // Host function case: Push args and call function. |
| 73 | auto &HostFunc = Func.getHostFunc(); |
| 74 | |
| 75 | // Generate CallingFrame from current frame. |
| 76 | // The module instance will be nullptr if current frame is a dummy frame. |
| 77 | // For this case, use the module instance of this host function. |
| 78 | const auto *ModInst = StackMgr.getModule(); |
| 79 | if (ModInst == nullptr) { |
| 80 | ModInst = Func.getModule(); |
| 81 | } |
| 82 | Runtime::CallingFrame CallFrame(this, ModInst); |
| 83 | |
| 84 | // Push frame. |
| 85 | StackMgr.pushFrame(Func.getModule(), // Module instance |
| 86 | RetIt, // Return PC |
| 87 | ArgsN, // Only args, no locals in stack |
| 88 | RetsN, // Returns num |
| 89 | IsTailCall // For tail-call |
| 90 | ); |
| 91 | |
| 92 | // Do the statistics if the statistics turned on. |
| 93 | if (Stat) { |
| 94 | // Check host function cost. |
| 95 | if (unlikely(!Stat->addCost(HostFunc.getCost()))) { |
| 96 | spdlog::error(ErrCode::Value::CostLimitExceeded); |
| 97 | return Unexpect(ErrCode::Value::CostLimitExceeded); |
| 98 | } |
| 99 | // Start recording time of running host function. |
| 100 | Stat->stopRecordWasm(); |
| 101 | Stat->startRecordHost(); |
| 102 | } |
| 103 | |
| 104 | // Call pre-host-function |
nothing calls this directly
no test coverage detected