@@ -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,13 @@ 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
+ /// Delay between interrupt retries. This duration specifies how long to wait
60
+ /// between attempts to send signals to the thread running the sandbox's VCPU.
61
+ /// Multiple retries may be necessary because signals only interrupt the VCPU
62
+ /// thread when the vcpu thread is in kernel space. There's a narrow window during which a
63
+ /// signal can be delivered to the thread, but the thread may not yet
64
+ /// have entered kernel space.
65
+ interrupt_retry_delay : Duration ,
58
66
}
59
67
60
68
impl SandboxConfiguration {
@@ -66,6 +74,8 @@ impl SandboxConfiguration {
66
74
pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
67
75
/// The minimum size of output data
68
76
pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
77
+ /// The default interrupt retry delay
78
+ pub const DEFAULT_INTERRUPT_RETRY_DELAY : Duration = Duration :: from_micros ( 500 ) ;
69
79
70
80
#[ allow( clippy:: too_many_arguments) ]
71
81
/// Create a new configuration for a sandbox with the given sizes.
@@ -75,13 +85,15 @@ impl SandboxConfiguration {
75
85
output_data_size : usize ,
76
86
stack_size_override : Option < u64 > ,
77
87
heap_size_override : Option < u64 > ,
88
+ interrupt_retry_delay : Duration ,
78
89
#[ cfg( gdb) ] guest_debug_info : Option < DebugInfo > ,
79
90
) -> Self {
80
91
Self {
81
92
input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
82
93
output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
83
94
stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
84
95
heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
96
+ interrupt_retry_delay,
85
97
86
98
#[ cfg( gdb) ]
87
99
guest_debug_info,
@@ -114,6 +126,16 @@ impl SandboxConfiguration {
114
126
self . heap_size_override = heap_size;
115
127
}
116
128
129
+ /// Sets the interrupt retry delay
130
+ pub fn set_interrupt_retry_delay ( & mut self , delay : Duration ) {
131
+ self . interrupt_retry_delay = delay;
132
+ }
133
+
134
+ /// Get the delay between retries for interrupts
135
+ pub fn get_interrupt_retry_delay ( & self ) -> Duration {
136
+ self . interrupt_retry_delay
137
+ }
138
+
117
139
/// Sets the configuration for the guest debug
118
140
#[ cfg( gdb) ]
119
141
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -172,6 +194,7 @@ impl Default for SandboxConfiguration {
172
194
Self :: DEFAULT_OUTPUT_SIZE ,
173
195
None ,
174
196
None ,
197
+ Self :: DEFAULT_INTERRUPT_RETRY_DELAY ,
175
198
#[ cfg( gdb) ]
176
199
None ,
177
200
)
@@ -194,6 +217,7 @@ mod tests {
194
217
OUTPUT_DATA_SIZE_OVERRIDE ,
195
218
Some ( STACK_SIZE_OVERRIDE ) ,
196
219
Some ( HEAP_SIZE_OVERRIDE ) ,
220
+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
197
221
#[ cfg( gdb) ]
198
222
None ,
199
223
) ;
@@ -219,6 +243,7 @@ mod tests {
219
243
SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
220
244
None ,
221
245
None ,
246
+ SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY ,
222
247
#[ cfg( gdb) ]
223
248
None ,
224
249
) ;
0 commit comments