mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-30 02:18:57 -06:00
Set pointer mask
This commit is contained in:
2
build.rs
2
build.rs
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user