This commit is contained in:
Yota Toyama
2023-09-28 16:19:16 +10:00
parent 039a10213d
commit 6cb47fddd0
2 changed files with 16 additions and 25 deletions

View File

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

View File

@@ -1,10 +1,7 @@
use bdwgc_alloc::Allocator; use bdwgc_alloc::Allocator;
use std::{ use std::alloc::{alloc, Layout};
alloc::{alloc, Layout},
thread::spawn,
};
const BITS: usize = 7 << 48; const BITS: usize = (1 << 8 - 1) << 48;
#[global_allocator] #[global_allocator]
static GLOBAL_ALLOCATOR: Allocator = Allocator; static GLOBAL_ALLOCATOR: Allocator = Allocator;
@@ -12,31 +9,25 @@ static GLOBAL_ALLOCATOR: Allocator = Allocator;
fn main() { fn main() {
unsafe { Allocator::initialize() } unsafe { Allocator::initialize() }
let t1 = spawn(|| {
unsafe { Allocator::register_current_thread().unwrap() }
loop {
let ptr = allocate();
unsafe { *ptr = 0 };
}
});
let t2 = spawn(|| {
unsafe { Allocator::register_current_thread().unwrap() }
let x = allocate(); let x = allocate();
unsafe { *x = 42 }; unsafe { *x = 42 };
loop { let x = x as usize | BITS;
assert_eq!(unsafe { *((x as usize & !BITS) as *mut usize) }, 42); let mut xs = vec![];
}
});
t1.join().unwrap(); loop {
t2.join().unwrap(); assert_eq!(x & BITS, BITS);
assert_eq!(unsafe { *((x & !BITS) as *mut usize) }, 42);
let ptr = allocate();
unsafe { *ptr = 0 };
xs.push(ptr);
Allocator::force_collect();
}
} }
fn allocate() -> *mut usize { fn allocate() -> *mut usize {
(unsafe { alloc(Layout::new::<usize>()) }) as *mut usize (unsafe { alloc(Layout::from_size_align(1 << 8, 8).unwrap()) }) as *mut usize
} }