@@ -9,6 +9,7 @@ use crate::runtime::*;
9
9
#[ derive( Default , Clone ) ]
10
10
pub struct Host {
11
11
pub preview1_ctx : Option < wasmtime_wasi:: WasiCtx > ,
12
+ #[ cfg( feature = "multithread" ) ]
12
13
pub wasi_threads : Option < Arc < WasiThreadsCtx < Host > > > ,
13
14
}
14
15
@@ -37,10 +38,13 @@ impl H2O<Host> {
37
38
}
38
39
39
40
let engine = Engine :: new ( & wasm_config) ?;
40
- let linker: Linker < Host > = Linker :: new ( & engine) ;
41
41
42
42
let module = Module :: from_file ( & engine, & conf. filepath ) ?;
43
43
44
+ let linker: Linker < Host > = Linker :: new ( & engine) ;
45
+
46
+ // linker.allow_unknown_exports(true);
47
+
44
48
let host = Host :: default ( ) ;
45
49
let store = Store :: new ( & engine, host) ;
46
50
@@ -143,8 +147,26 @@ impl H2O<Host> {
143
147
version_common:: funcs:: export_config ( & mut linker, conf. config_wasm . clone ( ) ) ?;
144
148
}
145
149
150
+ // linker.define_unknown_imports_as_traps(&module)?;
151
+
146
152
let instance = linker. instantiate ( & mut store, & module) ?;
147
153
154
+ // call _start function explicitly if there is one exported from the WATM module
155
+ let func = instance. get_func ( & mut store, "_start" ) ;
156
+
157
+ if let Some ( func) = func {
158
+ let mut res = vec ! [ Val :: null( ) ; func. ty( & store) . results( ) . len( ) ] ;
159
+ match func. call ( & mut store, & [ ] , & mut res) {
160
+ Ok ( _) => { }
161
+ Err ( e) => {
162
+ return Err ( anyhow:: Error :: msg ( format ! (
163
+ "failed to call _start function: {}" ,
164
+ e
165
+ ) ) )
166
+ }
167
+ }
168
+ }
169
+
148
170
Ok ( H2O {
149
171
version : match version {
150
172
Some ( v) => v,
0 commit comments