1- // TODO(danbugs:297): forgot to remove stuff related to host exceptions and
2- // host function definitions in my previous PR. Will remove them in the next commit.
31/*
42Copyright 2024 The Hyperlight Authors.
53
@@ -38,12 +36,6 @@ pub struct SandboxConfiguration {
3836 /// Guest gdb debug port
3937 #[ cfg( gdb) ]
4038 guest_debug_info : Option < DebugInfo > ,
41- /// The size of the memory buffer that is made available for Guest Function
42- /// Definitions
43- host_function_definition_size : usize ,
44- /// The size of the memory buffer that is made available for serialising
45- /// Host Exceptions
46- host_exception_size : usize ,
4739 /// The size of the memory buffer that is made available for input to the
4840 /// Guest Binary
4941 input_data_size : usize ,
@@ -64,10 +56,6 @@ pub struct SandboxConfiguration {
6456 /// field should be represented as an `Option`, that type is not
6557 /// FFI-safe, so it cannot be.
6658 heap_size_override : u64 ,
67- /// The kernel_stack_size to use in the guest sandbox. If set to 0, the default kernel stack size will be used.
68- /// The value will be increased to a multiple page size when memory is allocated if necessary.
69- ///
70- kernel_stack_size : usize ,
7159 /// The max_execution_time of a guest execution in milliseconds. If set to 0, the max_execution_time
7260 /// will be set to the default value of 1000ms if the guest execution does not complete within the time specified
7361 /// then the execution will be cancelled, the minimum value is 1ms
@@ -107,16 +95,6 @@ impl SandboxConfiguration {
10795 pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
10896 /// The minimum size of output data
10997 pub const MIN_OUTPUT_SIZE : usize = 0x2000 ;
110- /// The default size of host function definitions
111- /// Host function definitions has its own page in memory, in order to be READ-ONLY
112- /// from a guest's perspective.
113- pub const DEFAULT_HOST_FUNCTION_DEFINITION_SIZE : usize = 0x1000 ;
114- /// The minimum size of host function definitions
115- pub const MIN_HOST_FUNCTION_DEFINITION_SIZE : usize = 0x1000 ;
116- /// The default size for host exceptions
117- pub const DEFAULT_HOST_EXCEPTION_SIZE : usize = 0x4000 ;
118- /// The minimum size for host exceptions
119- pub const MIN_HOST_EXCEPTION_SIZE : usize = 0x4000 ;
12098 /// The default value for max initialization time (in milliseconds)
12199 pub const DEFAULT_MAX_INITIALIZATION_TIME : u16 = 2000 ;
122100 /// The minimum value for max initialization time (in milliseconds)
@@ -139,22 +117,15 @@ impl SandboxConfiguration {
139117 pub const DEFAULT_GUEST_PANIC_CONTEXT_BUFFER_SIZE : usize = 0x400 ;
140118 /// The minimum value for guest panic context data
141119 pub const MIN_GUEST_PANIC_CONTEXT_BUFFER_SIZE : usize = 0x400 ;
142- /// The minimum value for kernel stack size
143- pub const MIN_KERNEL_STACK_SIZE : usize = 0x1000 ;
144- /// The default value for kernel stack size
145- pub const DEFAULT_KERNEL_STACK_SIZE : usize = Self :: MIN_KERNEL_STACK_SIZE ;
146120
147121 #[ allow( clippy:: too_many_arguments) ]
148122 /// Create a new configuration for a sandbox with the given sizes.
149123 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
150124 fn new (
151125 input_data_size : usize ,
152126 output_data_size : usize ,
153- function_definition_size : usize ,
154- host_exception_size : usize ,
155127 stack_size_override : Option < u64 > ,
156128 heap_size_override : Option < u64 > ,
157- kernel_stack_size : usize ,
158129 max_execution_time : Option < Duration > ,
159130 max_initialization_time : Option < Duration > ,
160131 max_wait_for_cancellation : Option < Duration > ,
@@ -164,14 +135,8 @@ impl SandboxConfiguration {
164135 Self {
165136 input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
166137 output_data_size : max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ,
167- host_function_definition_size : max (
168- function_definition_size,
169- Self :: MIN_HOST_FUNCTION_DEFINITION_SIZE ,
170- ) ,
171- host_exception_size : max ( host_exception_size, Self :: MIN_HOST_EXCEPTION_SIZE ) ,
172138 stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
173139 heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
174- kernel_stack_size : max ( kernel_stack_size, Self :: MIN_KERNEL_STACK_SIZE ) ,
175140 max_execution_time : {
176141 match max_execution_time {
177142 Some ( max_execution_time) => match max_execution_time. as_millis ( ) {
@@ -242,23 +207,6 @@ impl SandboxConfiguration {
242207 self . output_data_size = max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ;
243208 }
244209
245- /// Set the size of the memory buffer that is made available for serialising host function definitions
246- /// the minimum value is MIN_HOST_FUNCTION_DEFINITION_SIZE
247- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
248- pub fn set_host_function_definition_size ( & mut self , host_function_definition_size : usize ) {
249- self . host_function_definition_size = max (
250- host_function_definition_size,
251- Self :: MIN_HOST_FUNCTION_DEFINITION_SIZE ,
252- ) ;
253- }
254-
255- /// Set the size of the memory buffer that is made available for serialising host exceptions
256- /// the minimum value is MIN_HOST_EXCEPTION_SIZE
257- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
258- pub fn set_host_exception_size ( & mut self , host_exception_size : usize ) {
259- self . host_exception_size = max ( host_exception_size, Self :: MIN_HOST_EXCEPTION_SIZE ) ;
260- }
261-
262210 /// Set the stack size to use in the guest sandbox. If set to 0, the stack size will be determined from the PE file header
263211 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
264212 pub fn set_stack_size ( & mut self , stack_size : u64 ) {
@@ -271,13 +219,6 @@ impl SandboxConfiguration {
271219 self . heap_size_override = heap_size;
272220 }
273221
274- /// Set the kernel stack size to use in the guest sandbox. If less than the minimum value of MIN_KERNEL_STACK_SIZE, the minimum value will be used.
275- /// If its not a multiple of the page size, it will be increased to the a multiple of the page size when memory is allocated.
276- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
277- pub fn set_kernel_stack_size ( & mut self , kernel_stack_size : usize ) {
278- self . kernel_stack_size = max ( kernel_stack_size, Self :: MIN_KERNEL_STACK_SIZE ) ;
279- }
280-
281222 /// Set the maximum execution time of a guest function execution. If set to 0, the max_execution_time
282223 /// will be set to the default value of DEFAULT_MAX_EXECUTION_TIME if the guest execution does not complete within the time specified
283224 /// then the execution will be cancelled, the minimum value is MIN_MAX_EXECUTION_TIME
@@ -350,16 +291,6 @@ impl SandboxConfiguration {
350291 self . guest_debug_info = Some ( debug_info) ;
351292 }
352293
353- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
354- pub ( crate ) fn get_host_function_definition_size ( & self ) -> usize {
355- self . host_function_definition_size
356- }
357-
358- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
359- pub ( crate ) fn get_host_exception_size ( & self ) -> usize {
360- self . host_exception_size
361- }
362-
363294 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
364295 pub ( crate ) fn get_input_data_size ( & self ) -> usize {
365296 self . input_data_size
@@ -413,11 +344,6 @@ impl SandboxConfiguration {
413344 . unwrap_or_else ( || exe_info. stack_reserve ( ) )
414345 }
415346
416- #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
417- pub ( crate ) fn get_kernel_stack_size ( & self ) -> usize {
418- self . kernel_stack_size
419- }
420-
421347 /// If self.heap_size_override is non-zero, return it. Otherwise,
422348 /// return exe_info.heap_reserve()
423349 #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -433,11 +359,8 @@ impl Default for SandboxConfiguration {
433359 Self :: new (
434360 Self :: DEFAULT_INPUT_SIZE ,
435361 Self :: DEFAULT_OUTPUT_SIZE ,
436- Self :: DEFAULT_HOST_FUNCTION_DEFINITION_SIZE ,
437- Self :: DEFAULT_HOST_EXCEPTION_SIZE ,
438362 None ,
439363 None ,
440- Self :: DEFAULT_KERNEL_STACK_SIZE ,
441364 None ,
442365 None ,
443366 None ,
@@ -461,21 +384,15 @@ mod tests {
461384 const HEAP_SIZE_OVERRIDE : u64 = 0x50000 ;
462385 const INPUT_DATA_SIZE_OVERRIDE : usize = 0x4000 ;
463386 const OUTPUT_DATA_SIZE_OVERRIDE : usize = 0x4001 ;
464- const HOST_FUNCTION_DEFINITION_SIZE_OVERRIDE : usize = 0x4002 ;
465- const HOST_EXCEPTION_SIZE_OVERRIDE : usize = 0x4003 ;
466387 const MAX_EXECUTION_TIME_OVERRIDE : u16 = 1010 ;
467388 const MAX_WAIT_FOR_CANCELLATION_OVERRIDE : u8 = 200 ;
468389 const MAX_INITIALIZATION_TIME_OVERRIDE : u16 = 2000 ;
469390 const GUEST_PANIC_CONTEXT_BUFFER_SIZE_OVERRIDE : usize = 0x4005 ;
470- const KERNEL_STACK_SIZE_OVERRIDE : usize = 0x4000 ;
471391 let mut cfg = SandboxConfiguration :: new (
472392 INPUT_DATA_SIZE_OVERRIDE ,
473393 OUTPUT_DATA_SIZE_OVERRIDE ,
474- HOST_FUNCTION_DEFINITION_SIZE_OVERRIDE ,
475- HOST_EXCEPTION_SIZE_OVERRIDE ,
476394 Some ( STACK_SIZE_OVERRIDE ) ,
477395 Some ( HEAP_SIZE_OVERRIDE ) ,
478- KERNEL_STACK_SIZE_OVERRIDE ,
479396 Some ( Duration :: from_millis ( MAX_EXECUTION_TIME_OVERRIDE as u64 ) ) ,
480397 Some ( Duration :: from_millis (
481398 MAX_INITIALIZATION_TIME_OVERRIDE as u64 ,
@@ -501,14 +418,8 @@ mod tests {
501418 cfg. heap_size_override = 2048 ;
502419 assert_eq ! ( 1024 , cfg. stack_size_override) ;
503420 assert_eq ! ( 2048 , cfg. heap_size_override) ;
504- assert_eq ! ( 16384 , cfg. kernel_stack_size) ;
505421 assert_eq ! ( INPUT_DATA_SIZE_OVERRIDE , cfg. input_data_size) ;
506422 assert_eq ! ( OUTPUT_DATA_SIZE_OVERRIDE , cfg. output_data_size) ;
507- assert_eq ! (
508- HOST_FUNCTION_DEFINITION_SIZE_OVERRIDE ,
509- cfg. host_function_definition_size
510- ) ;
511- assert_eq ! ( HOST_EXCEPTION_SIZE_OVERRIDE , cfg. host_exception_size) ;
512423 assert_eq ! ( MAX_EXECUTION_TIME_OVERRIDE , cfg. max_execution_time) ;
513424 assert_eq ! (
514425 MAX_WAIT_FOR_CANCELLATION_OVERRIDE ,
@@ -529,11 +440,8 @@ mod tests {
529440 let mut cfg = SandboxConfiguration :: new (
530441 SandboxConfiguration :: MIN_INPUT_SIZE - 1 ,
531442 SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
532- SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE - 1 ,
533- SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE - 1 ,
534443 None ,
535444 None ,
536- SandboxConfiguration :: MIN_KERNEL_STACK_SIZE - 1 ,
537445 Some ( Duration :: from_millis (
538446 SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
539447 ) ) ,
@@ -549,18 +457,6 @@ mod tests {
549457 ) ;
550458 assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
551459 assert_eq ! ( SandboxConfiguration :: MIN_OUTPUT_SIZE , cfg. output_data_size) ;
552- assert_eq ! (
553- SandboxConfiguration :: MIN_KERNEL_STACK_SIZE ,
554- cfg. kernel_stack_size
555- ) ;
556- assert_eq ! (
557- SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE ,
558- cfg. host_function_definition_size
559- ) ;
560- assert_eq ! (
561- SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE ,
562- cfg. host_exception_size
563- ) ;
564460 assert_eq ! ( 0 , cfg. stack_size_override) ;
565461 assert_eq ! ( 0 , cfg. heap_size_override) ;
566462 assert_eq ! (
@@ -582,10 +478,6 @@ mod tests {
582478
583479 cfg. set_input_data_size ( SandboxConfiguration :: MIN_INPUT_SIZE - 1 ) ;
584480 cfg. set_output_data_size ( SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ) ;
585- cfg. set_host_function_definition_size (
586- SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE - 1 ,
587- ) ;
588- cfg. set_host_exception_size ( SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE - 1 ) ;
589481 cfg. set_max_execution_time ( Duration :: from_millis (
590482 SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
591483 ) ) ;
@@ -601,14 +493,6 @@ mod tests {
601493
602494 assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
603495 assert_eq ! ( SandboxConfiguration :: MIN_OUTPUT_SIZE , cfg. output_data_size) ;
604- assert_eq ! (
605- SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE ,
606- cfg. host_function_definition_size
607- ) ;
608- assert_eq ! (
609- SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE ,
610- cfg. host_exception_size
611- ) ;
612496 assert_eq ! (
613497 SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ,
614498 cfg. max_execution_time
@@ -631,20 +515,6 @@ mod tests {
631515 use crate :: sandbox:: config:: DebugInfo ;
632516
633517 proptest ! {
634- #[ test]
635- fn host_function_definition_size( size in SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE ..=SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE * 10 ) {
636- let mut cfg = SandboxConfiguration :: default ( ) ;
637- cfg. set_host_function_definition_size( size) ;
638- prop_assert_eq!( size, cfg. get_host_function_definition_size( ) ) ;
639- }
640-
641- #[ test]
642- fn host_exception_size( size in SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE ..=SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE * 10 ) {
643- let mut cfg = SandboxConfiguration :: default ( ) ;
644- cfg. set_host_exception_size( size) ;
645- prop_assert_eq!( size, cfg. get_host_exception_size( ) ) ;
646- }
647-
648518 #[ test]
649519 fn input_data_size( size in SandboxConfiguration :: MIN_INPUT_SIZE ..=SandboxConfiguration :: MIN_INPUT_SIZE * 10 ) {
650520 let mut cfg = SandboxConfiguration :: default ( ) ;
0 commit comments