@@ -15,6 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
use std:: cmp:: max;
18
+ use std:: time:: Duration ;
18
19
19
20
use tracing:: { instrument, Span } ;
20
21
@@ -55,6 +56,8 @@ pub struct SandboxConfiguration {
55
56
/// field should be represented as an `Option`, that type is not
56
57
/// FFI-safe, so it cannot be.
57
58
heap_size_override : u64 ,
59
+ /// Interrupt retry delay
60
+ interrupt_retry_delay : Duration ,
58
61
}
59
62
60
63
impl SandboxConfiguration {
@@ -66,6 +69,8 @@ impl SandboxConfiguration {
66
69
pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
67
70
/// The minimum size of output data
68
71
pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
72
+ /// The default interrupt retry delay
73
+ pub const DEFAULT_INTERRUPT_RETRY_DELAY : Duration = Duration :: from_micros ( 500 ) ;
69
74
70
75
#[ allow( clippy:: too_many_arguments) ]
71
76
/// Create a new configuration for a sandbox with the given sizes.
@@ -75,13 +80,15 @@ impl SandboxConfiguration {
75
80
output_data_size : usize ,
76
81
stack_size_override : Option < u64 > ,
77
82
heap_size_override : Option < u64 > ,
83
+ interrutp_retry_delay : Duration ,
78
84
#[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
79
85
) -> Self {
80
86
Self {
81
87
input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
82
88
output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
83
89
stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
84
90
heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
91
+ interrupt_retry_delay : interrutp_retry_delay,
85
92
86
93
#[ cfg( gdb) ]
87
94
guest_debug_info,
@@ -114,6 +121,16 @@ impl SandboxConfiguration {
114
121
self . heap_size_override = heap_size;
115
122
}
116
123
124
+ /// Sets the interrupt retry delay
125
+ pub fn set_interrupt_retry_delay ( & mut self , delay : Duration ) {
126
+ self . interrupt_retry_delay = delay;
127
+ }
128
+
129
+ /// Get the delay between retries for interrupts
130
+ pub fn get_interrupt_retry_delay ( & self ) -> Duration {
131
+ self . interrupt_retry_delay
132
+ }
133
+
117
134
/// Sets the configuration for the guest debug
118
135
#[ cfg( gdb) ]
119
136
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -172,6 +189,7 @@ impl Default for SandboxConfiguration {
172
189
Self :: DEFAULT_OUTPUT_SIZE ,
173
190
None ,
174
191
None ,
192
+ Self :: DEFAULT_INTERRUPT_RETRY_DELAY ,
175
193
#[ cfg( gdb) ]
176
194
None ,
177
195
)
@@ -194,6 +212,7 @@ mod tests {
194
212
OUTPUT_DATA_SIZE_OVERRIDE ,
195
213
Some ( STACK_SIZE_OVERRIDE ) ,
196
214
Some ( HEAP_SIZE_OVERRIDE ) ,
215
+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
197
216
#[ cfg( gdb) ]
198
217
None ,
199
218
) ;
@@ -219,6 +238,7 @@ mod tests {
219
238
SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
220
239
None ,
221
240
None ,
241
+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
222
242
#[ cfg( gdb) ]
223
243
None ,
224
244
) ;
0 commit comments