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.
3
1
/*
4
2
Copyright 2024 The Hyperlight Authors.
5
3
@@ -38,12 +36,6 @@ pub struct SandboxConfiguration {
38
36
/// Guest gdb debug port
39
37
#[ cfg( gdb) ]
40
38
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 ,
47
39
/// The size of the memory buffer that is made available for input to the
48
40
/// Guest Binary
49
41
input_data_size : usize ,
@@ -64,10 +56,6 @@ pub struct SandboxConfiguration {
64
56
/// field should be represented as an `Option`, that type is not
65
57
/// FFI-safe, so it cannot be.
66
58
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 ,
71
59
/// The max_execution_time of a guest execution in milliseconds. If set to 0, the max_execution_time
72
60
/// will be set to the default value of 1000ms if the guest execution does not complete within the time specified
73
61
/// then the execution will be cancelled, the minimum value is 1ms
@@ -107,16 +95,6 @@ impl SandboxConfiguration {
107
95
pub const DEFAULT_OUTPUT_SIZE : usize = 0x4000 ;
108
96
/// The minimum size of output data
109
97
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 ;
120
98
/// The default value for max initialization time (in milliseconds)
121
99
pub const DEFAULT_MAX_INITIALIZATION_TIME : u16 = 2000 ;
122
100
/// The minimum value for max initialization time (in milliseconds)
@@ -139,22 +117,15 @@ impl SandboxConfiguration {
139
117
pub const DEFAULT_GUEST_PANIC_CONTEXT_BUFFER_SIZE : usize = 0x400 ;
140
118
/// The minimum value for guest panic context data
141
119
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 ;
146
120
147
121
#[ allow( clippy:: too_many_arguments) ]
148
122
/// Create a new configuration for a sandbox with the given sizes.
149
123
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
150
124
fn new (
151
125
input_data_size : usize ,
152
126
output_data_size : usize ,
153
- function_definition_size : usize ,
154
- host_exception_size : usize ,
155
127
stack_size_override : Option < u64 > ,
156
128
heap_size_override : Option < u64 > ,
157
- kernel_stack_size : usize ,
158
129
max_execution_time : Option < Duration > ,
159
130
max_initialization_time : Option < Duration > ,
160
131
max_wait_for_cancellation : Option < Duration > ,
@@ -164,14 +135,8 @@ impl SandboxConfiguration {
164
135
Self {
165
136
input_data_size : max ( input_data_size, Self :: MIN_INPUT_SIZE ) ,
166
137
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 ) ,
172
138
stack_size_override : stack_size_override. unwrap_or ( 0 ) ,
173
139
heap_size_override : heap_size_override. unwrap_or ( 0 ) ,
174
- kernel_stack_size : max ( kernel_stack_size, Self :: MIN_KERNEL_STACK_SIZE ) ,
175
140
max_execution_time : {
176
141
match max_execution_time {
177
142
Some ( max_execution_time) => match max_execution_time. as_millis ( ) {
@@ -242,23 +207,6 @@ impl SandboxConfiguration {
242
207
self . output_data_size = max ( output_data_size, Self :: MIN_OUTPUT_SIZE ) ;
243
208
}
244
209
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
-
262
210
/// 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
263
211
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
264
212
pub fn set_stack_size ( & mut self , stack_size : u64 ) {
@@ -271,13 +219,6 @@ impl SandboxConfiguration {
271
219
self . heap_size_override = heap_size;
272
220
}
273
221
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
-
281
222
/// Set the maximum execution time of a guest function execution. If set to 0, the max_execution_time
282
223
/// will be set to the default value of DEFAULT_MAX_EXECUTION_TIME if the guest execution does not complete within the time specified
283
224
/// then the execution will be cancelled, the minimum value is MIN_MAX_EXECUTION_TIME
@@ -350,16 +291,6 @@ impl SandboxConfiguration {
350
291
self . guest_debug_info = Some ( debug_info) ;
351
292
}
352
293
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
-
363
294
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
364
295
pub ( crate ) fn get_input_data_size ( & self ) -> usize {
365
296
self . input_data_size
@@ -413,11 +344,6 @@ impl SandboxConfiguration {
413
344
. unwrap_or_else ( || exe_info. stack_reserve ( ) )
414
345
}
415
346
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
-
421
347
/// If self.heap_size_override is non-zero, return it. Otherwise,
422
348
/// return exe_info.heap_reserve()
423
349
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
@@ -433,11 +359,8 @@ impl Default for SandboxConfiguration {
433
359
Self :: new (
434
360
Self :: DEFAULT_INPUT_SIZE ,
435
361
Self :: DEFAULT_OUTPUT_SIZE ,
436
- Self :: DEFAULT_HOST_FUNCTION_DEFINITION_SIZE ,
437
- Self :: DEFAULT_HOST_EXCEPTION_SIZE ,
438
362
None ,
439
363
None ,
440
- Self :: DEFAULT_KERNEL_STACK_SIZE ,
441
364
None ,
442
365
None ,
443
366
None ,
@@ -461,21 +384,15 @@ mod tests {
461
384
const HEAP_SIZE_OVERRIDE : u64 = 0x50000 ;
462
385
const INPUT_DATA_SIZE_OVERRIDE : usize = 0x4000 ;
463
386
const OUTPUT_DATA_SIZE_OVERRIDE : usize = 0x4001 ;
464
- const HOST_FUNCTION_DEFINITION_SIZE_OVERRIDE : usize = 0x4002 ;
465
- const HOST_EXCEPTION_SIZE_OVERRIDE : usize = 0x4003 ;
466
387
const MAX_EXECUTION_TIME_OVERRIDE : u16 = 1010 ;
467
388
const MAX_WAIT_FOR_CANCELLATION_OVERRIDE : u8 = 200 ;
468
389
const MAX_INITIALIZATION_TIME_OVERRIDE : u16 = 2000 ;
469
390
const GUEST_PANIC_CONTEXT_BUFFER_SIZE_OVERRIDE : usize = 0x4005 ;
470
- const KERNEL_STACK_SIZE_OVERRIDE : usize = 0x4000 ;
471
391
let mut cfg = SandboxConfiguration :: new (
472
392
INPUT_DATA_SIZE_OVERRIDE ,
473
393
OUTPUT_DATA_SIZE_OVERRIDE ,
474
- HOST_FUNCTION_DEFINITION_SIZE_OVERRIDE ,
475
- HOST_EXCEPTION_SIZE_OVERRIDE ,
476
394
Some ( STACK_SIZE_OVERRIDE ) ,
477
395
Some ( HEAP_SIZE_OVERRIDE ) ,
478
- KERNEL_STACK_SIZE_OVERRIDE ,
479
396
Some ( Duration :: from_millis ( MAX_EXECUTION_TIME_OVERRIDE as u64 ) ) ,
480
397
Some ( Duration :: from_millis (
481
398
MAX_INITIALIZATION_TIME_OVERRIDE as u64 ,
@@ -501,14 +418,8 @@ mod tests {
501
418
cfg. heap_size_override = 2048 ;
502
419
assert_eq ! ( 1024 , cfg. stack_size_override) ;
503
420
assert_eq ! ( 2048 , cfg. heap_size_override) ;
504
- assert_eq ! ( 16384 , cfg. kernel_stack_size) ;
505
421
assert_eq ! ( INPUT_DATA_SIZE_OVERRIDE , cfg. input_data_size) ;
506
422
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) ;
512
423
assert_eq ! ( MAX_EXECUTION_TIME_OVERRIDE , cfg. max_execution_time) ;
513
424
assert_eq ! (
514
425
MAX_WAIT_FOR_CANCELLATION_OVERRIDE ,
@@ -529,11 +440,8 @@ mod tests {
529
440
let mut cfg = SandboxConfiguration :: new (
530
441
SandboxConfiguration :: MIN_INPUT_SIZE - 1 ,
531
442
SandboxConfiguration :: MIN_OUTPUT_SIZE - 1 ,
532
- SandboxConfiguration :: MIN_HOST_FUNCTION_DEFINITION_SIZE - 1 ,
533
- SandboxConfiguration :: MIN_HOST_EXCEPTION_SIZE - 1 ,
534
443
None ,
535
444
None ,
536
- SandboxConfiguration :: MIN_KERNEL_STACK_SIZE - 1 ,
537
445
Some ( Duration :: from_millis (
538
446
SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
539
447
) ) ,
@@ -549,18 +457,6 @@ mod tests {
549
457
) ;
550
458
assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
551
459
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
- ) ;
564
460
assert_eq ! ( 0 , cfg. stack_size_override) ;
565
461
assert_eq ! ( 0 , cfg. heap_size_override) ;
566
462
assert_eq ! (
@@ -582,10 +478,6 @@ mod tests {
582
478
583
479
cfg. set_input_data_size ( SandboxConfiguration :: MIN_INPUT_SIZE - 1 ) ;
584
480
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 ) ;
589
481
cfg. set_max_execution_time ( Duration :: from_millis (
590
482
SandboxConfiguration :: MIN_MAX_EXECUTION_TIME as u64 ,
591
483
) ) ;
@@ -601,14 +493,6 @@ mod tests {
601
493
602
494
assert_eq ! ( SandboxConfiguration :: MIN_INPUT_SIZE , cfg. input_data_size) ;
603
495
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
- ) ;
612
496
assert_eq ! (
613
497
SandboxConfiguration :: MIN_MAX_EXECUTION_TIME ,
614
498
cfg. max_execution_time
@@ -631,20 +515,6 @@ mod tests {
631
515
use crate :: sandbox:: config:: DebugInfo ;
632
516
633
517
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
-
648
518
#[ test]
649
519
fn input_data_size( size in SandboxConfiguration :: MIN_INPUT_SIZE ..=SandboxConfiguration :: MIN_INPUT_SIZE * 10 ) {
650
520
let mut cfg = SandboxConfiguration :: default ( ) ;
0 commit comments