Skip to content

Commit a8778f3

Browse files
abrownalexcrichton
andcommitted
review: move entry point check earlier
Co-authored-by: Alex Crichton <[email protected]>
1 parent 21e2740 commit a8778f3

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

crates/wasi-threads/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ pub struct WasiThreadsCtx<T> {
1818
}
1919

2020
impl<T: Clone + Send + 'static> WasiThreadsCtx<T> {
21-
pub fn new(module: Module, linker: Arc<Linker<T>>) -> Self {
22-
Self { module, linker }
21+
pub fn new(module: Module, linker: Arc<Linker<T>>) -> Result<Self> {
22+
if !has_wasi_entry_point(&module) {
23+
bail!(
24+
"failed to find wasi-threads entry point function: {}",
25+
WASI_ENTRY_POINT
26+
);
27+
}
28+
Ok(Self { module, linker })
2329
}
2430

2531
pub fn spawn(&self, host: T, thread_start_arg: i32) -> Result<i32> {
@@ -133,3 +139,14 @@ pub fn add_to_linker<T: Clone + Send + 'static>(
133139
module should import a single shared memory as \"memory\""
134140
))
135141
}
142+
143+
fn has_wasi_entry_point(module: &Module) -> bool {
144+
module
145+
.get_export(WASI_ENTRY_POINT)
146+
.and_then(|t| t.func().cloned())
147+
.and_then(|t| {
148+
let params: Vec<ValType> = t.params().collect();
149+
Some(params == [ValType::I32, ValType::I32] && t.results().len() == 0)
150+
})
151+
.unwrap_or(false)
152+
}

src/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn populate_with_wasi(
505505
host.wasi_threads = Some(std::sync::Arc::new(WasiThreadsCtx::new(
506506
_module,
507507
std::sync::Arc::new(linker.clone()),
508-
)));
508+
)?));
509509
}
510510
}
511511

0 commit comments

Comments
 (0)