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)
|
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();
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user