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
79
80
81
82
//! `RealtimeSanitizer` escape hatch for intentionally-blocking regions.
//!
//! Under `--cfg rtsan` the audio worker / RT paths carry
//! `#[sanitize(realtime = "nonblocking")]` (via `#[kithara::rtsan_forbid_blocking]`),
//! so `RTSan` aborts on any `malloc` / `free` / lock / syscall reached from them.
//! A function annotated `#[kithara::rtsan_allow_blocking]` opens a [`permit`]
//! guard for its whole body, suspending those checks via the `__rtsan_disable`
//! / `__rtsan_enable` C entry points exported by the linked sanitizer runtime —
//! used to *inventory* genuinely-unavoidable blocking points one at a time
//! while the surrounding coordination stays checked.
//!
//! The guard is **reentrant**: a thread-local depth counter toggles the runtime
//! only at the outermost permit, so annotating both a caller and a callee (or
//! re-entering through recursion) stays correct regardless of whether the
//! runtime's own `disable` is refcounted. Off `rtsan` the guard is a zero-cost
//! ZST.
unsafe extern "C"
thread_local!
/// RAII guard that re-enables `RealtimeSanitizer` checks when the outermost
/// guard on the thread drops. Created by [`permit`]; emitted by
/// `#[kithara::rtsan_allow_blocking]`.
;
/// Suspend `RealtimeSanitizer` blocking-checks until the returned guard drops.
///
/// Reentrant: only the outermost live guard toggles the runtime.
/// Zero-cost no-op guard when `RealtimeSanitizer` is not compiled in.
;
/// No-op when `RealtimeSanitizer` is not compiled in.