@@ -15,6 +15,7 @@ limitations under the License.
1515*/
1616
1717use std:: cmp:: max;
18+ use std:: time:: Duration ;
1819
1920use tracing:: { instrument, Span } ;
2021
@@ -55,6 +56,8 @@ pub struct SandboxConfiguration {
5556 /// field should be represented as an `Option`, that type is not
5657 /// FFI-safe, so it cannot be.
5758 heap_size_override : u64 ,
59+ /// Interrupt retry delay
60+ interrupt_retry_delay : Duration ,
5861}
5962
6063impl SandboxConfiguration {
@@ -66,6 +69,8 @@ impl SandboxConfiguration {
6669 pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
6770 /// The minimum size of output data
6871 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 ) ;
6974
7075 #[ allow( clippy:: too_many_arguments) ]
7176 /// Create a new configuration for a sandbox with the given sizes.
@@ -75,13 +80,15 @@ impl SandboxConfiguration {
7580 output_data_size : usize ,
7681 stack_size_override : Option < u64 > ,
7782 heap_size_override : Option < u64 > ,
83+ interrutp_retry_delay : Duration ,
7884 #[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
7985 ) -> Self {
8086 Self {
8187 input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
8288 output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
8389 stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
8490 heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
91+ interrupt_retry_delay : interrutp_retry_delay,
8592
8693 #[ cfg( gdb) ]
8794 guest_debug_info,
@@ -114,6 +121,16 @@ impl SandboxConfiguration {
114121 self . heap_size_override = heap_size;
115122 }
116123
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+
117134 /// Sets the configuration for the guest debug
118135 #[ cfg( gdb) ]
119136 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -172,6 +189,7 @@ impl Default for SandboxConfiguration {
172189 Self :: DEFAULT_OUTPUT_SIZE ,
173190 None ,
174191 None ,
192+ Self :: DEFAULT_INTERRUPT_RETRY_DELAY ,
175193 #[ cfg( gdb) ]
176194 None ,
177195 )
@@ -194,6 +212,7 @@ mod tests {
194212 OUTPUT_DATA_SIZE_OVERRIDE ,
195213 Some ( STACK_SIZE_OVERRIDE ) ,
196214 Some ( HEAP_SIZE_OVERRIDE ) ,
215+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
197216 #[ cfg( gdb) ]
198217 None ,
199218 ) ;
@@ -219,6 +238,7 @@ mod tests {
219238 SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
220239 None ,
221240 None ,
241+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
222242 #[ cfg( gdb) ]
223243 None ,
224244 ) ;
0 commit comments