@@ -22,7 +22,7 @@ use hyperlight_host::mem::memory_region::MemoryRegionFlags;
22
22
use hyperlight_host:: sandbox:: SandboxConfiguration ;
23
23
use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
24
24
use hyperlight_host:: sandbox_state:: transition:: Noop ;
25
- use hyperlight_host:: { GuestBinary , HyperlightError , UninitializedSandbox } ;
25
+ use hyperlight_host:: { GuestBinary , HyperlightError , MultiUseSandbox , UninitializedSandbox } ;
26
26
use hyperlight_testing:: { c_simple_guest_as_string, simple_guest_as_string} ;
27
27
28
28
pub mod common; // pub to disable dead_code warning
@@ -266,76 +266,30 @@ fn guest_malloc_abort() {
266
266
) ) ;
267
267
}
268
268
269
- // checks that alloca works
269
+ // Tests libc alloca
270
270
#[ test]
271
- fn dynamic_stack_allocate ( ) {
272
- let mut sbox = new_uninit ( ) . unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ;
273
-
274
- let bytes = 10_000 ; // some low number that can be allocated on stack
275
-
276
- sbox. call_guest_function_by_name (
277
- "StackAllocate" ,
278
- ReturnType :: Int ,
279
- Some ( vec ! [ ParameterValue :: Int ( bytes) ] ) ,
280
- )
281
- . unwrap ( ) ;
282
- }
283
-
284
- // checks alloca fails with stackoverflow for large allocations
285
- #[ test]
286
- fn dynamic_stack_allocate_overflow ( ) {
287
- let mut sbox1 = new_uninit ( ) . unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ;
288
-
289
- // zero is handled as special case in guest,
290
- // will turn DEFAULT_GUEST_STACK_SIZE + 1
291
- let bytes = 0 ;
292
-
293
- let res = sbox1
294
- . call_guest_function_by_name (
295
- "StackAllocate" ,
296
- ReturnType :: Int ,
297
- Some ( vec ! [ ParameterValue :: Int ( bytes) ] ) ,
298
- )
299
- . unwrap_err ( ) ;
300
- println ! ( "{:?}" , res) ;
301
- assert ! ( matches!( res, HyperlightError :: StackOverflow ( ) ) ) ;
302
- }
303
-
304
- // checks alloca fails with overflow when stack pointer overflows
305
- #[ test]
306
- fn dynamic_stack_allocate_pointer_overflow ( ) {
307
- let mut sbox1 = new_uninit_rust ( ) . unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ;
308
- let bytes = 10 * 1024 * 1024 ; // 10Mb
271
+ fn dynamic_stack_allocate_c_guest ( ) {
272
+ let path = c_simple_guest_as_string ( ) . unwrap ( ) ;
273
+ let guest_path = GuestBinary :: FilePath ( path) ;
274
+ let uninit = UninitializedSandbox :: new ( guest_path, None , None , None ) ;
275
+ let mut sbox1: MultiUseSandbox = uninit. unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ;
309
276
310
- let res = sbox1
277
+ let res2 = sbox1
311
278
. call_guest_function_by_name (
312
279
"StackAllocate" ,
313
280
ReturnType :: Int ,
314
- Some ( vec ! [ ParameterValue :: Int ( bytes ) ] ) ,
281
+ Some ( vec ! [ ParameterValue :: Int ( 100 ) ] ) ,
315
282
)
316
- . unwrap_err ( ) ;
317
- println ! ( "{:?}" , res) ;
318
- assert ! ( matches!( res, HyperlightError :: StackOverflow ( ) ) ) ;
319
- }
320
-
321
- // checks alloca fails with stackoverflow for huge allocations with c guest lib
322
- #[ test]
323
- fn dynamic_stack_allocate_overflow_c_guest ( ) {
324
- let path = c_simple_guest_as_string ( ) . unwrap ( ) ;
325
- let guest_path = GuestBinary :: FilePath ( path) ;
326
- let uninit = UninitializedSandbox :: new ( guest_path, None , None , None ) ;
327
- let mut sbox1 = uninit. unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ;
328
-
329
- let bytes = 0 ; // zero is handled as special case in guest, will turn into large number
283
+ . unwrap ( ) ;
284
+ assert ! ( matches!( res2, ReturnValue :: Int ( n) if n == 100 ) ) ;
330
285
331
286
let res = sbox1
332
287
. call_guest_function_by_name (
333
288
"StackAllocate" ,
334
289
ReturnType :: Int ,
335
- Some ( vec ! [ ParameterValue :: Int ( bytes ) ] ) ,
290
+ Some ( vec ! [ ParameterValue :: Int ( 128 * 1024 * 1024 ) ] ) ,
336
291
)
337
292
. unwrap_err ( ) ;
338
- println ! ( "{:?}" , res) ;
339
293
assert ! ( matches!( res, HyperlightError :: StackOverflow ( ) ) ) ;
340
294
}
341
295
0 commit comments