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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//! Hand-rolled `#[repr(C)]` plugin vtable.
//!
//! Design rationale: see ADR-001 / docs/abi-evolution.md (TBD). In short:
//! `abi_stable`'s prefix-type model rejects loads where the host's vtable
//! has more fields than the plugin's, blocking the host-grows-faster
//! direction we need. The hand-rolled C-style vtable with a leading
//! `api_version: u32` field, version-gated host access, and an
//! append-only evolution discipline gives us bidirectional ABI compat
//! without a third-party load-time check that fights us.
//!
//! # Layout invariants (load-bearing)
//!
//! 1. `api_version` MUST be the first field.
//! 2. Existing fields MUST NOT be reordered or removed in any future
//! crate version. New fields MUST be appended after the existing ones.
//! 3. `PLUGIN_API_VERSION` increments by 1 each time a new field is
//! appended and the corresponding accessor lands.
//! 4. Hosts MUST read `api_version` before accessing any field beyond
//! the v1 baseline. Reading newer fields on a plugin that reports
//! a lower `api_version` is undefined behavior — the plugin's
//! allocation does not include those bytes.
//!
//! See `crates/hub/tests/abi_matrix.rs` for the regression test that
//! enforces invariants 1–3 by loading every published plugin version
//! against the current hub binary.
use c_void;
use ;
use crateRecordMetricFn;
use crate;
/// API version corresponding to the v1 baseline (initial release of the
/// hand-rolled vtable). Every field declared in `PluginVTable` is part
/// of v1 and is present on every plugin built against this crate.
pub const PLUGIN_API_VERSION_V1: u32 = 1;
/// API version v2: adds `set_metric_recorder` so plugins can emit
/// Prometheus metrics through the hub's existing recorder. Plugins
/// built against v2 keep loading on v1 hubs (the hub ignores the field
/// because it doesn't know it exists); plugins built against v1 keep
/// loading on v2 hubs (the hub gates access on `api_version >= 2` and
/// skips the install for v1 plugins).
pub const PLUGIN_API_VERSION_V2: u32 = 2;
/// Latest API version this crate's `PluginVTable` exposes. Plugin
/// authors set this as the `api_version` field. When future versions
/// of this crate append a field, this constant bumps by 1.
pub const PLUGIN_API_VERSION: u32 = PLUGIN_API_VERSION_V2;
/// Symbol name the hub looks up via `dlsym` after `dlopen`.
pub const GET_PLUGIN_VTABLE_SYMBOL: & = b"get_plugin_vtable\0";
/// Type of the exported entry-point symbol.
pub type GetPluginVTableFn = extern "C" fn ;
/// The function table a plugin shared library exports.
///
/// `#[repr(C)]` is mandatory: it pins field offsets and padding rules
/// so plugins built against an older version of this crate keep
/// working when the hub is built against a newer one (and vice versa).
///
/// # Safety contract for hosts
///
/// Fields below the v1 baseline marker are version-gated. Hosts MUST
/// NOT access them via `&PluginVTable` directly — the borrow would
/// implicitly cover the whole struct, which on an older plugin is
/// past the end of its allocation. Use the `read_*_field` accessors
/// or read individual fields through the raw pointer (e.g.
/// `unsafe { (*ptr).api_version }`) which read only the bytes for that
/// field.