@@ -51,6 +51,7 @@ pub struct Console {
51
51
stdout : ArcBoxFile ,
52
52
stderr : ArcBoxFile ,
53
53
capabilities : Capabilities ,
54
+ memfs_memory_limiter : Option < virtual_fs:: limiter:: DynFsMemoryLimiter > ,
54
55
}
55
56
56
57
impl Console {
@@ -81,6 +82,7 @@ impl Console {
81
82
stdout : ArcBoxFile :: new ( Box :: new ( Pipe :: channel ( ) . 0 ) ) ,
82
83
stderr : ArcBoxFile :: new ( Box :: new ( Pipe :: channel ( ) . 0 ) ) ,
83
84
capabilities : Default :: default ( ) ,
85
+ memfs_memory_limiter : None ,
84
86
}
85
87
}
86
88
@@ -143,6 +145,14 @@ impl Console {
143
145
self
144
146
}
145
147
148
+ pub fn with_mem_fs_memory_limiter (
149
+ mut self ,
150
+ limiter : virtual_fs:: limiter:: DynFsMemoryLimiter ,
151
+ ) -> Self {
152
+ self . memfs_memory_limiter = Some ( limiter) ;
153
+ self
154
+ }
155
+
146
156
pub fn run ( & mut self ) -> Result < ( TaskJoinHandle , WasiProcess ) , VirtualBusError > {
147
157
// Extract the program name from the arguments
148
158
let empty_args: Vec < & [ u8 ] > = Vec :: new ( ) ;
@@ -193,6 +203,18 @@ impl Console {
193
203
// TODO: no unwrap!
194
204
let env = WasiEnv :: from_init ( env_init) . unwrap ( ) ;
195
205
206
+ if let Some ( limiter) = & self . memfs_memory_limiter {
207
+ match & env. state . fs . root_fs {
208
+ crate :: fs:: WasiFsRoot :: Sandbox ( tmpfs) => {
209
+ tmpfs. set_memory_limiter ( limiter. clone ( ) ) ;
210
+ }
211
+ crate :: fs:: WasiFsRoot :: Backing ( _) => {
212
+ tracing:: error!( "tried to set a tmpfs memory limiter on a backing fs" ) ;
213
+ return Err ( VirtualBusError :: InvokeFailed ) ;
214
+ }
215
+ }
216
+ }
217
+
196
218
// TODO: this should not happen here...
197
219
// Display the welcome message
198
220
let tasks = env. tasks ( ) . clone ( ) ;
0 commit comments