Call specified function from embedded wasm
| 133 | thread_local std::stack<WasmEdge_ExecutorContext *> ExecutorsStack; |
| 134 | /// Call specified function from embedded wasm |
| 135 | void callWasm(const char *FnName) { |
| 136 | Ptr<WasmEdge_ASTModuleContext> Module; |
| 137 | TRY(WasmEdge_LoaderParseFromFile) |
| 138 | (Ptr{TRY(WasmEdge_LoaderCreate)(nullptr)}, Module, PathNestedWasmCompiled); |
| 139 | TRY(WasmEdge_ValidatorValidate) |
| 140 | (Ptr{TRY(WasmEdge_ValidatorCreate)(nullptr)}, Module); |
| 141 | |
| 142 | static auto Executor = Ptr{TRY(WasmEdge_ExecutorCreate)(nullptr, nullptr)}; |
| 143 | auto Store = Ptr{TRY(WasmEdge_StoreCreate)()}; |
| 144 | auto Host = Ptr{TRY(WasmEdge_ModuleInstanceCreate)(StringView{"env"})}; |
| 145 | WasmEdge_ModuleInstanceAddFunction( |
| 146 | Host, StringView{"hostFnCheck"}, |
| 147 | WasmEdge_FunctionInstanceCreate( |
| 148 | Ptr{TRY(WasmEdge_FunctionTypeCreate)(nullptr, 0, nullptr, 0)}, |
| 149 | [](void *, const WasmEdge_CallingFrameContext *Frame, |
| 150 | const WasmEdge_Value *, WasmEdge_Value *) { |
| 151 | hostFnCheck(Frame); |
| 152 | return WasmEdge_Result_Success; |
| 153 | }, |
| 154 | nullptr, 0)); |
| 155 | WasmEdge_ModuleInstanceAddFunction( |
| 156 | Host, StringView{"hostFnOverwrite"}, |
| 157 | WasmEdge_FunctionInstanceCreate( |
| 158 | Ptr{TRY(WasmEdge_FunctionTypeCreate)(nullptr, 0, nullptr, 0)}, |
| 159 | [](void *, const WasmEdge_CallingFrameContext *, |
| 160 | const WasmEdge_Value *, WasmEdge_Value *) { |
| 161 | hostFnOverwrite(); |
| 162 | return WasmEdge_Result_Success; |
| 163 | }, |
| 164 | nullptr, 0)); |
| 165 | TRY(WasmEdge_ExecutorRegisterImport)(Executor, Store, Host); |
| 166 | |
| 167 | Ptr<WasmEdge_ModuleInstanceContext> Instance; |
| 168 | TRY(WasmEdge_ExecutorInstantiate)(Executor, Instance, Store, Module); |
| 169 | auto *WasmFn = |
| 170 | TRY(WasmEdge_ModuleInstanceFindFunction)(Instance, StringView{FnName}); |
| 171 | ExecutorsStack.push(Executor); |
| 172 | TRY(WasmEdge_ExecutorInvoke)(Executor, WasmFn, nullptr, 0, nullptr, 0); |
| 173 | ExecutorsStack.pop(); |
| 174 | } |
| 175 | |
| 176 | size_t CalledHostFnCheck = 0; |
| 177 | void hostFnCheck(const WasmEdge_CallingFrameContext *Frame) { |
no test coverage detected