@@ -4,9 +4,10 @@ use nix::unistd;
4
4
5
5
use crate :: discrete_alloc;
6
6
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!!
8
8
static SUPERVISOR : std:: sync:: Mutex < Option < Supervisor > > = std:: sync:: Mutex :: new ( None ) ;
9
9
static mut PAGE_ADDR : * mut libc:: c_void = std:: ptr:: null_mut ( ) ;
10
+ static mut PAGE_SIZE : usize = 4096 ;
10
11
static mut CLICK_HERE_4_FREE_STACK : [ u8 ; 1024 ] = [ 0 ; 1024 ] ;
11
12
12
13
#[ cfg( target_pointer_width = "64" ) ]
@@ -67,6 +68,15 @@ impl Supervisor {
67
68
drop ( sv) ;
68
69
69
70
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
+
70
80
let ( t_message, r_message) = ipc:: channel ( ) . unwrap ( ) ;
71
81
let ( t_event, r_event) = ipc:: channel ( ) . unwrap ( ) ;
72
82
unsafe {
@@ -407,7 +417,7 @@ fn handle_segfault(
407
417
) {
408
418
let siginfo = ptrace:: getsiginfo ( pid) . unwrap ( ) ;
409
419
let addr = unsafe { siginfo. si_addr ( ) . addr ( ) } ;
410
- let page_addr = addr - addr % 4096 ;
420
+ let page_addr = addr - addr % unsafe { PAGE_SIZE } ;
411
421
412
422
if ch_pages. contains ( & page_addr) {
413
423
// Overall structure:
@@ -578,14 +588,14 @@ fn intercept_retptr(
578
588
// manually, so we *must not ever* unwind from it
579
589
pub unsafe extern "C" fn mempr_off ( ) {
580
590
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 ) ;
582
592
}
583
593
let _ = signal:: raise ( signal:: SIGSTOP ) ;
584
594
}
585
595
586
596
pub unsafe extern "C" fn mempr_on ( ) {
587
597
unsafe {
588
- let _ = libc:: mprotect ( PAGE_ADDR , 4096 , libc:: PROT_NONE ) ;
598
+ let _ = libc:: mprotect ( PAGE_ADDR , PAGE_SIZE , libc:: PROT_NONE ) ;
589
599
}
590
600
let _ = signal:: raise ( signal:: SIGSTOP ) ;
591
601
}
0 commit comments