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/2ce1367c9d1271c83fb63bef26d896a2f290cd23/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_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// Extern Types
257
258WASM_DECLARE_TYPE(externtype)
259
260typedef uint8_t wasm_externkind_t;
261enum wasm_externkind_enum {
262 WASM_EXTERN_FUNC,
263 WASM_EXTERN_GLOBAL,
264 WASM_EXTERN_TABLE,
265 WASM_EXTERN_MEMORY,
266};
267
269
274
279
284
289
290
291// Import Types
292
293WASM_DECLARE_TYPE(importtype)
294
296 own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*);
297
301
302
303// Export Types
304
305WASM_DECLARE_TYPE(exporttype)
306
308 own wasm_name_t*, own wasm_externtype_t*);
309
312
313
315// Runtime Objects
316
317// Values
318
319struct wasm_ref_t;
320
321typedef struct wasm_val_t {
323 union {
324 int32_t i32;
325 int64_t i64;
326 float32_t f32;
327 float64_t f64;
328 struct wasm_ref_t* ref;
329 } of;
331
332WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
333WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);
334
335WASM_DECLARE_VEC(val, )
336
337
338// References
339
340#define WASM_DECLARE_REF_BASE(name) \
341 WASM_DECLARE_OWN(name) \
342 \
343 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
344 WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \
345 \
346 WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
347 WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
348 WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \
349 wasm_##name##_t*, void*, void (*)(void*));
350
351#define WASM_DECLARE_REF(name) \
352 WASM_DECLARE_REF_BASE(name) \
353 \
354 WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \
355 WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \
356 WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \
357 WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*);
358
359#define WASM_DECLARE_SHARABLE_REF(name) \
360 WASM_DECLARE_REF(name) \
361 WASM_DECLARE_OWN(shared_##name) \
362 \
363 WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \
364 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*);
365
366
367WASM_DECLARE_REF_BASE(ref)
368
369
370// Frames
371
372WASM_DECLARE_OWN(frame)
373WASM_DECLARE_VEC(frame, *)
374WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*);
375
376WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*);
377WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*);
378WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*);
379WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*);
380
381
382// Traps
383
384typedef wasm_name_t wasm_message_t; // null terminated
385
386WASM_DECLARE_REF(trap)
387
388WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*);
389
390WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out);
391WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*);
392WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out);
393
394
395// Foreign Objects
396
397WASM_DECLARE_REF(foreign)
398
400
401
402// Modules
403
404WASM_DECLARE_SHARABLE_REF(module)
405
406WASM_API_EXTERN own wasm_module_t* wasm_module_new(
407 wasm_store_t*, const wasm_byte_vec_t* binary);
408
409WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary);
410
411WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out);
412WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out);
413
414WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out);
416
417
418// Function Instances
419
420WASM_DECLARE_REF(func)
421
423 const wasm_val_vec_t* args, own wasm_val_vec_t* results);
425 void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results);
426
427WASM_API_EXTERN own wasm_func_t* wasm_func_new(
431 void* env, void (*finalizer)(void*));
432
433WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*);
434WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*);
435WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*);
436
437WASM_API_EXTERN own wasm_trap_t* wasm_func_call(
438 const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results);
439
440
441// Global Instances
442
443WASM_DECLARE_REF(global)
444
445WASM_API_EXTERN own wasm_global_t* wasm_global_new(
446 wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*);
447
449
450WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out);
451WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*);
452
453
454// Table Instances
455
456WASM_DECLARE_REF(table)
457
458typedef uint32_t wasm_table_size_t;
459
460WASM_API_EXTERN own wasm_table_t* wasm_table_new(
462
463WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*);
464
465WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index);
467
469WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init);
470
471
472// Memory Instances
473
474WASM_DECLARE_REF(memory)
475
476typedef uint32_t wasm_memory_pages_t;
477
478static const size_t MEMORY_PAGE_SIZE = 0x10000;
479
481
483
485WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*);
486
489
490
491// Externals
492
493WASM_DECLARE_REF(extern)
494WASM_DECLARE_VEC(extern, *)
495
498
503
508
513
518
519
520// Module Instances
521
522WASM_DECLARE_REF(instance)
523
525 wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports,
526 own wasm_trap_t**
527);
528
529WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
530
531
533// Convenience
534
535// Vectors
536
537#define WASM_EMPTY_VEC {0, NULL}
538#define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array}
539
540
541// Value Type construction short-hands
542
543static inline own wasm_valtype_t* wasm_valtype_new_i32(void) {
544 return wasm_valtype_new(WASM_I32);
545}
546static inline own wasm_valtype_t* wasm_valtype_new_i64(void) {
547 return wasm_valtype_new(WASM_I64);
548}
549static inline own wasm_valtype_t* wasm_valtype_new_f32(void) {
550 return wasm_valtype_new(WASM_F32);
551}
552static inline own wasm_valtype_t* wasm_valtype_new_f64(void) {
553 return wasm_valtype_new(WASM_F64);
554}
555
556static inline own wasm_valtype_t* wasm_valtype_new_externref(void) {
557 return wasm_valtype_new(WASM_EXTERNREF);
558}
559static inline own wasm_valtype_t* wasm_valtype_new_funcref(void) {
560 return wasm_valtype_new(WASM_FUNCREF);
561}
562
563
564// Function Types construction short-hands
565
566static inline own wasm_functype_t* wasm_functype_new_0_0(void) {
567 wasm_valtype_vec_t params, results;
570 return wasm_functype_new(&params, &results);
571}
572
573static inline own wasm_functype_t* wasm_functype_new_1_0(
574 own wasm_valtype_t* p
575) {
576 wasm_valtype_t* ps[1] = {p};
577 wasm_valtype_vec_t params, results;
578 wasm_valtype_vec_new(&params, 1, ps);
580 return wasm_functype_new(&params, &results);
581}
582
583static inline own wasm_functype_t* wasm_functype_new_2_0(
584 own wasm_valtype_t* p1, own wasm_valtype_t* p2
585) {
586 wasm_valtype_t* ps[2] = {p1, p2};
587 wasm_valtype_vec_t params, results;
588 wasm_valtype_vec_new(&params, 2, ps);
590 return wasm_functype_new(&params, &results);
591}
592
593static inline own wasm_functype_t* wasm_functype_new_3_0(
594 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3
595) {
596 wasm_valtype_t* ps[3] = {p1, p2, p3};
597 wasm_valtype_vec_t params, results;
598 wasm_valtype_vec_new(&params, 3, ps);
600 return wasm_functype_new(&params, &results);
601}
602
603static inline own wasm_functype_t* wasm_functype_new_0_1(
604 own wasm_valtype_t* r
605) {
606 wasm_valtype_t* rs[1] = {r};
607 wasm_valtype_vec_t params, results;
609 wasm_valtype_vec_new(&results, 1, rs);
610 return wasm_functype_new(&params, &results);
611}
612
613static inline own wasm_functype_t* wasm_functype_new_1_1(
614 own wasm_valtype_t* p, own wasm_valtype_t* r
615) {
616 wasm_valtype_t* ps[1] = {p};
617 wasm_valtype_t* rs[1] = {r};
618 wasm_valtype_vec_t params, results;
619 wasm_valtype_vec_new(&params, 1, ps);
620 wasm_valtype_vec_new(&results, 1, rs);
621 return wasm_functype_new(&params, &results);
622}
623
624static inline own wasm_functype_t* wasm_functype_new_2_1(
625 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r
626) {
627 wasm_valtype_t* ps[2] = {p1, p2};
628 wasm_valtype_t* rs[1] = {r};
629 wasm_valtype_vec_t params, results;
630 wasm_valtype_vec_new(&params, 2, ps);
631 wasm_valtype_vec_new(&results, 1, rs);
632 return wasm_functype_new(&params, &results);
633}
634
635static inline own wasm_functype_t* wasm_functype_new_3_1(
636 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
637 own wasm_valtype_t* r
638) {
639 wasm_valtype_t* ps[3] = {p1, p2, p3};
640 wasm_valtype_t* rs[1] = {r};
641 wasm_valtype_vec_t params, results;
642 wasm_valtype_vec_new(&params, 3, ps);
643 wasm_valtype_vec_new(&results, 1, rs);
644 return wasm_functype_new(&params, &results);
645}
646
647static inline own wasm_functype_t* wasm_functype_new_0_2(
648 own wasm_valtype_t* r1, own wasm_valtype_t* r2
649) {
650 wasm_valtype_t* rs[2] = {r1, r2};
651 wasm_valtype_vec_t params, results;
653 wasm_valtype_vec_new(&results, 2, rs);
654 return wasm_functype_new(&params, &results);
655}
656
657static inline own wasm_functype_t* wasm_functype_new_1_2(
658 own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2
659) {
660 wasm_valtype_t* ps[1] = {p};
661 wasm_valtype_t* rs[2] = {r1, r2};
662 wasm_valtype_vec_t params, results;
663 wasm_valtype_vec_new(&params, 1, ps);
664 wasm_valtype_vec_new(&results, 2, rs);
665 return wasm_functype_new(&params, &results);
666}
667
668static inline own wasm_functype_t* wasm_functype_new_2_2(
669 own wasm_valtype_t* p1, own wasm_valtype_t* p2,
670 own wasm_valtype_t* r1, own wasm_valtype_t* r2
671) {
672 wasm_valtype_t* ps[2] = {p1, p2};
673 wasm_valtype_t* rs[2] = {r1, r2};
674 wasm_valtype_vec_t params, results;
675 wasm_valtype_vec_new(&params, 2, ps);
676 wasm_valtype_vec_new(&results, 2, rs);
677 return wasm_functype_new(&params, &results);
678}
679
680static inline own wasm_functype_t* wasm_functype_new_3_2(
681 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
682 own wasm_valtype_t* r1, own wasm_valtype_t* r2
683) {
684 wasm_valtype_t* ps[3] = {p1, p2, p3};
685 wasm_valtype_t* rs[2] = {r1, r2};
686 wasm_valtype_vec_t params, results;
687 wasm_valtype_vec_new(&params, 3, ps);
688 wasm_valtype_vec_new(&results, 2, rs);
689 return wasm_functype_new(&params, &results);
690}
691
692
693// Value construction short-hands
694
695static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) {
696#if UINTPTR_MAX == UINT32_MAX
697 out->kind = WASM_I32;
698 out->of.i32 = (intptr_t)p;
699#elif UINTPTR_MAX == UINT64_MAX
700 out->kind = WASM_I64;
701 out->of.i64 = (intptr_t)p;
702#endif
703}
704
705static inline void* wasm_val_ptr(const wasm_val_t* val) {
706#if UINTPTR_MAX == UINT32_MAX
707 return (void*)(intptr_t)val->of.i32;
708#elif UINTPTR_MAX == UINT64_MAX
709 return (void*)(intptr_t)val->of.i64;
710#endif
711}
712
713#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}}
714#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}}
715#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}}
716#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}}
717#define WASM_REF_VAL(r) {.kind = WASM_EXTERNREF, .of = {.ref = r}}
718#define WASM_INIT_VAL {.kind = WASM_EXTERNREF, .of = {.ref = NULL}}
719
720
722
723#undef own
724
725#ifdef __cplusplus
726} // extern "C"
727#endif
728
729#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:305
Opaque struct representing a wasm external value.
A list of wasm_extern_t values.
Definition: wasm.h:494
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:373
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:293
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.
Opaque struct representing a wasm trap.
Representation of a WebAssembly value.
Definition: wasm.h:321
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:322
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:335
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.
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:260
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:422
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:458
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:476
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:424
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
bool wasm_memory_grow(wasm_memory_t *, wasm_memory_pages_t delta)
Attempts to grow this memory by delta wasm pages.
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.
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.