Skip to content

Commit 24c66b3

Browse files
57: Make GlobalAllocator allocation calls uncollectable r=ltratt a=jacob-hughes The GlobalAllocator is responsible for allocating all objects which are *not* managed by the GC, so we need to ensure that it doesn't try and allocate them in the managed pool. This is not currently possible for gc_malloc_precise due to limitations in Boehm, so for now, it needs to be prevented. Co-authored-by: Jake Hughes <[email protected]>
2 parents 3809a57 + 7c0e466 commit 24c66b3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

allocator/src/boehm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ extern "C" {
7070
#[cfg(feature = "rustgc")]
7171
pub(crate) fn GC_malloc_atomic(nbytes: usize) -> *mut u8;
7272

73+
#[cfg(feature = "rustgc")]
74+
pub(crate) fn GC_malloc_atomic_uncollectable(nbytes: usize) -> *mut u8;
75+
7376
pub(crate) fn GC_thread_is_registered() -> u32;
7477

7578
pub(crate) fn GC_register_my_thread(stack_base: *mut u8) -> i32;

allocator/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ pub struct GcAllocator;
1313

1414
unsafe impl GlobalAlloc for GcAllocator {
1515
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
16-
#[cfg(feature = "rustgc")]
17-
return boehm::GC_malloc(layout.size()) as *mut u8;
18-
#[cfg(not(feature = "rustgc"))]
1916
return boehm::GC_malloc_uncollectable(layout.size()) as *mut u8;
2017
}
2118

@@ -30,20 +27,19 @@ unsafe impl GlobalAlloc for GcAllocator {
3027
#[cfg(feature = "rustgc")]
3128
#[inline]
3229
unsafe fn alloc_precise(&self, layout: Layout, bitmap: usize, bitmap_size: usize) -> *mut u8 {
33-
let gc_descr = boehm::GC_make_descriptor(&bitmap, bitmap_size);
34-
boehm::GC_malloc_explicitly_typed(layout.size(), gc_descr) as *mut u8
30+
unimplemented!("Boehm does not provide an uncollectable version of this call")
3531
}
3632

3733
#[cfg(feature = "rustgc")]
3834
#[inline]
3935
fn alloc_conservative(&self, layout: Layout) -> *mut u8 {
40-
unsafe { boehm::GC_malloc(layout.size()) as *mut u8 }
36+
unsafe { boehm::GC_malloc_uncollectable(layout.size()) as *mut u8 }
4137
}
4238

4339
#[cfg(feature = "rustgc")]
4440
#[inline]
4541
unsafe fn alloc_untraceable(&self, layout: Layout) -> *mut u8 {
46-
boehm::GC_malloc_atomic(layout.size()) as *mut u8
42+
boehm::GC_malloc_atomic_uncollectable(layout.size()) as *mut u8
4743
}
4844
}
4945

0 commit comments

Comments
 (0)