From 10ffdd9351e4d52bb0dd4c5b1eac8e1e83b24292 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Thu, 28 Sep 2023 16:33:49 +1000 Subject: [PATCH] Set pointer mask --- build.rs | 2 +- examples/tagged_pointer/src/main.rs | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/build.rs b/build.rs index ccc8471..f5e2676 100644 --- a/build.rs +++ b/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(); diff --git a/examples/tagged_pointer/src/main.rs b/examples/tagged_pointer/src/main.rs index 64a421d..4d13e96 100644 --- a/examples/tagged_pointer/src/main.rs +++ b/examples/tagged_pointer/src/main.rs @@ -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); } }