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
//! What may be stored in pool memory, and the macro that says so for a list of
//! types.
use UnsafeCell;
use ;
/// A type that may live in the run's pool, and so in a checkpoint.
///
/// You need this on any type you hand to `AllocRef::leak_and_initialize_sbx` or
/// `..._anon`, or store in a `BVec` or `BMap`. The integers, `()`, `AtomicU32`,
/// `AtomicUsize`, `UnsafeCell<T>` and `[T; N]` already have it; write
/// [`impl_sandbox_safe!`](crate::impl_sandbox_safe) for your own.
///
/// # Safety
///
/// A checkpoint stores the pool's bytes and restores them into a run that has
/// nothing else in common with the one that wrote them. So: no `Box`, `Vec`,
/// `String` or any other host-heap owner inside, and every pointer the type
/// holds must address pool memory, which keeps its address across a restore. A
/// host pointer written before a save is a dangling pointer after the restore,
/// and nothing will tell you.
pub unsafe
/// Declare [`SandboxSafe`] for one or more types at once.
///
/// # Safety
///
/// This writes an `unsafe impl` for every type listed, so each must meet
/// [`SandboxSafe`]'s conditions — no host-heap ownership, no pointer outside
/// the pool. Nothing is checked.
///
/// # Examples
///
/// ```ignore
/// #[repr(C)]
/// pub struct Counters { hits: u64, misses: u64 }
///
/// #[repr(C)]
/// pub struct Window { start: u64, len: u64 }
///
/// impl_sandbox_safe!(Counters, Window);
/// ```
// The integers: plain data, no pointers.
impl_sandbox_safe!;
// Zero-sized, so there is nothing to restore.
unsafe
// Atomics carry no pointers; the interior mutability is part of the layout.
unsafe
unsafe
// The cell adds interior mutability and no pointers, so it inherits T's answer.
unsafe
// An array is its element repeated; nothing new is reachable through it.
unsafe