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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/**
* \file wasmtime/val.h
*
* APIs for interacting with WebAssembly values in Wasmtime.
*/
extern "C" WASMTIME_FEATURE_GC
/// \brief Value of #wasmtime_valkind_t meaning that #wasmtime_val_t is an
/// externref
/// \brief Value of #wasmtime_valkind_t meaning that #wasmtime_val_t is an
/// anyref
/// \brief Value of #wasmtime_valkind_t meaning that #wasmtime_val_t is an
/// exnref
// WASMTIME_FEATURE_GC
/// \brief A 128-bit value representing the WebAssembly `v128` type. Bytes are
/// stored in little-endian order.
typedef uint8_t wasmtime_v128;
/**
* \typedef wasmtime_anyref_t
* \brief Convenience alias for #wasmtime_anyref
*
* \struct wasmtime_anyref
* \brief A WebAssembly value in the `any` hierarchy of GC types.
*
* This structure represents an `anyref` that WebAssembly can create and
* pass back to the host. The host can also create values to pass to a guest.
*
* Note that this structure does not itself contain the data that it refers to.
* Instead to contains metadata to point back within a #wasmtime_context_t, so
* referencing the internal data requires using a `wasmtime_context_t`.
*
* Anyref values are required to be explicitly unrooted via
* `wasmtime_anyref_unroot` to enable them to be garbage-collected.
*
* If you do not unroot the value, *even if you free the corresponding
* Store*, there will be some memory leaked, because GC roots use a
* separate allocation to track liveness.
*
* Null anyref values are represented by this structure and can be tested and
* created with the `wasmtime_anyref_is_null` and `wasmtime_anyref_set_null`
* functions.
*/
typedef struct wasmtime_anyref wasmtime_anyref_t;
/**
* \typedef wasmtime_exnref_t
* \brief Convenience alias for #wasmtime_exnref
*
* \struct wasmtime_exnref
* \brief A WebAssembly exception reference value.
*
* This structure represents an `exnref` value, which is a reference to a
* WebAssembly exception object. Like other GC reference types, it must be
* explicitly unrooted via #wasmtime_exnref_unroot to enable garbage
* collection.
*
* Null exnref values are represented with `store_id == 0`.
*/
typedef struct wasmtime_exnref wasmtime_exnref_t;
/**
* \typedef wasmtime_externref_t
* \brief Convenience alias for #wasmtime_externref
*
* \struct wasmtime_externref
* \brief A host-defined un-forgeable reference to pass into WebAssembly.
*
* This structure represents an `externref` that can be passed to WebAssembly.
* It cannot be forged by WebAssembly itself and is guaranteed to have been
* created by the host.
*
* This structure is similar to #wasmtime_anyref_t but represents the
* `externref` type in WebAssembly. This can be created on the host from
* arbitrary host pointers/destructors. Note that this value is itself a
* reference into a #wasmtime_context_t and must be explicitly unrooted to
* enable garbage collection.
*
* Note that null is represented with this structure and created with
* `wasmtime_externref_set_null`. Null can be tested for with the
* `wasmtime_externref_is_null` function.
*/
typedef struct wasmtime_externref wasmtime_externref_t;
/**
* \typedef wasmtime_eqref_t
* \brief Convenience alias for #wasmtime_eqref
*
* \struct wasmtime_eqref
* \brief A WebAssembly `eqref` value.
*
* This structure represents a reference to a GC object that can be tested for
* equality. The subtypes of `eqref` include `structref`, `arrayref`, and
* `i31ref`.
*
* This type has the same representation and ownership semantics as
* #wasmtime_anyref_t. Values must be explicitly unrooted via
* #wasmtime_eqref_unroot to enable garbage collection.
*/
typedef struct wasmtime_eqref wasmtime_eqref_t;
/**
* \typedef wasmtime_structref_t
* \brief Convenience alias for #wasmtime_structref
*
* \struct wasmtime_structref
* \brief A WebAssembly `structref` value.
*
* This structure represents a reference to a GC struct. It is a subtype of
* `eqref` and `anyref`.
*
* Values must be explicitly unrooted via #wasmtime_structref_unroot.
*/
typedef struct wasmtime_structref wasmtime_structref_t;
/**
* \typedef wasmtime_arrayref_t
* \brief Convenience alias for #wasmtime_arrayref
*
* \struct wasmtime_arrayref
* \brief A WebAssembly `arrayref` value.
*
* This structure represents a reference to a GC array. It is a subtype of
* `eqref` and `anyref`.
*
* Values must be explicitly unrooted via #wasmtime_arrayref_unroot.
*/
typedef struct wasmtime_arrayref wasmtime_arrayref_t;
// WASMTIME_FEATURE_GC
/**
* \typedef wasmtime_valunion_t
* \brief Convenience alias for #wasmtime_valunion
*
* \union wasmtime_valunion
* \brief Container for different kinds of wasm values.
*
* This type is contained in #wasmtime_val_t and contains the payload for the
* various kinds of items a value can be.
*/
typedef union wasmtime_valunion wasmtime_valunion_t;
/// \brief Initialize a `wasmtime_func_t` value as a null function reference.
///
/// This function will initialize the `func` provided to be a null function
/// reference. Used in conjunction with #wasmtime_val_t and
/// #wasmtime_valunion_t.
static inline void
/// \brief Helper function to test whether the `func` provided is a null
/// function reference.
///
/// This function is used with #wasmtime_val_t and #wasmtime_valunion_t and its
/// `funcref` field. This will test whether the field represents a null funcref.
static inline bool
/**
* \typedef wasmtime_val_raw_t
* \brief Convenience alias for #wasmtime_val_raw
*
* \union wasmtime_val_raw
* \brief Container for possible wasm values.
*
* This type is used on conjunction with #wasmtime_func_new_unchecked as well
* as #wasmtime_func_call_unchecked. Instances of this type do not have type
* information associated with them, it's up to the embedder to figure out
* how to interpret the bits contained within, often using some other channel
* to determine the type.
*/
typedef union wasmtime_val_raw wasmtime_val_raw_t;
// Assert that the shape of this type is as expected since it needs to match
// Rust.
static inline void
/**
* \typedef wasmtime_val_t
* \brief Convenience alias for #wasmtime_val_t
*
* \union wasmtime_val
* \brief Container for different kinds of wasm values.
*
* Note that this structure may contain an owned value, namely rooted GC
* references, depending on the context in which this is used. APIs which
* consume a #wasmtime_val_t do not take ownership, but APIs that return
* #wasmtime_val_t require that #wasmtime_val_unroot is called to clean up
* any possible GC roots in the value.
*
* If you do not unroot the value, *even if you free the corresponding
* Store*, there will be some memory leaked, because GC roots use a
* separate allocation to track liveness.
*/
typedef struct wasmtime_val wasmtime_val_t;
/**
* \brief Unroot the value contained by `val`.
*
* This function will unroot any GC references that `val` points to, for
* example if it has the `WASMTIME_EXTERNREF`, `WASMTIME_ANYREF`, or
* `WASMTIME_EXNREF` kinds. This
* function leaves `val` in an undefined state and it should not be used again
* without re-initializing.
*
* This method does not need to be called for integers, floats, v128, or
* funcref values.
*/
WASM_API_EXTERN void ;
/**
* \brief Clones the value pointed to by `src` into the `dst` provided.
*
* This function will clone any rooted GC values in `src` and have them
* newly rooted inside of `dst`. When using this API the `dst` should be
* later unrooted with #wasmtime_val_unroot if it contains GC values.
*/
WASM_API_EXTERN void ;
} // extern "C"
// WASMTIME_VAL_H