@@ -4,8 +4,9 @@ macro_rules! alloc_tests {
44 use libc:: c_void;
55 use std:: sync:: Arc ;
66 use $TestRegion as TestRegion ;
7- use $crate:: alloc:: Limits ;
7+ use $crate:: alloc:: { host_page_size , Limits , MINSIGSTKSZ } ;
88 use $crate:: context:: { Context , ContextHandle } ;
9+ use $crate:: error:: Error ;
910 use $crate:: instance:: InstanceInternal ;
1011 use $crate:: module:: { GlobalValue , HeapSpec , MockModuleBuilder } ;
1112 use $crate:: region:: Region ;
@@ -713,6 +714,69 @@ macro_rules! alloc_tests {
713714 assert_eq!( region. free_slots( ) , 2 ) ;
714715 assert_eq!( region. used_slots( ) , 0 ) ;
715716 }
717+
718+ #[ test]
719+ fn reject_sigstack_smaller_than_min( ) {
720+ if MINSIGSTKSZ == 0 {
721+ // can't trigger the error on this platform
722+ return ;
723+ }
724+ let limits = Limits {
725+ // keep it page-aligned but make it too small
726+ signal_stack_size: ( MINSIGSTKSZ . checked_sub( 1 ) . unwrap( ) / host_page_size( ) )
727+ * host_page_size( ) ,
728+ ..Limits :: default ( )
729+ } ;
730+ let res = TestRegion :: create( 1 , & limits) ;
731+ match res {
732+ Err ( Error :: InvalidArgument (
733+ "signal stack size must be at least MINSIGSTKSZ (defined in <signal.h>)" ,
734+ ) ) => ( ) ,
735+ Err ( e) => panic!( "unexpected error: {}" , e) ,
736+ Ok ( _) => panic!( "unexpected success" ) ,
737+ }
738+ }
739+
740+ /// This test ensures that a signal stack smaller than 12KiB is rejected when Lucet is
741+ /// compiled in debug mode.
742+ #[ test]
743+ #[ cfg( debug_assertions) ]
744+ fn reject_debug_sigstack_smaller_than_12kib( ) {
745+ if 8192 < MINSIGSTKSZ {
746+ // can't trigger the error on this platform, as the MINSIGSTKSZ check runs first
747+ return ;
748+ }
749+ let limits = Limits {
750+ signal_stack_size: 8192 ,
751+ ..Limits :: default ( )
752+ } ;
753+ let res = TestRegion :: create( 1 , & limits) ;
754+ match res {
755+ Err ( Error :: InvalidArgument (
756+ "signal stack size must be at least 12KiB for debug builds" ,
757+ ) ) => ( ) ,
758+ Err ( e) => panic!( "unexpected error: {}" , e) ,
759+ Ok ( _) => panic!( "unexpected success" ) ,
760+ }
761+ }
762+
763+ #[ test]
764+ fn reject_unaligned_sigstack( ) {
765+ let limits = Limits {
766+ signal_stack_size: std:: cmp:: max( libc:: SIGSTKSZ , 12 * 1024 )
767+ . checked_add( 1 )
768+ . unwrap( ) ,
769+ ..Limits :: default ( )
770+ } ;
771+ let res = TestRegion :: create( 1 , & limits) ;
772+ match res {
773+ Err ( Error :: InvalidArgument (
774+ "signal stack size must be a multiple of host page size" ,
775+ ) ) => ( ) ,
776+ Err ( e) => panic!( "unexpected error: {}" , e) ,
777+ Ok ( _) => panic!( "unexpected success" ) ,
778+ }
779+ }
716780 } ;
717781}
718782
0 commit comments