MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / proxyCallIndirect

Method proxyCallIndirect

lib/executor/engine/proxy.cpp:146–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146Expect<void> Executor::proxyCallIndirect(Runtime::StackManager &StackMgr,
147 const uint32_t TableIdx,
148 const uint32_t FuncTypeIdx,
149 const uint32_t FuncIdx,
150 const ValVariant *Args,
151 ValVariant *Rets) noexcept {
152 const auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
153 assuming(TabInst);
154
155 if (unlikely(FuncIdx >= TabInst->getSize())) {
156 return Unexpect(ErrCode::Value::UndefinedElement);
157 }
158
159 auto Ref = TabInst->getRefAddr(FuncIdx);
160 assuming(Ref);
161 if (unlikely(Ref->isNull())) {
162 return Unexpect(ErrCode::Value::UninitializedElement);
163 }
164
165 const auto *ModInst = StackMgr.getModule();
166 assuming(ModInst);
167 const auto &ExpDefType = **ModInst->getType(FuncTypeIdx);
168 const auto *FuncInst = retrieveFuncRef(*Ref);
169 assuming(FuncInst);
170 bool IsMatch = false;
171 if (FuncInst->getModule()) {
172 IsMatch = AST::TypeMatcher::matchType(
173 ModInst->getTypeList(), *ExpDefType.getTypeIndex(),
174 FuncInst->getModule()->getTypeList(), FuncInst->getTypeIndex());
175 } else {
176 // Independent host module instance case. Matching the composite type
177 // directly.
178 IsMatch = AST::TypeMatcher::matchType(
179 ModInst->getTypeList(), ExpDefType.getCompositeType(),
180 FuncInst->getHostFunc().getDefinedType().getCompositeType());
181 }
182 if (!IsMatch) {
183 return Unexpect(ErrCode::Value::IndirectCallTypeMismatch);
184 }
185
186 const auto &FuncType = FuncInst->getFuncType();
187 const uint32_t ParamsSize =
188 static_cast<uint32_t>(FuncType.getParamTypes().size());
189 const uint32_t ReturnsSize =
190 static_cast<uint32_t>(FuncType.getReturnTypes().size());
191
192 for (uint32_t I = 0; I < ParamsSize; ++I) {
193 StackMgr.push(Args[I]);
194 }
195
196 auto Instrs = FuncInst->getInstrs();
197 EXPECTED_TRY(auto StartIt, enterFunction(StackMgr, *FuncInst, Instrs.end()));
198 EXPECTED_TRY(execute(StackMgr, StartIt, Instrs.end()));
199
200 for (uint32_t I = 0; I < ReturnsSize; ++I) {
201 Rets[ReturnsSize - 1 - I] = StackMgr.pop();
202 }
203 return {};

Callers

nothing calls this directly

Calls 15

unlikelyFunction · 0.85
UnexpectFunction · 0.85
retrieveFuncRefFunction · 0.85
getRefAddrMethod · 0.80
isNullMethod · 0.80
getTypeListMethod · 0.80
getParamTypesMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
EXPECTED_TRYFunction · 0.70
getSizeMethod · 0.45
getModuleMethod · 0.45

Tested by

no test coverage detected