4 Commits

Author SHA1 Message Date
Yota Toyama
e11647fab9 Merge branch 'main' into chore/pointer-mask 2023-09-28 15:55:11 +10:00
Yota Toyama
08d549315b Fix 2023-09-24 20:23:45 +10:00
Yota Toyama
a4bcbf2c7b Call memalign 2023-09-24 17:01:53 +10:00
Yota Toyama
5f41a2b8e2 Set pointer mask 2023-09-24 16:56:08 +10:00
6 changed files with 7 additions and 42 deletions

View File

@@ -3,7 +3,6 @@
"autogen",
"autotools",
"bdwgc",
"canonicalize",
"cflag",
"dealloc",
"finalizer",

View File

@@ -23,8 +23,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 -D POINTER_MASK=0x7",
dst.join("include").display()
))
.build();
@@ -60,7 +59,10 @@ fn main() {
let dst = Config::new(LIB_GC_DIR)
.profile("Release")
.define("BUILD_SHARED_LIBS", "FALSE")
.cflag(format!("-I{}", libatomic_include_path))
.cflag(format!(
"-I{} -DPOINTER_MASK=0x7",
libatomic_include_path, foo
))
.build();
println!(

View File

@@ -5,5 +5,4 @@ members = [
"free_by_borrow",
"free_by_gc",
"static_threads",
"tagged_pointer",
]

View File

@@ -1,9 +0,0 @@
[package]
name = "tagged_pointer"
version = "0.1.0"
authors = ["Yota Toyama <raviqqe@gmail.com>"]
edition = "2021"
publish = false
[dependencies]
bdwgc-alloc = { path = "../.." }

View File

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

View File

@@ -25,6 +25,7 @@ extern "C" {
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
fn GC_init();
fn GC_malloc(size: size_t) -> *mut c_void;
fn GC_memalign(align: size_t, size: size_t) -> *mut c_void;
fn GC_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
@@ -126,7 +127,7 @@ impl Allocator {
unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
GC_malloc(layout.size()) as *mut u8
GC_memalign(layout.align(), layout.size()) as *mut u8
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {