@@ -4,9 +4,10 @@ use nix::unistd;
44
55use crate :: discrete_alloc;
66
7- // Note: we do NOT ever want to block the child from accessing this!!
7+ // We do NOT ever want to block the child from accessing this!!
88static SUPERVISOR : std:: sync:: Mutex < Option < Supervisor > > = std:: sync:: Mutex :: new ( None ) ;
99static mut PAGE_ADDR : * mut libc:: c_void = std:: ptr:: null_mut ( ) ;
10+ static mut PAGE_SIZE : usize = 4096 ;
1011static mut CLICK_HERE_4_FREE_STACK : [ u8 ; 1024 ] = [ 0 ; 1024 ] ;
1112
1213#[ cfg( target_pointer_width = "64" ) ]
@@ -67,6 +68,15 @@ impl Supervisor {
6768 drop ( sv) ;
6869
6970 if is_none {
71+ #[ allow( clippy:: cast_possible_truncation) ]
72+ #[ allow( clippy:: cast_sign_loss) ]
73+ unsafe {
74+ let ret = libc:: sysconf ( libc:: _SC_PAGESIZE) ;
75+ if ret > 0 {
76+ PAGE_SIZE = ret as _ ;
77+ }
78+ }
79+
7080 let ( t_message, r_message) = ipc:: channel ( ) . unwrap ( ) ;
7181 let ( t_event, r_event) = ipc:: channel ( ) . unwrap ( ) ;
7282 unsafe {
@@ -407,7 +417,7 @@ fn handle_segfault(
407417) {
408418 let siginfo = ptrace:: getsiginfo ( pid) . unwrap ( ) ;
409419 let addr = unsafe { siginfo. si_addr ( ) . addr ( ) } ;
410- let page_addr = addr - addr % 4096 ;
420+ let page_addr = addr - addr % unsafe { PAGE_SIZE } ;
411421
412422 if ch_pages. contains ( & page_addr) {
413423 // Overall structure:
@@ -578,14 +588,14 @@ fn intercept_retptr(
578588// manually, so we *must not ever* unwind from it
579589pub unsafe extern "C" fn mempr_off ( ) {
580590 unsafe {
581- let _ = libc:: mprotect ( PAGE_ADDR , 4096 , libc:: PROT_READ | libc:: PROT_WRITE ) ;
591+ let _ = libc:: mprotect ( PAGE_ADDR , PAGE_SIZE , libc:: PROT_READ | libc:: PROT_WRITE ) ;
582592 }
583593 let _ = signal:: raise ( signal:: SIGSTOP ) ;
584594}
585595
586596pub unsafe extern "C" fn mempr_on ( ) {
587597 unsafe {
588- let _ = libc:: mprotect ( PAGE_ADDR , 4096 , libc:: PROT_NONE ) ;
598+ let _ = libc:: mprotect ( PAGE_ADDR , PAGE_SIZE , libc:: PROT_NONE ) ;
589599 }
590600 let _ = signal:: raise ( signal:: SIGSTOP ) ;
591601}
0 commit comments