Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasm-mico-runtime shim implementation #642

Closed
wants to merge 3 commits into from

Conversation

macko99
Copy link

@macko99 macko99 commented Jul 13, 2024

this is an updated PR using adding addtional shim implementation: Wamr using latest wamr-rust-sdk.

It is still not working, the shim exits with one of the errors:
-"thread signal env initialized failed"
-without any error
-"error running start function: Failed to create instance: InstantiationFailure("error while pre-opening mapped directory: invalid map"
-"Running "_start"" then "Error: ExecutionError("Exception: unreachable")"

My module has only the main function defined.
I have tried disabling hardware checks in WAMR since I'm working on the VM, commit

FYI @squillace @0xE282B0 @lum1n0us @Mossaka


impl Clone for WamrEngine {
fn clone(&self) -> Self {
let runtime = Runtime::new().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is this a deep clone or shallow clone? Runwasi clones the runtime so that it could share to different instances. (i.e. https://github.com/containerd/runwasi/blob/main/crates/containerd-shim-wasm/src/sandbox/instance.rs#L98)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In wamr-rust-sdk, it'll execute +1 on runtime's reference counter.

log::info!("Create a WASI context");

let wasi_ctx = WasiCtxBuilder::new()
.set_pre_open_path(vec!["/"], vec!["/"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.set_pre_open_path(vec!["/"], vec!["/"])
.set_pre_open_path(vec!["/"], vec![])

let wasi_ctx = WasiCtxBuilder::new()
.set_pre_open_path(vec!["/"], vec!["/"])
.set_env_vars(envs.iter().map(String::as_str).collect())
.build();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.build();
.set_arguments(args.iter().map(String::as_str).collect())
.build();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to pass arguments (like "wasi-demo-oci.wasm echo 'hi'") to wasm functions.

let function = Function::find_export_func(&instance, &func)
.map_err(|e| anyhow::Error::msg(format!("Failed to find function: {:?}", e)))?;
let status = function
.call(&instance, &Vec::new())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case.

Suggested change
.call(&instance, &Vec::new())
.call(&instance, &vec![]))

@lum1n0us
Copy link

lum1n0us commented Jul 25, 2024

  • Need to sync up with latest wamr-rust-sdk.
diff --git a/crates/containerd-shim-wamr/Cargo.toml b/crates/containerd-shim-wamr/Cargo.toml
index 2dd3178..7ea5e0a 100644
--- a/crates/containerd-shim-wamr/Cargo.toml
+++ b/crates/containerd-shim-wamr/Cargo.toml
@@ -13,7 +13,7 @@ oci-spec = { workspace = true, features = ["runtime"] }
 ttrpc = { workspace = true }
 sha256 = { workspace = true }

-wamr-rust-sdk = { git = "https://github.com/macko99/wamr-rust-sdk", branch = "main" }
+wamr-rust-sdk = { git = "https://github.com/bytecodealliance/wamr-rust-sdk", branch = "main" }

 [dev-dependencies]
 containerd-shim-wasm = { workspace = true, features = ["testing"] }
  • Pass wasm arguments
diff --git a/crates/containerd-shim-wamr/src/instance.rs b/crates/containerd-shim-wamr/src/instance.rs
index b1f15e3..8632a53 100644
--- a/crates/containerd-shim-wamr/src/instance.rs
+++ b/crates/containerd-shim-wamr/src/instance.rs
@@ -66,9 +66,10 @@ impl Engine for WamrEngine {
         log::info!("Create a WASI context");

         let wasi_ctx = WasiCtxBuilder::new()
-        .set_pre_open_path(vec!["/"], vec![])
-        .set_env_vars(envs.iter().map(String::as_str).collect())
-        .build();
+            .set_pre_open_path(vec!["/"], vec![])
+            .set_env_vars(envs.iter().map(String::as_str).collect())
+            .set_arguments(args.iter().map(String::as_str).collect())
+            .build();

         module.set_wasi_context(wasi_ctx);

Then it should work

@lum1n0us
Copy link

@lum1n0us
Copy link

@Mossaka any update? Let me know if you need any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants