@@ -16,8 +16,8 @@ use spin_factors::{
16
16
RuntimeFactors , RuntimeFactorsInstanceState ,
17
17
} ;
18
18
use wasmtime_wasi:: {
19
- DirPerms , FilePerms , ResourceTable , StdinStream , StdoutStream , WasiCtx , WasiCtxBuilder ,
20
- WasiImpl , WasiView ,
19
+ DirPerms , FilePerms , IoImpl , IoView , ResourceTable , StdinStream , StdoutStream , WasiCtx ,
20
+ WasiCtxBuilder , WasiImpl , WasiView ,
21
21
} ;
22
22
23
23
pub use wasmtime_wasi:: SocketAddrUse ;
@@ -37,10 +37,10 @@ impl WasiFactor {
37
37
runtime_instance_state : & mut impl RuntimeFactorsInstanceState ,
38
38
) -> Option < WasiImpl < impl WasiView + ' _ > > {
39
39
let ( state, table) = runtime_instance_state. get_with_table :: < WasiFactor > ( ) ?;
40
- Some ( WasiImpl ( WasiImplInner {
40
+ Some ( WasiImpl ( IoImpl ( WasiImplInner {
41
41
ctx : & mut state. ctx ,
42
42
table,
43
- } ) )
43
+ } ) ) )
44
44
}
45
45
}
46
46
@@ -50,52 +50,63 @@ impl Factor for WasiFactor {
50
50
type InstanceBuilder = InstanceBuilder ;
51
51
52
52
fn init < T : Send + ' static > ( & mut self , mut ctx : InitContext < T , Self > ) -> anyhow:: Result < ( ) > {
53
- fn type_annotate < T , F > ( f : F ) -> F
53
+ fn type_annotate_wasi < T , F > ( f : F ) -> F
54
54
where
55
55
F : Fn ( & mut T ) -> WasiImpl < WasiImplInner > ,
56
56
{
57
57
f
58
58
}
59
+ fn type_annotate_io < T , F > ( f : F ) -> F
60
+ where
61
+ F : Fn ( & mut T ) -> IoImpl < WasiImplInner > ,
62
+ {
63
+ f
64
+ }
59
65
let get_data_with_table = ctx. get_data_with_table_fn ( ) ;
60
- let closure = type_annotate ( move |data| {
66
+ let io_closure = type_annotate_io ( move |data| {
61
67
let ( state, table) = get_data_with_table ( data) ;
62
- WasiImpl ( WasiImplInner {
68
+ IoImpl ( WasiImplInner {
63
69
ctx : & mut state. ctx ,
64
70
table,
65
71
} )
66
72
} ) ;
73
+ let wasi_closure = type_annotate_wasi ( move |data| WasiImpl ( io_closure ( data) ) ) ;
67
74
let linker = ctx. linker ( ) ;
68
75
use wasmtime_wasi:: bindings;
69
- bindings:: clocks:: wall_clock:: add_to_linker_get_host ( linker, closure) ?;
70
- bindings:: clocks:: monotonic_clock:: add_to_linker_get_host ( linker, closure) ?;
71
- bindings:: filesystem:: types:: add_to_linker_get_host ( linker, closure) ?;
72
- bindings:: filesystem:: preopens:: add_to_linker_get_host ( linker, closure) ?;
73
- bindings:: io:: error:: add_to_linker_get_host ( linker, closure) ?;
74
- bindings:: io:: poll:: add_to_linker_get_host ( linker, closure) ?;
75
- bindings:: io:: streams:: add_to_linker_get_host ( linker, closure) ?;
76
- bindings:: random:: random:: add_to_linker_get_host ( linker, closure) ?;
77
- bindings:: random:: insecure:: add_to_linker_get_host ( linker, closure) ?;
78
- bindings:: random:: insecure_seed:: add_to_linker_get_host ( linker, closure) ?;
79
- bindings:: cli:: exit:: add_to_linker_get_host ( linker, & Default :: default ( ) , closure) ?;
80
- bindings:: cli:: environment:: add_to_linker_get_host ( linker, closure) ?;
81
- bindings:: cli:: stdin:: add_to_linker_get_host ( linker, closure) ?;
82
- bindings:: cli:: stdout:: add_to_linker_get_host ( linker, closure) ?;
83
- bindings:: cli:: stderr:: add_to_linker_get_host ( linker, closure) ?;
84
- bindings:: cli:: terminal_input:: add_to_linker_get_host ( linker, closure) ?;
85
- bindings:: cli:: terminal_output:: add_to_linker_get_host ( linker, closure) ?;
86
- bindings:: cli:: terminal_stdin:: add_to_linker_get_host ( linker, closure) ?;
87
- bindings:: cli:: terminal_stdout:: add_to_linker_get_host ( linker, closure) ?;
88
- bindings:: cli:: terminal_stderr:: add_to_linker_get_host ( linker, closure) ?;
89
- bindings:: sockets:: tcp:: add_to_linker_get_host ( linker, closure) ?;
90
- bindings:: sockets:: tcp_create_socket:: add_to_linker_get_host ( linker, closure) ?;
91
- bindings:: sockets:: udp:: add_to_linker_get_host ( linker, closure) ?;
92
- bindings:: sockets:: udp_create_socket:: add_to_linker_get_host ( linker, closure) ?;
93
- bindings:: sockets:: instance_network:: add_to_linker_get_host ( linker, closure) ?;
94
- bindings:: sockets:: network:: add_to_linker_get_host ( linker, & Default :: default ( ) , closure) ?;
95
- bindings:: sockets:: ip_name_lookup:: add_to_linker_get_host ( linker, closure) ?;
96
-
97
- wasi_2023_10_18:: add_to_linker ( linker, closure) ?;
98
- wasi_2023_11_10:: add_to_linker ( linker, closure) ?;
76
+ bindings:: clocks:: wall_clock:: add_to_linker_get_host ( linker, wasi_closure) ?;
77
+ bindings:: clocks:: monotonic_clock:: add_to_linker_get_host ( linker, wasi_closure) ?;
78
+ bindings:: filesystem:: types:: add_to_linker_get_host ( linker, wasi_closure) ?;
79
+ bindings:: filesystem:: preopens:: add_to_linker_get_host ( linker, wasi_closure) ?;
80
+ bindings:: io:: error:: add_to_linker_get_host ( linker, io_closure) ?;
81
+ bindings:: io:: poll:: add_to_linker_get_host ( linker, io_closure) ?;
82
+ bindings:: io:: streams:: add_to_linker_get_host ( linker, io_closure) ?;
83
+ bindings:: random:: random:: add_to_linker_get_host ( linker, wasi_closure) ?;
84
+ bindings:: random:: insecure:: add_to_linker_get_host ( linker, wasi_closure) ?;
85
+ bindings:: random:: insecure_seed:: add_to_linker_get_host ( linker, wasi_closure) ?;
86
+ bindings:: cli:: exit:: add_to_linker_get_host ( linker, & Default :: default ( ) , wasi_closure) ?;
87
+ bindings:: cli:: environment:: add_to_linker_get_host ( linker, wasi_closure) ?;
88
+ bindings:: cli:: stdin:: add_to_linker_get_host ( linker, wasi_closure) ?;
89
+ bindings:: cli:: stdout:: add_to_linker_get_host ( linker, wasi_closure) ?;
90
+ bindings:: cli:: stderr:: add_to_linker_get_host ( linker, wasi_closure) ?;
91
+ bindings:: cli:: terminal_input:: add_to_linker_get_host ( linker, wasi_closure) ?;
92
+ bindings:: cli:: terminal_output:: add_to_linker_get_host ( linker, wasi_closure) ?;
93
+ bindings:: cli:: terminal_stdin:: add_to_linker_get_host ( linker, wasi_closure) ?;
94
+ bindings:: cli:: terminal_stdout:: add_to_linker_get_host ( linker, wasi_closure) ?;
95
+ bindings:: cli:: terminal_stderr:: add_to_linker_get_host ( linker, wasi_closure) ?;
96
+ bindings:: sockets:: tcp:: add_to_linker_get_host ( linker, wasi_closure) ?;
97
+ bindings:: sockets:: tcp_create_socket:: add_to_linker_get_host ( linker, wasi_closure) ?;
98
+ bindings:: sockets:: udp:: add_to_linker_get_host ( linker, wasi_closure) ?;
99
+ bindings:: sockets:: udp_create_socket:: add_to_linker_get_host ( linker, wasi_closure) ?;
100
+ bindings:: sockets:: instance_network:: add_to_linker_get_host ( linker, wasi_closure) ?;
101
+ bindings:: sockets:: network:: add_to_linker_get_host (
102
+ linker,
103
+ & Default :: default ( ) ,
104
+ wasi_closure,
105
+ ) ?;
106
+ bindings:: sockets:: ip_name_lookup:: add_to_linker_get_host ( linker, wasi_closure) ?;
107
+
108
+ wasi_2023_10_18:: add_to_linker ( linker, wasi_closure) ?;
109
+ wasi_2023_11_10:: add_to_linker ( linker, wasi_closure) ?;
99
110
100
111
Ok ( ( ) )
101
112
}
@@ -288,7 +299,9 @@ impl WasiView for WasiImplInner<'_> {
288
299
fn ctx ( & mut self ) -> & mut WasiCtx {
289
300
self . ctx
290
301
}
302
+ }
291
303
304
+ impl IoView for WasiImplInner < ' _ > {
292
305
fn table ( & mut self ) -> & mut ResourceTable {
293
306
self . table
294
307
}
0 commit comments