Set pointer mask

This commit is contained in:
Yota Toyama
2023-09-28 16:33:49 +10:00
parent 0bd260a7c0
commit 10ffdd9351
2 changed files with 8 additions and 14 deletions

View File

@@ -24,7 +24,7 @@ fn main() {
let dst = autotools::Config::new(LIB_GC_DIR) let dst = autotools::Config::new(LIB_GC_DIR)
.cflag(format!( .cflag(format!(
// spell-checker: disable-next-line // spell-checker: disable-next-line
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC", "-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC -DPOINTER_MASK=0xffffffffffffffff",
dst.join("include").display() dst.join("include").display()
)) ))
.build(); .build();

View File

@@ -1,7 +1,7 @@
use bdwgc_alloc::Allocator; use bdwgc_alloc::Allocator;
use std::alloc::{alloc, Layout}; use std::alloc::{alloc, Layout};
const BITS: usize = (1 << 8 - 1) << 48; const BITS: usize = usize::MAX << 48 | 0x7;
#[global_allocator] #[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator; static GLOBAL_ALLOCATOR: Allocator = Allocator;
@@ -9,22 +9,16 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() { fn main() {
unsafe { Allocator::initialize() } unsafe { Allocator::initialize() }
let x = allocate();
unsafe { *x = 42 };
let x = x as usize | BITS;
let mut xs = vec![];
loop { loop {
assert_eq!(x & BITS, BITS); let x = allocate();
assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42); unsafe { *x = 42 };
let x = x as usize | BITS;
let ptr = allocate(); assert_eq!(x & BITS, BITS);
unsafe { *ptr = 0 };
xs.push(ptr);
Allocator::force_collect(); Allocator::force_collect();
assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42);
} }
} }