Skip to content

Commit 750ba9a

Browse files
unify execute_wasmtime and execute_with_lind (#903)
1 parent e5eb83c commit 750ba9a

File tree

2 files changed

+4
-36
lines changed
  • src
    • lind-boot/src/lind_wasmtime
    • wasmtime/crates/lind-multi-process/src

2 files changed

+4
-36
lines changed

src/lind-boot/src/lind_wasmtime/execute.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ use wasmtime_wasi_threads::WasiThreadsCtx;
4747
/// shutting down RawPOSIX, ensuring runtime-wide cleanup happens only after the
4848
/// last process terminates.
4949
pub fn execute_wasmtime(lindboot_cli: CliOptions) -> anyhow::Result<Vec<Val>> {
50-
// -- Initialize the Wasmtime execution environment --
51-
let wasm_file_path = Path::new(lindboot_cli.wasm_file());
52-
let args = lindboot_cli.args.clone();
53-
let wt_config = make_wasmtime_config(lindboot_cli.wasmtime_backtrace);
54-
let engine = Engine::new(&wt_config).context("failed to create execution engine")?;
55-
let host = HostCtx::default();
56-
let mut wstore = Store::new(&engine, host);
57-
5850
// -- Initialize Lind + RawPOSIX + 3i runtime --
5951
// Initialize the Lind cage counter
6052
let lind_manager = Arc::new(LindCageManager::new(0));
@@ -75,30 +67,8 @@ pub fn execute_wasmtime(lindboot_cli: CliOptions) -> anyhow::Result<Vec<Val>> {
7567
panic!("[lind-boot] egister syscall handlers (clone/exec/exit) with 3i failed");
7668
}
7769

78-
// -- Load module and attach host APIs --
79-
let module = read_wasm_or_cwasm(&engine, wasm_file_path)?;
80-
let mut linker = Linker::new(&engine);
81-
82-
attach_api(
83-
&mut wstore,
84-
&mut linker,
85-
&module,
86-
lind_manager.clone(),
87-
lindboot_cli.clone(),
88-
None,
89-
)?;
90-
9170
// -- Run the first module in the first cage --
92-
let result = wasmtime_wasi::runtime::with_ambient_tokio_runtime(|| {
93-
load_main_module(
94-
&mut wstore,
95-
&mut linker,
96-
&module,
97-
CAGE_START_ID as u64,
98-
&args,
99-
)
100-
.with_context(|| format!("failed to run main module"))
101-
});
71+
let result = execute_with_lind(lindboot_cli, lind_manager.clone(), CAGE_START_ID as u64);
10272

10373
match result {
10474
Ok(ref _res) => {
@@ -149,7 +119,7 @@ pub fn execute_with_lind(
149119
&module,
150120
lind_manager.clone(),
151121
lind_boot.clone(),
152-
Some(cageid as i32),
122+
cageid as i32,
153123
)?;
154124

155125
// -- Run the module in the cage --
@@ -271,7 +241,7 @@ fn attach_api(
271241
module: &Module,
272242
lind_manager: Arc<LindCageManager>,
273243
lindboot_cli: CliOptions,
274-
cageid: Option<i32>,
244+
cageid: i32,
275245
) -> Result<()> {
276246
// Initialize argv/environ data and attach all Lind host functions
277247
// (syscall dispatch, debug, signals, and argv/environ) to the linker.

src/wasmtime/crates/lind-multi-process/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<
116116
linker: Linker<T>,
117117
lind_manager: Arc<LindCageManager>,
118118
lindboot_cli: U,
119-
cageid: Option<i32>,
119+
cageid: i32,
120120
get_cx: impl Fn(&mut T) -> &mut LindCtx<T, U> + Send + Sync + 'static,
121121
fork_host: impl Fn(&T) -> T + Send + Sync + 'static,
122122
exec: impl Fn(
@@ -138,8 +138,6 @@ impl<
138138
let fork_host = Arc::new(fork_host);
139139
let exec_host = Arc::new(exec);
140140

141-
// cage id starts from 1
142-
let cageid = cageid.unwrap_or(CAGE_START_ID);
143141
let tid = THREAD_START_ID;
144142
let next_threadid = Arc::new(AtomicU32::new(THREAD_START_ID as u32)); // cageid starts from 1
145143
Ok(Self {

0 commit comments

Comments
 (0)