File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,14 @@ pub struct WasiThreadsCtx<T> {
1818}
1919
2020impl < 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+ }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments