Wasmtime
wasm.h
Go to the documentation of this file.
1// Wasmtime-vendored copy of this header file as present in upstream:
2// <https://github.com/WebAssembly/wasm-c-api/blob/9d6b93764ac96cdd9db51081c363e09d2d488b4d/include/wasm.h>
3//
4// Wasmtime maintainers can update this vendored copy in-tree with the
5// ./ci/vendor-c-api-headers.sh shell script.
6//
7// WebAssembly C API
8
9#ifndef WASM_H
10#define WASM_H
11
12#include <stddef.h>
13#include <stdint.h>
14#include <stdbool.h>
15#include <string.h>
16#include <assert.h>
17
18#ifndef WASM_API_EXTERN
19#if defined(_WIN32) && !defined(__MINGW32__) && !defined(LIBWASM_STATIC)
20#define WASM_API_EXTERN __declspec(dllimport)
21#else
22#define WASM_API_EXTERN
23#endif
24#endif
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
31// Auxiliaries
32
33// Machine types
34
35inline void assertions(void) {
36 static_assert(sizeof(float) == sizeof(uint32_t), "incompatible float type");
37 static_assert(sizeof(double) == sizeof(uint64_t), "incompatible double type");
38 static_assert(sizeof(intptr_t) == sizeof(uint32_t) ||
39 sizeof(intptr_t) == sizeof(uint64_t),
40 "incompatible pointer type");
41}
42
43typedef char byte_t;
44typedef float float32_t;
45typedef double float64_t;
46
47
48// Ownership
49
50#define own
51
52// The qualifier `own` is used to indicate ownership of data in this API.
53// It is intended to be interpreted similar to a `const` qualifier:
54//
55// - `own wasm_xxx_t*` owns the pointed-to data
56// - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx`
57// - `own wasm_xxx_vec_t` owns the vector as well as its elements(!)
58// - an `own` function parameter passes ownership from caller to callee
59// - an `own` function result passes ownership from callee to caller
60// - an exception are `own` pointer parameters named `out`, which are copy-back
61// output parameters passing back ownership from callee to caller
62//
63// Own data is created by `wasm_xxx_new` functions and some others.
64// It must be released with the corresponding `wasm_xxx_delete` function.
65//
66// Deleting a reference does not necessarily delete the underlying object,
67// it merely indicates that this owner no longer uses it.
68//
69// For vectors, `const wasm_xxx_vec_t` is used informally to indicate that
70// neither the vector nor its elements should be modified.
71// TODO: introduce proper `wasm_xxx_const_vec_t`?
72
73
74#define WASM_DECLARE_OWN(name) \
75 typedef struct wasm_##name##_t wasm_##name##_t; \
76 \
77 WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*);
78
79
80// Vectors
81
82#define WASM_DECLARE_VEC(name, ptr_or_none) \
83 typedef struct wasm_##name##_vec_t { \
84 size_t size; \
85 wasm_##name##_t ptr_or_none* data; \
86 } wasm_##name##_vec_t; \
87 \
88 WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \
89 WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \
90 own wasm_##name##_vec_t* out, size_t); \
91 WASM_API_EXTERN void wasm_##name##_vec_new( \
92 own wasm_##name##_vec_t* out, \
93 size_t, own wasm_##name##_t ptr_or_none const[]); \
94 WASM_API_EXTERN void wasm_##name##_vec_copy( \
95 own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \
96 WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*);
97
98
99// Byte vectors
100
102WASM_DECLARE_VEC(byte, )
103
105
106#define wasm_name wasm_byte_vec
107#define wasm_name_new wasm_byte_vec_new
108#define wasm_name_new_empty wasm_byte_vec_new_empty
109#define wasm_name_new_uninitialized wasm_byte_vec_new_uninitialized
110#define wasm_name_copy wasm_byte_vec_copy
111#define wasm_name_delete wasm_byte_vec_delete
112
113static inline void wasm_name_new_from_string(
114 own wasm_name_t* out, const char* s
115) {
116 wasm_name_new(out, strlen(s), s);
117}
118
119static inline void wasm_name_new_from_string_nt(
120 own wasm_name_t* out, const char* s
121) {
122 wasm_name_new(out, strlen(s) + 1, s);
123}
124
125
127// Runtime Environment
128
129// Configuration
130
131WASM_DECLARE_OWN(config)
132
133WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
134
135// Embedders may provide custom functions for manipulating configs.
136
137
138// Engine
139
140WASM_DECLARE_OWN(engine)
141
142WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
144
145
146// Store
147
148WASM_DECLARE_OWN(store)
149
151
152
154// Type Representations
155
156// Type attributes
157
158typedef uint8_t wasm_mutability_t;
159enum wasm_mutability_enum {
160 WASM_CONST,
161 WASM_VAR,
162};
163
164typedef struct wasm_limits_t {
165 uint32_t min;
166 uint32_t max;
168
169static const uint32_t wasm_limits_max_default = 0xffffffff;
170
171
172// Generic
173
174#define WASM_DECLARE_TYPE(name) \
175 WASM_DECLARE_OWN(name) \
176 WASM_DECLARE_VEC(name, *) \
177 \
178 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*);
179
180
181// Value Types
182
183WASM_DECLARE_TYPE(valtype)
184
185typedef uint8_t wasm_valkind_t;
186enum wasm_valkind_enum {
187 WASM_I32,
188 WASM_I64,
189 WASM_F32,
190 WASM_F64,
191 WASM_EXTERNREF = 128,
192 WASM_FUNCREF,
193};
194
196
198
199static inline bool wasm_valkind_is_num(wasm_valkind_t k) {
200 return k < WASM_EXTERNREF;
201}
202static inline bool wasm_valkind_is_ref(wasm_valkind_t k) {
203 return k >= WASM_EXTERNREF;
204}
205
206static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) {
207 return wasm_valkind_is_num(wasm_valtype_kind(t));
208}
209static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) {
210 return wasm_valkind_is_ref(wasm_valtype_kind(t));
211}
212
213
214// Function Types
215
216WASM_DECLARE_TYPE(functype)
217
219 own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results);
220
223
224
225// Global Types
226
227WASM_DECLARE_TYPE(globaltype)
228
231
234
235
236// Table Types
237
238WASM_DECLARE_TYPE(tabletype)
239
241 own wasm_valtype_t*, const wasm_limits_t*);
242
245
246
247// Memory Types
248
249WASM_DECLARE_TYPE(memorytype)
250
252
254
255
256// Tag Types
257
258WASM_DECLARE_TYPE(tagtype)
259
261
263
264
265// Extern Types
266
267WASM_DECLARE_TYPE(externtype)
268
269typedef uint8_t wasm_externkind_t;
270enum wasm_externkind_enum {
271 WASM_EXTERN_FUNC,
272 WASM_EXTERN_GLOBAL,
273 WASM_EXTERN_TABLE,
274 WASM_EXTERN_MEMORY,
275 WASM_EXTERN_TAG,
276};
277
279
285
291
297
303
304
305// Import Types
306
307WASM_DECLARE_TYPE(importtype)
308
310 own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*);
311
315
316
317// Export Types
318
319WASM_DECLARE_TYPE(exporttype)
320
322 own wasm_name_t*, own wasm_externtype_t*);
323
326
327
329// Runtime Objects
330
331// Values
332
333struct wasm_ref_t;
334
335typedef struct wasm_val_t {
337 union {
338 int32_t i32;
339 int64_t i64;
340 float32_t f32;
341 float64_t f64;
342 struct wasm_ref_t* ref;
343 } of;
345
346WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
347WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);
348
349WASM_DECLARE_VEC(val, )
350
351
352// References
353
354#define WASM_DECLARE_REF_BASE(name) \
355 WASM_DECLARE_OWN(name) \
356 \
357 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
358 WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \
359 \
360 WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
361 WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
362 WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \
363 wasm_##name##_t*, void*, void (*)(void*));
364
365#define WASM_DECLARE_REF(name) \
366 WASM_DECLARE_REF_BASE(name) \
367 \
368 WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \
369 WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \
370 WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \
371 WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*);
372
373#define WASM_DECLARE_SHARABLE_REF(name) \
374 WASM_DECLARE_REF(name) \
375 WASM_DECLARE_OWN(shared_##name) \
376 \
377 WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \
378 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*);
379
380
381WASM_DECLARE_REF_BASE(ref)
382
383
384// Frames
385
386WASM_DECLARE_OWN(frame)
387WASM_DECLARE_VEC(frame, *)
388WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*);
389
390WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*);
391WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*);
392WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*);
393WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*);
394
395
396// Traps
397
398typedef wasm_name_t wasm_message_t; // null terminated
399
400WASM_DECLARE_REF(trap)
401
402WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*);
403
404WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out);
405WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*);
406WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out);
407
408
409// Foreign Objects
410
411WASM_DECLARE_REF(foreign)
412
414
415
416// Modules
417
418WASM_DECLARE_SHARABLE_REF(module)
419
420WASM_API_EXTERN own wasm_module_t* wasm_module_new(
421 wasm_store_t*, const wasm_byte_vec_t* binary);
422
423WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary);
424
425WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out);
426WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out);
427
428WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out);
430
431
432// Function Instances
433
434WASM_DECLARE_REF(func)
435
437 const wasm_val_vec_t* args, own wasm_val_vec_t* results);
439 void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results);
440
441WASM_API_EXTERN own wasm_func_t* wasm_func_new(
445 void* env, void (*finalizer)(void*));
446
447WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*);
448WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*);
449WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*);
450
451WASM_API_EXTERN own wasm_trap_t* wasm_func_call(
452 const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results);
453
454
455// Global Instances
456
457WASM_DECLARE_REF(global)
458
459WASM_API_EXTERN own wasm_global_t* wasm_global_new(
460 wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*);
461
463
464WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out);
465WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*);
466
467
468// Table Instances
469
470WASM_DECLARE_REF(table)
471
472typedef uint32_t wasm_table_size_t;
473
474WASM_API_EXTERN own wasm_table_t* wasm_table_new(
476
477WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*);
478
479WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index);
481
483WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init);
484
485
486// Memory Instances
487
488WASM_DECLARE_REF(memory)
489
490typedef uint32_t wasm_memory_pages_t;
491
492static const size_t MEMORY_PAGE_SIZE = 0x10000;
493
495
497
499WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*);
500
503
504
505// Externals
506
507WASM_DECLARE_REF(extern)
508WASM_DECLARE_VEC(extern, *)
509
512
517
522
527
532
533
534// Module Instances
535
536WASM_DECLARE_REF(instance)
537
539 wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports,
540 own wasm_trap_t**
541);
542
543WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
544
545
547// Convenience
548
549// Vectors
550
551#define WASM_EMPTY_VEC {0, NULL}
552#define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array}
553
554
555// Value Type construction short-hands
556
557static inline own wasm_valtype_t* wasm_valtype_new_i32(void) {
558 return wasm_valtype_new(WASM_I32);
559}
560static inline own wasm_valtype_t* wasm_valtype_new_i64(void) {
561 return wasm_valtype_new(WASM_I64);
562}
563static inline own wasm_valtype_t* wasm_valtype_new_f32(void) {
564 return wasm_valtype_new(WASM_F32);
565}
566static inline own wasm_valtype_t* wasm_valtype_new_f64(void) {
567 return wasm_valtype_new(WASM_F64);
568}
569
570static inline own wasm_valtype_t* wasm_valtype_new_externref(void) {
571 return wasm_valtype_new(WASM_EXTERNREF);
572}
573static inline own wasm_valtype_t* wasm_valtype_new_funcref(void) {
574 return wasm_valtype_new(WASM_FUNCREF);
575}
576
577
578// Function Types construction short-hands
579
580static inline own wasm_functype_t* wasm_functype_new_0_0(void) {
581 wasm_valtype_vec_t params, results;
584 return wasm_functype_new(&params, &results);
585}
586
587static inline own wasm_functype_t* wasm_functype_new_1_0(
588 own wasm_valtype_t* p
589) {
590 wasm_valtype_t* ps[1] = {p};
591 wasm_valtype_vec_t params, results;
592 wasm_valtype_vec_new(&params, 1, ps);
594 return wasm_functype_new(&params, &results);
595}
596
597static inline own wasm_functype_t* wasm_functype_new_2_0(
598 own wasm_valtype_t* p1, own wasm_valtype_t* p2
599) {
600 wasm_valtype_t* ps[2] = {p1, p2};
601 wasm_valtype_vec_t params, results;
602 wasm_valtype_vec_new(&params, 2, ps);
604 return wasm_functype_new(&params, &results);
605}
606
607static inline own wasm_functype_t* wasm_functype_new_3_0(
608 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3
609) {
610 wasm_valtype_t* ps[3] = {p1, p2, p3};
611 wasm_valtype_vec_t params, results;
612 wasm_valtype_vec_new(&params, 3, ps);
614 return wasm_functype_new(&params, &results);
615}
616
617static inline own wasm_functype_t* wasm_functype_new_0_1(
618 own wasm_valtype_t* r
619) {
620 wasm_valtype_t* rs[1] = {r};
621 wasm_valtype_vec_t params, results;
623 wasm_valtype_vec_new(&results, 1, rs);
624 return wasm_functype_new(&params, &results);
625}
626
627static inline own wasm_functype_t* wasm_functype_new_1_1(
628 own wasm_valtype_t* p, own wasm_valtype_t* r
629) {
630 wasm_valtype_t* ps[1] = {p};
631 wasm_valtype_t* rs[1] = {r};
632 wasm_valtype_vec_t params, results;
633 wasm_valtype_vec_new(&params, 1, ps);
634 wasm_valtype_vec_new(&results, 1, rs);
635 return wasm_functype_new(&params, &results);
636}
637
638static inline own wasm_functype_t* wasm_functype_new_2_1(
639 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r
640) {
641 wasm_valtype_t* ps[2] = {p1, p2};
642 wasm_valtype_t* rs[1] = {r};
643 wasm_valtype_vec_t params, results;
644 wasm_valtype_vec_new(&params, 2, ps);
645 wasm_valtype_vec_new(&results, 1, rs);
646 return wasm_functype_new(&params, &results);
647}
648
649static inline own wasm_functype_t* wasm_functype_new_3_1(
650 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
651 own wasm_valtype_t* r
652) {
653 wasm_valtype_t* ps[3] = {p1, p2, p3};
654 wasm_valtype_t* rs[1] = {r};
655 wasm_valtype_vec_t params, results;
656 wasm_valtype_vec_new(&params, 3, ps);
657 wasm_valtype_vec_new(&results, 1, rs);
658 return wasm_functype_new(&params, &results);
659}
660
661static inline own wasm_functype_t* wasm_functype_new_0_2(
662 own wasm_valtype_t* r1, own wasm_valtype_t* r2
663) {
664 wasm_valtype_t* rs[2] = {r1, r2};
665 wasm_valtype_vec_t params, results;
667 wasm_valtype_vec_new(&results, 2, rs);
668 return wasm_functype_new(&params, &results);
669}
670
671static inline own wasm_functype_t* wasm_functype_new_1_2(
672 own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2
673) {
674 wasm_valtype_t* ps[1] = {p};
675 wasm_valtype_t* rs[2] = {r1, r2};
676 wasm_valtype_vec_t params, results;
677 wasm_valtype_vec_new(&params, 1, ps);
678 wasm_valtype_vec_new(&results, 2, rs);
679 return wasm_functype_new(&params, &results);
680}
681
682static inline own wasm_functype_t* wasm_functype_new_2_2(
683 own wasm_valtype_t* p1, own wasm_valtype_t* p2,
684 own wasm_valtype_t* r1, own wasm_valtype_t* r2
685) {
686 wasm_valtype_t* ps[2] = {p1, p2};
687 wasm_valtype_t* rs[2] = {r1, r2};
688 wasm_valtype_vec_t params, results;
689 wasm_valtype_vec_new(&params, 2, ps);
690 wasm_valtype_vec_new(&results, 2, rs);
691 return wasm_functype_new(&params, &results);
692}
693
694static inline own wasm_functype_t* wasm_functype_new_3_2(
695 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
696 own wasm_valtype_t* r1, own wasm_valtype_t* r2
697) {
698 wasm_valtype_t* ps[3] = {p1, p2, p3};
699 wasm_valtype_t* rs[2] = {r1, r2};
700 wasm_valtype_vec_t params, results;
701 wasm_valtype_vec_new(&params, 3, ps);
702 wasm_valtype_vec_new(&results, 2, rs);
703 return wasm_functype_new(&params, &results);
704}
705
706
707// Value construction short-hands
708
709static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) {
710#if UINTPTR_MAX == UINT32_MAX
711 out->kind = WASM_I32;
712 out->of.i32 = (intptr_t)p;
713#elif UINTPTR_MAX == UINT64_MAX
714 out->kind = WASM_I64;
715 out->of.i64 = (intptr_t)p;
716#endif
717}
718
719static inline void* wasm_val_ptr(const wasm_val_t* val) {
720#if UINTPTR_MAX == UINT32_MAX
721 return (void*)(intptr_t)val->of.i32;
722#elif UINTPTR_MAX == UINT64_MAX
723 return (void*)(intptr_t)val->of.i64;
724#endif
725}
726
727#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}}
728#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}}
729#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}}
730#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}}
731#define WASM_REF_VAL(r) {.kind = WASM_EXTERNREF, .of = {.ref = r}}
732#define WASM_INIT_VAL {.kind = WASM_EXTERNREF, .of = {.ref = NULL}}
733
734
736
737#undef own
738
739#ifdef __cplusplus
740} // extern "C"
741#endif
742
743#endif // #ifdef WASM_H
A list of bytes.
Definition: wasm.h:102
Global engine configuration.
Compilation environment and configuration.
An opaque object representing the type of an export.
A list of wasm_exporttype_t values.
Definition: wasm.h:319
Opaque struct representing a wasm external value.
A list of wasm_extern_t values.
Definition: wasm.h:508
An opaque object representing the type of a external value. Can be seen as a superclass of wasm_funct...
Unimplemented in Wasmtime.
Opaque struct representing a frame of a wasm stack trace.
A list of wasm_frame_t frameues.
Definition: wasm.h:387
Opaque struct representing a compiled wasm function.
An opaque object representing the type of a function.
Opaque struct representing a wasm global.
An opaque object representing the type of a global.
An opaque object representing the type of an import.
A list of wasm_importtype_t values.
Definition: wasm.h:307
Opaque struct representing a wasm instance.
Limits for tables/memories in wasm modules.
Definition: wasm.h:164
uint32_t min
Definition: wasm.h:165
uint32_t max
Definition: wasm.h:166
Opaque struct representing a wasm memory.
An opaque object representing the type of a memory.
Opaque struct representing a compiled wasm module.
A reference type: either a funcref or an externref.
A collection of instances and wasm global items.
Opaque struct representing a wasm table.
An opaque object representing the type of a table.
An opaque object representing the type of a tag.
Opaque struct representing a wasm trap.
Representation of a WebAssembly value.
Definition: wasm.h:335
wasm_valkind_t kind
The kind of this value, or which of the fields in the of payload contains the actual value.
Definition: wasm.h:336
union wasm_val_t::@0 of
The actual value of this wasm_val_t. Only one field of this anonymous union is valid,...
A list of wasm_val_t values.
Definition: wasm.h:349
An object representing the type of a value.
A list of wasm_valtype_t values.
Definition: wasm.h:183
const wasm_externtype_t * wasm_importtype_type(const wasm_importtype_t *)
Returns the type of item this import is importing.
const wasm_functype_t * wasm_externtype_as_functype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_functype_t.
struct wasm_val_t wasm_val_t
Convenience alias for wasm_val_t.
uint32_t wasm_frame_func_index(const wasm_frame_t *)
Returns the function index in the original wasm module that this frame corresponds to.
const wasm_valtype_t * wasm_tabletype_element(const wasm_tabletype_t *)
Returns the element type of this table.
wasm_global_t * wasm_global_new(wasm_store_t *, const wasm_globaltype_t *, const wasm_val_t *)
Creates a new WebAssembly global.
struct wasm_instance_t * wasm_frame_instance(const wasm_frame_t *)
Unimplemented in Wasmtime, aborts the process if called.
const wasm_globaltype_t * wasm_externtype_as_globaltype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_globaltype_t.
void wasm_global_get(const wasm_global_t *, wasm_val_t *out)
Gets the value of this global.
wasm_tabletype_t * wasm_tabletype_new(wasm_valtype_t *, const wasm_limits_t *)
Creates a new table type.
void wasm_module_exports(const wasm_module_t *, wasm_exporttype_vec_t *out)
Returns the list of exports that this module provides.
const wasm_extern_t * wasm_memory_as_extern_const(const wasm_memory_t *)
Converts a wasm_memory_t to wasm_extern_t.
wasm_tabletype_t * wasm_externtype_as_tabletype(wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tabletype_t.
void wasm_trap_message(const wasm_trap_t *, wasm_message_t *out)
Retrieves the message associated with this trap.
const wasm_functype_t * wasm_tagtype_functype(const wasm_tagtype_t *)
Returns the function type of this tag type.
wasm_tagtype_t * wasm_tagtype_new(wasm_functype_t *)
Creates a new tag type.
wasm_extern_t * wasm_func_as_extern(wasm_func_t *)
Converts a wasm_func_t to wasm_extern_t.
wasm_config_t * wasm_config_new(void)
Creates a new empty configuration object.
const wasm_name_t * wasm_exporttype_name(const wasm_exporttype_t *)
Returns the name of this export.
uint8_t wasm_externkind_t
Classifier for wasm_externtype_t.
Definition: wasm.h:269
wasm_table_t * wasm_extern_as_table(wasm_extern_t *)
Converts a wasm_extern_t to wasm_table_t.
void wasm_trap_trace(const wasm_trap_t *, wasm_frame_vec_t *out)
Returns the trace of wasm frames for this trap.
wasm_func_t * wasm_func_new_with_env(wasm_store_t *, const wasm_functype_t *type, wasm_func_callback_with_env_t, void *env, void(*finalizer)(void *))
Creates a new WebAssembly function with host functionality.
wasm_module_t * wasm_module_new(wasm_store_t *, const wasm_byte_vec_t *binary)
Compiles a raw WebAssembly binary to a wasm_module_t.
wasm_externkind_t wasm_extern_kind(const wasm_extern_t *)
Returns the kind of this extern, indicating what it will downcast as.
void wasm_instance_exports(const wasm_instance_t *, wasm_extern_vec_t *out)
Returns the exports of an instance.
wasm_trap_t *(* wasm_func_callback_t)(const wasm_val_vec_t *args, wasm_val_vec_t *results)
Type definition for functions passed to wasm_func_new.
Definition: wasm.h:436
size_t wasm_frame_module_offset(const wasm_frame_t *)
Returns the byte offset from the beginning of the original wasm file to the instruction this frame po...
wasm_memorytype_t * wasm_memory_type(const wasm_memory_t *)
Returns the type of this memory.
void wasm_valtype_vec_new(wasm_valtype_vec_t *out, size_t, wasm_valtype_t *const[])
Creates a vector with the provided contents.
const wasm_externtype_t * wasm_exporttype_type(const wasm_exporttype_t *)
Returns the type of this export.
const wasm_tabletype_t * wasm_externtype_as_tabletype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tabletype_t.
uint32_t wasm_table_size_t
Typedef for indices and sizes of wasm tables.
Definition: wasm.h:472
const wasm_externtype_t * wasm_tabletype_as_externtype_const(const wasm_tabletype_t *)
Converts a wasm_tabletype_t to a wasm_externtype_t.
wasm_memory_t * wasm_memory_new(wasm_store_t *, const wasm_memorytype_t *)
Creates a new WebAssembly memory.
wasm_extern_t * wasm_memory_as_extern(wasm_memory_t *)
Converts a wasm_memory_t to wasm_extern_t.
wasm_engine_t * wasm_engine_new(void)
Creates a new engine with the default configuration.
wasm_table_size_t wasm_table_size(const wasm_table_t *)
Gets the current size, in elements, of this table.
uint8_t wasm_valkind_t
Different kinds of types supported in wasm.
Definition: wasm.h:185
const wasm_valtype_vec_t * wasm_functype_results(const wasm_functype_t *)
Returns the list of results of this function type.
void wasm_global_set(wasm_global_t *, const wasm_val_t *)
Sets the value of this global.
const wasm_limits_t * wasm_memorytype_limits(const wasm_memorytype_t *)
Returns the limits of this memory.
const wasm_valtype_vec_t * wasm_functype_params(const wasm_functype_t *)
Returns the list of parameters of this function type.
char byte_t
A type definition for a number that occupies a single byte of data.
Definition: wasm.h:43
const wasm_valtype_t * wasm_globaltype_content(const wasm_globaltype_t *)
Returns the type of value contained in a global.
const wasm_externtype_t * wasm_functype_as_externtype_const(const wasm_functype_t *)
Converts a wasm_functype_t to a wasm_externtype_t.
const wasm_name_t * wasm_importtype_name(const wasm_importtype_t *)
Returns the name this import is importing from.
size_t wasm_func_param_arity(const wasm_func_t *)
Returns the number of arguments expected by this function.
const wasm_global_t * wasm_extern_as_global_const(const wasm_extern_t *)
Converts a wasm_extern_t to wasm_global_t.
wasm_frame_t * wasm_trap_origin(const wasm_trap_t *)
Returns the top frame of the wasm stack responsible for this trap.
size_t wasm_memory_data_size(const wasm_memory_t *)
Returns the size, in bytes, of this memory.
const wasm_memory_t * wasm_extern_as_memory_const(const wasm_extern_t *)
Converts a wasm_extern_t to wasm_memory_t.
bool wasm_table_grow(wasm_table_t *, wasm_table_size_t delta, wasm_ref_t *init)
Attempts to grow this table by delta elements.
wasm_trap_t * wasm_trap_new(wasm_store_t *store, const wasm_message_t *)
Creates a new wasm_trap_t with the provided message.
struct wasm_limits_t wasm_limits_t
A convenience typedef to wasm_limits_t.
wasm_exporttype_t * wasm_exporttype_new(wasm_name_t *, wasm_externtype_t *)
Creates a new export type.
wasm_instance_t * wasm_instance_new(wasm_store_t *, const wasm_module_t *, const wasm_extern_vec_t *imports, wasm_trap_t **)
Instantiates a module with the provided imports.
void wasm_val_copy(wasm_val_t *out, const wasm_val_t *)
Copies a wasm_val_t to a new one.
uint32_t wasm_memory_pages_t
Unsigned integer to hold the number of pages a memory has.
Definition: wasm.h:490
wasm_func_t * wasm_extern_as_func(wasm_extern_t *)
Converts a wasm_extern_t to wasm_func_t.
wasm_globaltype_t * wasm_globaltype_new(wasm_valtype_t *, wasm_mutability_t)
Creates a new global type.
wasm_trap_t *(* wasm_func_callback_with_env_t)(void *env, const wasm_val_vec_t *args, wasm_val_vec_t *results)
Type definition for functions passed to wasm_func_new_with_env.
Definition: wasm.h:438
wasm_externtype_t * wasm_memorytype_as_externtype(wasm_memorytype_t *)
Converts a wasm_memorytype_t to a wasm_externtype_t.
bool wasm_table_set(wasm_table_t *, wasm_table_size_t index, wasm_ref_t *)
Sets an element in this table.
float float32_t
A type definition for a 32-bit float.
Definition: wasm.h:44
wasm_tagtype_t * wasm_externtype_as_tagtype(wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tagtype_t.
bool wasm_memory_grow(wasm_memory_t *, wasm_memory_pages_t delta)
Attempts to grow this memory by delta wasm pages.
const wasm_tagtype_t * wasm_externtype_as_tagtype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tagtype_t.
wasm_ref_t * wasm_table_get(const wasm_table_t *, wasm_table_size_t index)
Gets an element from this table.
wasm_store_t * wasm_store_new(wasm_engine_t *)
Creates a new store within the specified engine.
wasm_globaltype_t * wasm_global_type(const wasm_global_t *)
Returns the type of this global.
const wasm_name_t * wasm_importtype_module(const wasm_importtype_t *)
Returns the module this import is importing from.
wasm_tabletype_t * wasm_table_type(const wasm_table_t *)
Returns the type of this table.
bool wasm_module_validate(wasm_store_t *, const wasm_byte_vec_t *binary)
Validates whether a provided byte sequence is a valid wasm binary.
wasm_func_t * wasm_func_new(wasm_store_t *, const wasm_functype_t *, wasm_func_callback_t)
Creates a new WebAssembly function with host functionality.
const wasm_table_t * wasm_extern_as_table_const(const wasm_extern_t *)
Converts a wasm_extern_t to wasm_table_t.
wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t *)
Returns the kind of external item this type represents.
wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t *)
Returns whether or not a global is mutable.
wasm_extern_t * wasm_global_as_extern(wasm_global_t *)
Converts a wasm_global_t to wasm_extern_t.
wasm_functype_t * wasm_externtype_as_functype(wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_functype_t.
wasm_memory_pages_t wasm_memory_size(const wasm_memory_t *)
Returns the size, in wasm pages, of this memory.
void wasm_module_imports(const wasm_module_t *, wasm_importtype_vec_t *out)
Returns the list of imports that this module expects.
wasm_externtype_t * wasm_globaltype_as_externtype(wasm_globaltype_t *)
Converts a wasm_globaltype_t to a wasm_externtype_t.
const wasm_extern_t * wasm_global_as_extern_const(const wasm_global_t *)
Converts a wasm_global_t to wasm_extern_t.
const wasm_memorytype_t * wasm_externtype_as_memorytype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_memorytype_t.
#define wasm_name_new
Convenience alias.
Definition: wasm.h:107
const wasm_extern_t * wasm_func_as_extern_const(const wasm_func_t *)
Converts a wasm_func_t to wasm_extern_t.
wasm_memorytype_t * wasm_externtype_as_memorytype(wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_memorytype_t.
wasm_trap_t * wasm_func_call(const wasm_func_t *, const wasm_val_vec_t *args, wasm_val_vec_t *results)
Calls the provided function with the arguments given.
wasm_module_t * wasm_module_deserialize(wasm_store_t *, const wasm_byte_vec_t *)
Deserializes a previously-serialized module.
wasm_importtype_t * wasm_importtype_new(wasm_name_t *module, wasm_name_t *name, wasm_externtype_t *)
Creates a new import type.
wasm_global_t * wasm_extern_as_global(wasm_extern_t *)
Converts a wasm_extern_t to wasm_global_t.
wasm_foreign_t * wasm_foreign_new(wasm_store_t *)
Unimplemented in Wasmtime, aborts the process if called.
const wasm_externtype_t * wasm_globaltype_as_externtype_const(const wasm_globaltype_t *)
Converts a wasm_globaltype_t to a wasm_externtype_t.
wasm_engine_t * wasm_engine_new_with_config(wasm_config_t *)
Creates a new engine with the specified configuration.
size_t wasm_func_result_arity(const wasm_func_t *)
Returns the number of results returned by this function.
wasm_externtype_t * wasm_functype_as_externtype(wasm_functype_t *)
Converts a wasm_functype_t to a wasm_externtype_t.
wasm_functype_t * wasm_functype_new(wasm_valtype_vec_t *params, wasm_valtype_vec_t *results)
Creates a new function type with the provided parameter and result types.
wasm_globaltype_t * wasm_externtype_as_globaltype(wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_globaltype_t.
void wasm_val_delete(wasm_val_t *v)
Deletes a type.
wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t *)
Returns the associated kind for this value type.
wasm_memorytype_t * wasm_memorytype_new(const wasm_limits_t *)
Creates a new memory type.
double float64_t
A type definition for a 64-bit float.
Definition: wasm.h:45
const wasm_limits_t * wasm_tabletype_limits(const wasm_tabletype_t *)
Returns the limits of this table.
wasm_externtype_t * wasm_tabletype_as_externtype(wasm_tabletype_t *)
Converts a wasm_tabletype_t to a wasm_externtype_t.
uint8_t wasm_mutability_t
Boolean flag for whether a global is mutable or not.
Definition: wasm.h:158
wasm_valtype_t * wasm_valtype_new(wasm_valkind_t)
Creates a new value type from the specified kind.
wasm_frame_t * wasm_frame_copy(const wasm_frame_t *)
Returns a copy of the provided frame.
wasm_memory_t * wasm_extern_as_memory(wasm_extern_t *)
Converts a wasm_extern_t to wasm_memory_t.
byte_t wasm_byte_t
A type definition for a number that occupies a single byte of data.
Definition: wasm.h:101
void wasm_module_serialize(const wasm_module_t *, wasm_byte_vec_t *out)
Serializes the provided module to a byte vector.
wasm_extern_t * wasm_table_as_extern(wasm_table_t *)
Converts a wasm_table_t to wasm_extern_t.
const wasm_extern_t * wasm_table_as_extern_const(const wasm_table_t *)
Converts a wasm_table_t to wasm_extern_t.
wasm_externtype_t * wasm_extern_type(const wasm_extern_t *)
Returns the type of this extern.
wasm_functype_t * wasm_func_type(const wasm_func_t *)
Returns the type of this function.
byte_t * wasm_memory_data(wasm_memory_t *)
Returns the base address, in memory, where this memory is located.
const wasm_func_t * wasm_extern_as_func_const(const wasm_extern_t *)
Converts a wasm_extern_t to wasm_func_t.
const wasm_externtype_t * wasm_memorytype_as_externtype_const(const wasm_memorytype_t *)
Converts a wasm_memorytype_t to a wasm_externtype_t.
wasm_externtype_t * wasm_tagtype_as_externtype(wasm_tagtype_t *)
Converts a wasm_tagtype_t to a wasm_externtype_t.
void wasm_valtype_vec_new_empty(wasm_valtype_vec_t *out)
Creates an empty vector.
size_t wasm_frame_func_offset(const wasm_frame_t *)
Returns the byte offset from the beginning of the function in the original wasm file to the instructi...
wasm_table_t * wasm_table_new(wasm_store_t *, const wasm_tabletype_t *, wasm_ref_t *init)
Creates a new WebAssembly table.
const wasm_externtype_t * wasm_tagtype_as_externtype_const(const wasm_tagtype_t *)
Converts a wasm_tagtype_t to a wasm_externtype_t.