1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::collector::RawCollectorImpl;
use crate::{ContextState, ShadowStack, CollectorRef};
use std::mem::ManuallyDrop;
use std::fmt::Debug;
#[cfg(feature = "sync")]
pub mod sync;
pub mod nosync;
pub unsafe trait CollectionManager<C>: self::sealed::Sealed
where C: RawCollectorImpl<Manager=Self, RawContext=Self::Context> {
type Context: RawContext<C>;
fn new() -> Self;
fn is_collecting(&self) -> bool;
fn should_trigger_collection(&self) -> bool;
unsafe fn freeze_context(&self, context: &Self::Context);
unsafe fn unfreeze_context(&self, context: &Self::Context);
fn prevent_collection<R>(collector: &C, func: impl FnOnce() -> R) -> R;
unsafe fn free_context(collector: &C, context: *mut Self::Context);
}
pub unsafe trait RawContext<C>: Debug + self::sealed::Sealed
where C: RawCollectorImpl<RawContext=Self> {
unsafe fn register_new(collector: &CollectorRef<C>) -> ManuallyDrop<Box<Self>>;
unsafe fn trigger_safepoint(&self);
#[inline]
unsafe fn assume_valid_shadow_stack(&self) -> &ShadowStack<C> {
match self.state() {
ContextState::Active => unreachable!("active context: {:?}", self),
ContextState::SafePoint { .. } | ContextState::Frozen { .. } => {},
}
&*self.shadow_stack_ptr()
}
fn shadow_stack_ptr(&self) -> *mut ShadowStack<C>;
unsafe fn collector(&self) -> &C;
fn state(&self) -> ContextState;
}
mod sealed {
pub trait Sealed {}
}