@@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- use std:: cmp:: { max, min} ;
18
- use std:: time:: Duration ;
17
+ use std:: cmp:: max;
19
18
20
19
use tracing:: { instrument, Span } ;
21
20
@@ -56,31 +55,6 @@ pub struct SandboxConfiguration {
56
55
/// field should be represented as an `Option`, that type is not
57
56
/// FFI-safe, so it cannot be.
58
57
heap_size_override : u64 ,
59
- /// The max_execution_time of a guest execution in milliseconds. If set to 0, the max_execution_time
60
- /// will be set to the default value of 1000ms if the guest execution does not complete within the time specified
61
- /// then the execution will be cancelled, the minimum value is 1ms
62
- ///
63
- /// Note: this is a C-compatible struct, so even though this optional
64
- /// field should be represented as an `Option`, that type is not
65
- /// FFI-safe, so it cannot be.
66
- ///
67
- max_execution_time : u16 ,
68
- /// The max_wait_for_cancellation represents the maximum time the host should wait for a guest execution to be cancelled
69
- /// If set to 0, the max_wait_for_cancellation will be set to the default value of 10ms.
70
- /// The minimum value is 1ms.
71
- ///
72
- /// Note: this is a C-compatible struct, so even though this optional
73
- /// field should be represented as an `Option`, that type is not
74
- /// FFI-safe, so it cannot be.
75
- max_wait_for_cancellation : u8 ,
76
- // The max_initialization_time represents the maximum time the host should wait for a guest to initialize
77
- // If set to 0, the max_initialization_time will be set to the default value of 2000ms.
78
- // The minimum value is 1ms.
79
- //
80
- // Note: this is a C-compatible struct, so even though this optional
81
- // field should be represented as an `Option`, that type is not
82
- // FFI-safe, so it cannot be.
83
- max_initialization_time : u16 ,
84
58
}
85
59
86
60
impl SandboxConfiguration {
@@ -92,24 +66,6 @@ impl SandboxConfiguration {
92
66
pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
93
67
/// The minimum size of output data
94
68
pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
95
- /// The default value for max initialization time (in milliseconds)
96
- pub const DEFAULT_MAX_INITIALIZATION_TIME : u16 = 2000 ;
97
- /// The minimum value for max initialization time (in milliseconds)
98
- pub const MIN_MAX_INITIALIZATION_TIME : u16 = 1 ;
99
- /// The maximum value for max initialization time (in milliseconds)
100
- pub const MAX_MAX_INITIALIZATION_TIME : u16 = u16:: MAX ;
101
- /// The default and minimum values for max execution time (in milliseconds)
102
- pub const DEFAULT_MAX_EXECUTION_TIME : u16 = 1000 ;
103
- /// The minimum value for max execution time (in milliseconds)
104
- pub const MIN_MAX_EXECUTION_TIME : u16 = 1 ;
105
- /// The maximum value for max execution time (in milliseconds)
106
- pub const MAX_MAX_EXECUTION_TIME : u16 = u16:: MAX ;
107
- /// The default and minimum values for max wait for cancellation (in milliseconds)
108
- pub const DEFAULT_MAX_WAIT_FOR_CANCELLATION : u8 = 100 ;
109
- /// The minimum value for max wait for cancellation (in milliseconds)
110
- pub const MIN_MAX_WAIT_FOR_CANCELLATION : u8 = 10 ;
111
- /// The maximum value for max wait for cancellation (in milliseconds)
112
- pub const MAX_MAX_WAIT_FOR_CANCELLATION : u8 = u8:: MAX ;
113
69
114
70
#[ allow( clippy:: too_many_arguments) ]
115
71
/// Create a new configuration for a sandbox with the given sizes.
@@ -119,63 +75,14 @@ impl SandboxConfiguration {
119
75
output_data_size : usize ,
120
76
stack_size_override : Option < u64 > ,
121
77
heap_size_override : Option < u64 > ,
122
- max_execution_time : Option < Duration > ,
123
- max_initialization_time : Option < Duration > ,
124
- max_wait_for_cancellation : Option < Duration > ,
125
78
#[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
126
79
) -> Self {
127
80
Self {
128
81
input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
129
82
output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
130
83
stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
131
84
heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
132
- max_execution_time : {
133
- match max_execution_time {
134
- Some ( max_execution_time) => match max_execution_time. as_millis ( ) {
135
- 0 => Self :: DEFAULT_MAX_EXECUTION_TIME ,
136
- 1 .. => min (
137
- Self :: MAX_MAX_EXECUTION_TIME . into ( ) ,
138
- max (
139
- max_execution_time. as_millis ( ) ,
140
- Self :: MIN_MAX_EXECUTION_TIME . into ( ) ,
141
- ) ,
142
- ) as u16 ,
143
- } ,
144
- None => Self :: DEFAULT_MAX_EXECUTION_TIME ,
145
- }
146
- } ,
147
- max_wait_for_cancellation : {
148
- match max_wait_for_cancellation {
149
- Some ( max_wait_for_cancellation) => {
150
- match max_wait_for_cancellation. as_millis ( ) {
151
- 0 => Self :: DEFAULT_MAX_WAIT_FOR_CANCELLATION ,
152
- 1 .. => min (
153
- Self :: MAX_MAX_WAIT_FOR_CANCELLATION . into ( ) ,
154
- max (
155
- max_wait_for_cancellation. as_millis ( ) ,
156
- Self :: MIN_MAX_WAIT_FOR_CANCELLATION . into ( ) ,
157
- ) ,
158
- ) as u8 ,
159
- }
160
- }
161
- None => Self :: DEFAULT_MAX_WAIT_FOR_CANCELLATION ,
162
- }
163
- } ,
164
- max_initialization_time : {
165
- match max_initialization_time {
166
- Some ( max_initialization_time) => match max_initialization_time. as_millis ( ) {
167
- 0 => Self :: DEFAULT_MAX_INITIALIZATION_TIME ,
168
- 1 .. => min (
169
- Self :: MAX_MAX_INITIALIZATION_TIME . into ( ) ,
170
- max (
171
- max_initialization_time. as_millis ( ) ,
172
- Self :: MIN_MAX_INITIALIZATION_TIME . into ( ) ,
173
- ) ,
174
- ) as u16 ,
175
- } ,
176
- None => Self :: DEFAULT_MAX_INITIALIZATION_TIME ,
177
- }
178
- } ,
85
+
179
86
#[ cfg( gdb) ]
180
87
guest_debug_info,
181
88
}
@@ -207,62 +114,6 @@ impl SandboxConfiguration {
207
114
self . heap_size_override = heap_size;
208
115
}
209
116
210
- /// Set the maximum execution time of a guest function execution. If set to 0, the max_execution_time
211
- /// will be set to the default value of DEFAULT_MAX_EXECUTION_TIME if the guest execution does not complete within the time specified
212
- /// then the execution will be cancelled, the minimum value is MIN_MAX_EXECUTION_TIME
213
- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
214
- pub fn set_max_execution_time ( & mut self , max_execution_time : Duration ) {
215
- match max_execution_time. as_millis ( ) {
216
- 0 => self . max_execution_time = Self :: DEFAULT_MAX_EXECUTION_TIME ,
217
- 1 .. => {
218
- self . max_execution_time = min (
219
- Self :: MAX_MAX_EXECUTION_TIME . into ( ) ,
220
- max (
221
- max_execution_time. as_millis ( ) ,
222
- Self :: MIN_MAX_EXECUTION_TIME . into ( ) ,
223
- ) ,
224
- ) as u16
225
- }
226
- }
227
- }
228
-
229
- /// Set the maximum time to wait for guest execution calculation. If set to 0, the maximum cancellation time
230
- /// will be set to the default value of DEFAULT_MAX_WAIT_FOR_CANCELLATION if the guest execution cancellation does not complete within the time specified
231
- /// then an error will be returned, the minimum value is MIN_MAX_WAIT_FOR_CANCELLATION
232
- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
233
- pub fn set_max_execution_cancel_wait_time ( & mut self , max_wait_for_cancellation : Duration ) {
234
- match max_wait_for_cancellation. as_millis ( ) {
235
- 0 => self . max_wait_for_cancellation = Self :: DEFAULT_MAX_WAIT_FOR_CANCELLATION ,
236
- 1 .. => {
237
- self . max_wait_for_cancellation = min (
238
- Self :: MAX_MAX_WAIT_FOR_CANCELLATION . into ( ) ,
239
- max (
240
- max_wait_for_cancellation. as_millis ( ) ,
241
- Self :: MIN_MAX_WAIT_FOR_CANCELLATION . into ( ) ,
242
- ) ,
243
- ) as u8
244
- }
245
- }
246
- }
247
-
248
- /// Set the maximum time to wait for guest initialization. If set to 0, the maximum initialization time
249
- /// will be set to the default value of DEFAULT_MAX_INITIALIZATION_TIME if the guest initialization does not complete within the time specified
250
- /// then an error will be returned, the minimum value is MIN_MAX_INITIALIZATION_TIME
251
- pub fn set_max_initialization_time ( & mut self , max_initialization_time : Duration ) {
252
- match max_initialization_time. as_millis ( ) {
253
- 0 => self . max_initialization_time = Self :: DEFAULT_MAX_INITIALIZATION_TIME ,
254
- 1 .. => {
255
- self . max_initialization_time = min (
256
- Self :: MAX_MAX_INITIALIZATION_TIME . into ( ) ,
257
- max (
258
- max_initialization_time. as_millis ( ) ,
259
- Self :: MIN_MAX_INITIALIZATION_TIME . into ( ) ,
260
- ) ,
261
- ) as u16
262
- }
263
- }
264
- }
265
-
266
117
/// Sets the configuration for the guest debug
267
118
#[ cfg( gdb) ]
268
119
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -280,20 +131,6 @@ impl SandboxConfiguration {
280
131
self . output_data_size
281
132
}
282
133
283
- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
284
- pub ( crate ) fn get_max_execution_time ( & self ) -> u16 {
285
- self . max_execution_time
286
- }
287
-
288
- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
289
- pub ( crate ) fn get_max_wait_for_cancellation ( & self ) -> u8 {
290
- self . max_wait_for_cancellation
291
- }
292
-
293
- pub ( crate ) fn get_max_initialization_time ( & self ) -> u16 {
294
- self . max_initialization_time
295
- }
296
-
297
134
#[ cfg( gdb) ]
298
135
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
299
136
pub ( crate ) fn get_guest_debug_info ( & self ) -> Option < DebugInfo > {
@@ -335,9 +172,6 @@ impl Default for SandboxConfiguration {
335
172
Self :: DEFAULT_OUTPUT_SIZE ,
336
173
None ,
337
174
None ,
338
- None ,
339
- None ,
340
- None ,
341
175
#[ cfg( gdb) ]
342
176
None ,
343
177
)
@@ -346,8 +180,6 @@ impl Default for SandboxConfiguration {
346
180
347
181
#[ cfg( test) ]
348
182
mod tests {
349
- use std:: time:: Duration ;
350
-
351
183
use super :: SandboxConfiguration ;
352
184
use crate :: testing:: simple_guest_exe_info;
353
185
@@ -357,21 +189,11 @@ mod tests {
357
189
const HEAP_SIZE_OVERRIDE : u64 = 0x50000 ;
358
190
const INPUT_DATA_SIZE_OVERRIDE : usize = 0x4000 ;
359
191
const OUTPUT_DATA_SIZE_OVERRIDE : usize = 0x4001 ;
360
- const MAX_EXECUTION_TIME_OVERRIDE : u16 = 1010 ;
361
- const MAX_WAIT_FOR_CANCELLATION_OVERRIDE : u8 = 200 ;
362
- const MAX_INITIALIZATION_TIME_OVERRIDE : u16 = 2000 ;
363
192
let mut cfg = SandboxConfiguration :: new (
364
193
INPUT_DATA_SIZE_OVERRIDE ,
365
194
OUTPUT_DATA_SIZE_OVERRIDE ,
366
195
Some ( STACK_SIZE_OVERRIDE ) ,
367
196
Some ( HEAP_SIZE_OVERRIDE ) ,
368
- Some ( Duration :: from_millis ( MAX_EXECUTION_TIME_OVERRIDE as u64 ) ) ,
369
- Some ( Duration :: from_millis (
370
- MAX_INITIALIZATION_TIME_OVERRIDE as u64 ,
371
- ) ) ,
372
- Some ( Duration :: from_millis (
373
- MAX_WAIT_FOR_CANCELLATION_OVERRIDE as u64 ,
374
- ) ) ,
375
197
#[ cfg( gdb) ]
376
198
None ,
377
199
) ;
@@ -388,15 +210,6 @@ mod tests {
388
210
assert_eq ! ( 2048 , cfg. heap_size_override) ;
389
211
assert_eq ! ( INPUT_DATA_SIZE_OVERRIDE , cfg. input_data_size) ;
390
212
assert_eq ! ( OUTPUT_DATA_SIZE_OVERRIDE , cfg. output_data_size) ;
391
- assert_eq ! ( MAX_EXECUTION_TIME_OVERRIDE , cfg. max_execution_time) ;
392
- assert_eq ! (
393
- MAX_WAIT_FOR_CANCELLATION_OVERRIDE ,
394
- cfg. max_wait_for_cancellation
395
- ) ;
396
- assert_eq ! (
397
- MAX_WAIT_FOR_CANCELLATION_OVERRIDE ,
398
- cfg. max_wait_for_cancellation
399
- ) ;
400
213
}
401
214
402
215
#[ test]
@@ -406,57 +219,19 @@ mod tests {
406
219
SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
407
220
None ,
408
221
None ,
409
- Some ( Duration :: from_millis (
410
- SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
411
- ) ) ,
412
- Some ( Duration :: from_millis (
413
- SandboxConfiguration :: MIN_MAX_INITIALIZATION_TIME as u64 ,
414
- ) ) ,
415
- Some ( Duration :: from_millis (
416
- SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION as u64 - 1 ,
417
- ) ) ,
418
222
#[ cfg( gdb) ]
419
223
None ,
420
224
) ;
421
225
assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
422
226
assert_eq ! ( SandboxConfiguration :: MIN_OUTPUT_SIZE , cfg. output_data_size) ;
423
227
assert_eq ! ( 0 , cfg. stack_size_override) ;
424
228
assert_eq ! ( 0 , cfg. heap_size_override) ;
425
- assert_eq ! (
426
- SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ,
427
- cfg. max_execution_time
428
- ) ;
429
- assert_eq ! (
430
- SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION ,
431
- cfg. max_wait_for_cancellation
432
- ) ;
433
- assert_eq ! (
434
- SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ,
435
- cfg. max_initialization_time
436
- ) ;
437
229
438
230
cfg. set_input_data_size ( SandboxConfiguration :: MIN_INPUT_SIZE - 1 ) ;
439
231
cfg. set_output_data_size ( SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ) ;
440
- cfg. set_max_execution_time ( Duration :: from_millis (
441
- SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
442
- ) ) ;
443
- cfg. set_max_initialization_time ( Duration :: from_millis (
444
- SandboxConfiguration :: MIN_MAX_INITIALIZATION_TIME as u64 - 1 ,
445
- ) ) ;
446
- cfg. set_max_execution_cancel_wait_time ( Duration :: from_millis (
447
- SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION as u64 - 1 ,
448
- ) ) ;
449
232
450
233
assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
451
234
assert_eq ! ( SandboxConfiguration :: MIN_OUTPUT_SIZE , cfg. output_data_size) ;
452
- assert_eq ! (
453
- SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ,
454
- cfg. max_execution_time
455
- ) ;
456
- assert_eq ! (
457
- SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION ,
458
- cfg. max_wait_for_cancellation
459
- ) ;
460
235
}
461
236
462
237
mod proptests {
@@ -481,27 +256,6 @@ mod tests {
481
256
prop_assert_eq!( size, cfg. get_output_data_size( ) ) ;
482
257
}
483
258
484
- #[ test]
485
- fn max_execution_time( time in SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ..=SandboxConfiguration :: MIN_MAX_EXECUTION_TIME * 10 ) {
486
- let mut cfg = SandboxConfiguration :: default ( ) ;
487
- cfg. set_max_execution_time( std:: time:: Duration :: from_millis( time. into( ) ) ) ;
488
- prop_assert_eq!( time, cfg. get_max_execution_time( ) ) ;
489
- }
490
-
491
- #[ test]
492
- fn max_wait_for_cancellation( time in SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION ..=SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION * 10 ) {
493
- let mut cfg = SandboxConfiguration :: default ( ) ;
494
- cfg. set_max_execution_cancel_wait_time( std:: time:: Duration :: from_millis( time. into( ) ) ) ;
495
- prop_assert_eq!( time, cfg. get_max_wait_for_cancellation( ) ) ;
496
- }
497
-
498
- #[ test]
499
- fn max_initialization_time( time in SandboxConfiguration :: MIN_MAX_INITIALIZATION_TIME ..=SandboxConfiguration :: MIN_MAX_INITIALIZATION_TIME * 10 ) {
500
- let mut cfg = SandboxConfiguration :: default ( ) ;
501
- cfg. set_max_initialization_time( std:: time:: Duration :: from_millis( time. into( ) ) ) ;
502
- prop_assert_eq!( time, cfg. get_max_initialization_time( ) ) ;
503
- }
504
-
505
259
#[ test]
506
260
fn stack_size_override( size in 0x1000 ..=0x10000u64 ) {
507
261
let mut cfg = SandboxConfiguration :: default ( ) ;
0 commit comments