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)
.cflag(format!(
// 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()
))
.build();

View File

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