@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- use std:: cmp:: max;
17+ use std:: { cmp:: max, time :: Duration } ;
1818
1919use tracing:: { instrument, Span } ;
2020
@@ -55,6 +55,8 @@ pub struct SandboxConfiguration {
5555 /// field should be represented as an `Option`, that type is not
5656 /// FFI-safe, so it cannot be.
5757 heap_size_override : u64 ,
58+ /// Interrupt retry delay
59+ interrupt_retry_delay : Duration ,
5860}
5961
6062impl SandboxConfiguration {
@@ -66,6 +68,8 @@ impl SandboxConfiguration {
6668 pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
6769 /// The minimum size of output data
6870 pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
71+ /// The default interrupt retry delay
72+ pub const DEFAULT_INTERRUPT_RETRY_DELAY : Duration = Duration :: from_micros ( 500 ) ;
6973
7074 #[ allow( clippy:: too_many_arguments) ]
7175 /// Create a new configuration for a sandbox with the given sizes.
@@ -75,13 +79,15 @@ impl SandboxConfiguration {
7579 output_data_size : usize ,
7680 stack_size_override : Option < u64 > ,
7781 heap_size_override : Option < u64 > ,
82+ interrutp_retry_delay : Duration ,
7883 #[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
7984 ) -> Self {
8085 Self {
8186 input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
8287 output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
8388 stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
8489 heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
90+ interrupt_retry_delay : interrutp_retry_delay,
8591
8692 #[ cfg( gdb) ]
8793 guest_debug_info,
@@ -114,6 +120,16 @@ impl SandboxConfiguration {
114120 self . heap_size_override = heap_size;
115121 }
116122
123+ /// Sets the interrupt retry delay
124+ pub fn set_interrupt_retry_delay ( & mut self , delay : Duration ) {
125+ self . interrupt_retry_delay = delay;
126+ }
127+
128+ /// Get the delay between retries for interrupts
129+ pub fn get_interrupt_retry_delay ( & self ) -> Duration {
130+ self . interrupt_retry_delay
131+ }
132+
117133 /// Sets the configuration for the guest debug
118134 #[ cfg( gdb) ]
119135 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -172,6 +188,7 @@ impl Default for SandboxConfiguration {
172188 Self :: DEFAULT_OUTPUT_SIZE ,
173189 None ,
174190 None ,
191+ Self :: DEFAULT_INTERRUPT_RETRY_DELAY ,
175192 #[ cfg( gdb) ]
176193 None ,
177194 )
@@ -194,6 +211,7 @@ mod tests {
194211 OUTPUT_DATA_SIZE_OVERRIDE ,
195212 Some ( STACK_SIZE_OVERRIDE ) ,
196213 Some ( HEAP_SIZE_OVERRIDE ) ,
214+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
197215 #[ cfg( gdb) ]
198216 None ,
199217 ) ;
@@ -219,6 +237,7 @@ mod tests {
219237 SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
220238 None ,
221239 None ,
240+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
222241 #[ cfg( gdb) ]
223242 None ,
224243 ) ;
0 commit comments