@@ -17,6 +17,7 @@ limitations under the License.
1717use  std:: cmp:: max; 
1818use  std:: time:: Duration ; 
1919
20+ use  libc:: c_int; 
2021use  tracing:: { instrument,  Span } ; 
2122
2223use  crate :: mem:: exe:: ExeInfo ; 
@@ -63,6 +64,14 @@ pub struct SandboxConfiguration {
6364     /// signal can be delivered to the thread, but the thread may not yet 
6465     /// have entered kernel space. 
6566     interrupt_retry_delay :  Duration , 
67+     /// Offset from `SIGRTMIN` used to determine the signal number for interrupting 
68+      /// the VCPU thread. The actual signal sent is `SIGRTMIN + interrupt_vcpu_sigrtmin_offset`. 
69+      /// 
70+      /// This signal must fall within the valid real-time signal range supported by the host. 
71+      /// 
72+      /// Note: Since real-time signals can vary across platforms, ensure that the offset 
73+      /// results in a signal number that is not already in use by other components of the system. 
74+      interrupt_vcpu_sigrtmin_offset :  u8 , 
6675} 
6776
6877impl  SandboxConfiguration  { 
@@ -76,6 +85,8 @@ impl SandboxConfiguration {
7685     pub  const  MIN_OUTPUT_SIZE :  usize  = 0x2000 ; 
7786    /// The default interrupt retry delay 
7887     pub  const  DEFAULT_INTERRUPT_RETRY_DELAY :  Duration  = Duration :: from_micros ( 500 ) ; 
88+     /// The default signal offset from `SIGRTMIN` used to determine the signal number for interrupting 
89+      pub  const  INTERRUPT_VCPU_SIGRTMIN_OFFSET :  u8  = 0 ; 
7990
8091    #[ allow( clippy:: too_many_arguments) ]  
8192    /// Create a new configuration for a sandbox with the given sizes. 
@@ -86,6 +97,7 @@ impl SandboxConfiguration {
8697        stack_size_override :  Option < u64 > , 
8798        heap_size_override :  Option < u64 > , 
8899        interrupt_retry_delay :  Duration , 
100+         interrupt_vcpu_sigrtmin_offset :  u8 , 
89101        #[ cfg( gdb) ]   guest_debug_info :  Option < DebugInfo > , 
90102    )  -> Self  { 
91103        Self  { 
@@ -94,7 +106,7 @@ impl SandboxConfiguration {
94106            stack_size_override :  stack_size_override. unwrap_or ( 0 ) , 
95107            heap_size_override :  heap_size_override. unwrap_or ( 0 ) , 
96108            interrupt_retry_delay, 
97- 
109+             interrupt_vcpu_sigrtmin_offset , 
98110            #[ cfg( gdb) ]  
99111            guest_debug_info, 
100112        } 
@@ -136,6 +148,29 @@ impl SandboxConfiguration {
136148        self . interrupt_retry_delay 
137149    } 
138150
151+     /// Get the signal offset from `SIGRTMIN` used to determine the signal number for interrupting the VCPU thread 
152+      pub  fn  get_interrupt_vcpu_sigrtmin_offset ( & self )  -> u8  { 
153+         self . interrupt_vcpu_sigrtmin_offset 
154+     } 
155+ 
156+     /// Sets the offset from `SIGRTMIN` to determine the real-time signal used for 
157+      /// interrupting the VCPU thread. 
158+      /// 
159+      /// The final signal number is computed as `SIGRTMIN + offset`, and it must fall within 
160+      /// the valid range of real-time signals supported by the host system. 
161+      /// 
162+      /// Returns Ok(()) if the offset is valid, or an error if it exceeds the maximum real-time signal number. 
163+      pub  fn  set_interrupt_vcpu_sigrtmin_offset ( & mut  self ,  offset :  u8 )  -> crate :: Result < ( ) >  { 
164+         if  libc:: SIGRTMIN ( )  + offset as  c_int  > libc:: SIGRTMAX ( )  { 
165+             return  Err ( crate :: new_error!( 
166+                 "Invalid SIGRTMIN offset: {}. It exceeds the maximum real-time signal number." , 
167+                 offset
168+             ) ) ; 
169+         } 
170+         self . interrupt_vcpu_sigrtmin_offset  = offset; 
171+         Ok ( ( ) ) 
172+     } 
173+ 
139174    /// Sets the configuration for the guest debug 
140175     #[ cfg( gdb) ]  
141176    #[ instrument( skip_all,  parent = Span :: current( ) ,  level= "Trace" ) ]  
@@ -195,6 +230,7 @@ impl Default for SandboxConfiguration {
195230            None , 
196231            None , 
197232            Self :: DEFAULT_INTERRUPT_RETRY_DELAY , 
233+             Self :: INTERRUPT_VCPU_SIGRTMIN_OFFSET , 
198234            #[ cfg( gdb) ]  
199235            None , 
200236        ) 
@@ -218,6 +254,7 @@ mod tests {
218254            Some ( STACK_SIZE_OVERRIDE ) , 
219255            Some ( HEAP_SIZE_OVERRIDE ) , 
220256            SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY , 
257+             SandboxConfiguration :: INTERRUPT_VCPU_SIGRTMIN_OFFSET , 
221258            #[ cfg( gdb) ]  
222259            None , 
223260        ) ; 
@@ -244,6 +281,7 @@ mod tests {
244281            None , 
245282            None , 
246283            SandboxConfiguration :: DEFAULT_INTERRUPT_RETRY_DELAY , 
284+             SandboxConfiguration :: INTERRUPT_VCPU_SIGRTMIN_OFFSET , 
247285            #[ cfg( gdb) ]  
248286            None , 
249287        ) ; 
0 commit comments