| 2370 | } |
| 2371 | |
| 2372 | WASMEDGE_CAPI_EXPORT void WasmEdge_ModuleInstanceInitWASIWithFds( |
| 2373 | WasmEdge_ModuleInstanceContext *Cxt, const char *const *Args, |
| 2374 | const uint32_t ArgLen, const char *const *Envs, const uint32_t EnvLen, |
| 2375 | const char *const *Preopens, const uint32_t PreopenLen, |
| 2376 | const int32_t StdInFd, const int32_t StdOutFd, |
| 2377 | const int32_t StdErrFd) noexcept { |
| 2378 | if (!Cxt) { |
| 2379 | return; |
| 2380 | } |
| 2381 | auto *WasiMod = dynamic_cast<WasmEdge::Host::WasiModule *>(fromModCxt(Cxt)); |
| 2382 | if (!WasiMod) { |
| 2383 | return; |
| 2384 | } |
| 2385 | try { |
| 2386 | std::vector<std::string> ArgVec, EnvVec, DirVec; |
| 2387 | std::string ProgName; |
| 2388 | if (Args) { |
| 2389 | if (ArgLen > 0) { |
| 2390 | ProgName = Args[0]; |
| 2391 | } |
| 2392 | for (uint32_t I = 1; I < ArgLen; I++) { |
| 2393 | ArgVec.emplace_back(Args[I]); |
| 2394 | } |
| 2395 | } |
| 2396 | if (Envs) { |
| 2397 | for (uint32_t I = 0; I < EnvLen; I++) { |
| 2398 | EnvVec.emplace_back(Envs[I]); |
| 2399 | } |
| 2400 | } |
| 2401 | if (Preopens) { |
| 2402 | for (uint32_t I = 0; I < PreopenLen; I++) { |
| 2403 | DirVec.emplace_back(Preopens[I]); |
| 2404 | } |
| 2405 | } |
| 2406 | auto Result = WasiMod->initWithFds(DirVec, ProgName, ArgVec, EnvVec, |
| 2407 | StdInFd, StdOutFd, StdErrFd); |
| 2408 | if (!Result) { |
| 2409 | spdlog::error(" Failed to initialize WASI environment: {}"sv, |
| 2410 | Result.error()); |
| 2411 | } |
| 2412 | } catch (...) { |
| 2413 | handleCAPIError(); |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | WASMEDGE_CAPI_EXPORT extern uint32_t |
| 2418 | WasmEdge_ModuleInstanceWASIGetNativeHandler( |
no test coverage detected