@@ -25,6 +25,9 @@ use crate::mem::exe::ExeInfo;
25
25
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
26
26
#[ repr( C ) ]
27
27
pub struct SandboxConfiguration {
28
+ #[ cfg( gdb) ]
29
+ /// Guest gdb debug port
30
+ guest_debug_port : Option < u16 > ,
28
31
/// The maximum size of the guest error buffer.
29
32
guest_error_buffer_size : usize ,
30
33
/// The size of the memory buffer that is made available for Guest Function
@@ -136,6 +139,9 @@ impl SandboxConfiguration {
136
139
pub const MIN_KERNEL_STACK_SIZE : usize = 0x1000 ;
137
140
/// The default value for kernel stack size
138
141
pub const DEFAULT_KERNEL_STACK_SIZE : usize = Self :: MIN_KERNEL_STACK_SIZE ;
142
+ #[ cfg( gdb) ]
143
+ /// The minimum value for debug port
144
+ pub const MIN_GUEST_DEBUG_PORT : u16 = 9000 ;
139
145
140
146
#[ allow( clippy:: too_many_arguments) ]
141
147
/// Create a new configuration for a sandbox with the given sizes.
@@ -153,6 +159,7 @@ impl SandboxConfiguration {
153
159
max_initialization_time : Option < Duration > ,
154
160
max_wait_for_cancellation : Option < Duration > ,
155
161
guest_panic_context_buffer_size : usize ,
162
+ #[ cfg( gdb) ] guest_debug_port : Option < u16 > ,
156
163
) -> Self {
157
164
Self {
158
165
input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
@@ -220,6 +227,8 @@ impl SandboxConfiguration {
220
227
guest_panic_context_buffer_size,
221
228
Self :: MIN_GUEST_PANIC_CONTEXT_BUFFER_SIZE ,
222
229
) ,
230
+ #[ cfg( gdb) ]
231
+ guest_debug_port,
223
232
}
224
233
}
225
234
@@ -346,6 +355,13 @@ impl SandboxConfiguration {
346
355
) ;
347
356
}
348
357
358
+ #[ cfg( gdb) ]
359
+ #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
360
+ /// Sets the configuration for the guest debug
361
+ pub fn set_guest_debug_port ( & mut self , port : u16 ) {
362
+ self . guest_debug_port = Some ( max ( port, Self :: MIN_GUEST_DEBUG_PORT ) ) ;
363
+ }
364
+
349
365
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
350
366
pub ( crate ) fn get_guest_error_buffer_size ( & self ) -> usize {
351
367
self . guest_error_buffer_size
@@ -390,6 +406,12 @@ impl SandboxConfiguration {
390
406
self . max_initialization_time
391
407
}
392
408
409
+ #[ cfg( gdb) ]
410
+ #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
411
+ pub ( crate ) fn get_guest_debug_port ( & self ) -> Option < u16 > {
412
+ self . guest_debug_port
413
+ }
414
+
393
415
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
394
416
fn stack_size_override_opt ( & self ) -> Option < u64 > {
395
417
( self . stack_size_override > 0 ) . then_some ( self . stack_size_override )
@@ -438,6 +460,8 @@ impl Default for SandboxConfiguration {
438
460
None ,
439
461
None ,
440
462
Self :: DEFAULT_GUEST_PANIC_CONTEXT_BUFFER_SIZE ,
463
+ #[ cfg( gdb) ]
464
+ None ,
441
465
)
442
466
}
443
467
}
@@ -480,6 +504,8 @@ mod tests {
480
504
MAX_WAIT_FOR_CANCELLATION_OVERRIDE as u64 ,
481
505
) ) ,
482
506
GUEST_PANIC_CONTEXT_BUFFER_SIZE_OVERRIDE ,
507
+ #[ cfg( gdb) ]
508
+ None ,
483
509
) ;
484
510
let exe_infos = vec ! [
485
511
simple_guest_exe_info( ) . unwrap( ) ,
@@ -543,6 +569,8 @@ mod tests {
543
569
SandboxConfiguration :: MIN_MAX_WAIT_FOR_CANCELLATION as u64 - 1 ,
544
570
) ) ,
545
571
SandboxConfiguration :: MIN_GUEST_PANIC_CONTEXT_BUFFER_SIZE - 1 ,
572
+ #[ cfg( gdb) ]
573
+ None ,
546
574
) ;
547
575
assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
548
576
assert_eq ! ( SandboxConfiguration :: MIN_OUTPUT_SIZE , cfg. output_data_size) ;
@@ -711,6 +739,14 @@ mod tests {
711
739
cfg. set_heap_size( size) ;
712
740
prop_assert_eq!( size, cfg. heap_size_override) ;
713
741
}
742
+
743
+ #[ test]
744
+ #[ cfg( gdb) ]
745
+ fn guest_debug_port( port in 9000 ..=u16 :: MAX ) {
746
+ let mut cfg = SandboxConfiguration :: default ( ) ;
747
+ cfg. set_guest_debug_port( port) ;
748
+ prop_assert_eq!( port, * cfg. get_guest_debug_port( ) . as_ref( ) . unwrap( ) ) ;
749
+ }
714
750
}
715
751
}
716
752
}
0 commit comments