Skip to content

[Refactor] Integrate 3i into Wasmtime runtime #238

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

Draft
wants to merge 2 commits into
base: threei
Choose a base branch
from
Draft

Conversation

Yaxuan-w
Copy link
Member

@Yaxuan-w Yaxuan-w commented Jun 9, 2025

This PR refactors the Wasmtime runtime to support 3i-based dynamic syscall interposition.

It introduces
(1) mechanisms for capturing and storing instance context (vmctx)
(2) resolving exported Wasm functions by name at runtime
(3) replacing all original lind_syscall_api in RawPOSIX dispatcher by make_syscall in threei
(4) supporting copy_data_between_cages and copy_handler_table in wasmtime side

Notes:
This can only be tested after all draft PR being merged.

@@ -68,17 +68,25 @@ impl LindCommonCtx {
// exit syscall
30 => wasmtime_lind_multi_process::exit_syscall(caller, arg1 as i32),
// other syscalls goes into rawposix
Copy link
Contributor

Choose a reason for hiding this comment

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

either a long comment explaining the API or link to doc where its explained would be good

Copy link
Member Author

Choose a reason for hiding this comment

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

Add comments

@@ -43,6 +45,26 @@ fn parse_preloads(s: &str) -> Result<(String, PathBuf)> {
Ok((parts[0].into(), parts[1].into()))
}

static VM_TABLE: Lazy<RwLock<Vec<Option<InstanceHandle>>>> = Lazy::new(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

comment what this is and what the functions below do

Copy link
Member Author

Choose a reason for hiding this comment

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

Add comments

insert_ctx(current_pid as usize, grate_instancehandler.clone());
}

let res = threei_test_func(current_pid, Box::new(move |call_ptr: u64, cageid: u64, arg1: u64, arg1cageid: u64, arg2: u64, arg2cageid: u64, arg3: u64, arg3cageid: u64, arg4: u64, arg4cageid: u64, arg5: u64, arg5cageid: u64, arg6: u64, arg6cageid: u64| -> i32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is labeled test function, should this be part of the main codebase?

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed

@@ -186,6 +194,33 @@ pub fn add_to_linker<
},
)?;

// attach register_handler to wasmtime
Copy link
Contributor

Choose a reason for hiding this comment

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

id like more information in the comments on what these do

Copy link
Member Author

Choose a reason for hiding this comment

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

Add comments

@Yaxuan-w Yaxuan-w mentioned this pull request Apr 24, 2025
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.

2 participants