Wasmtime
wasm.h
Go to the documentation of this file.
1// WebAssembly C API
2
3#ifndef WASM_H
4#define WASM_H
5
6#include <stddef.h>
7#include <stdint.h>
8#include <stdbool.h>
9#include <string.h>
10#include <assert.h>
11
12#ifndef WASM_API_EXTERN
13#ifdef _WIN32
14#define WASM_API_EXTERN __declspec(dllimport)
15#else
16#define WASM_API_EXTERN
17#endif
18#endif
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
25// Auxiliaries
26
27// Machine types
28
29inline void assertions(void) {
30 static_assert(sizeof(float) == sizeof(uint32_t), "incompatible float type");
31 static_assert(sizeof(double) == sizeof(uint64_t), "incompatible double type");
32 static_assert(sizeof(intptr_t) == sizeof(uint32_t) ||
33 sizeof(intptr_t) == sizeof(uint64_t),
34 "incompatible pointer type");
35}
36
37typedef char byte_t;
38typedef float float32_t;
39typedef double float64_t;
40
41
42// Ownership
43
44#define own
45
46// The qualifier `own` is used to indicate ownership of data in this API.
47// It is intended to be interpreted similar to a `const` qualifier:
48//
49// - `own wasm_xxx_t*` owns the pointed-to data
50// - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx`
51// - `own wasm_xxx_vec_t` owns the vector as well as its elements(!)
52// - an `own` function parameter passes ownership from caller to callee
53// - an `own` function result passes ownership from callee to caller
54// - an exception are `own` pointer parameters named `out`, which are copy-back
55// output parameters passing back ownership from callee to caller
56//
57// Own data is created by `wasm_xxx_new` functions and some others.
58// It must be released with the corresponding `wasm_xxx_delete` function.
59//
60// Deleting a reference does not necessarily delete the underlying object,
61// it merely indicates that this owner no longer uses it.
62//
63// For vectors, `const wasm_xxx_vec_t` is used informally to indicate that
64// neither the vector nor its elements should be modified.
65// TODO: introduce proper `wasm_xxx_const_vec_t`?
66
67
68#define WASM_DECLARE_OWN(name) \
69 typedef struct wasm_##name##_t wasm_##name##_t; \
70 \
71 WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*);
72
73
74// Vectors
75
76#define WASM_DECLARE_VEC(name, ptr_or_none) \
77 typedef struct wasm_##name##_vec_t { \
78 size_t size; \
79 wasm_##name##_t ptr_or_none* data; \
80 } wasm_##name##_vec_t; \
81 \
82 WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \
83 WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \
84 own wasm_##name##_vec_t* out, size_t); \
85 WASM_API_EXTERN void wasm_##name##_vec_new( \
86 own wasm_##name##_vec_t* out, \
87 size_t, own wasm_##name##_t ptr_or_none const[]); \
88 WASM_API_EXTERN void wasm_##name##_vec_copy( \
89 own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \
90 WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*);
91
92
93// Byte vectors
94
96WASM_DECLARE_VEC(byte, )
97
99
100#define wasm_name wasm_byte_vec
101#define wasm_name_new wasm_byte_vec_new
102#define wasm_name_new_empty wasm_byte_vec_new_empty
103#define wasm_name_new_new_uninitialized wasm_byte_vec_new_uninitialized
104#define wasm_name_copy wasm_byte_vec_copy
105#define wasm_name_delete wasm_byte_vec_delete
106
107static inline void wasm_name_new_from_string(
108 own wasm_name_t* out, const char* s
109) {
110 wasm_name_new(out, strlen(s), s);
111}
112
113static inline void wasm_name_new_from_string_nt(
114 own wasm_name_t* out, const char* s
115) {
116 wasm_name_new(out, strlen(s) + 1, s);
117}
118
119
121// Runtime Environment
122
123// Configuration
124
125WASM_DECLARE_OWN(config)
126
127WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
128
129// Embedders may provide custom functions for manipulating configs.
130
131
132// Engine
133
134WASM_DECLARE_OWN(engine)
135
136WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
138
139
140// Store
141
142WASM_DECLARE_OWN(store)
143
145
146
148// Type Representations
149
150// Type attributes
151
152typedef uint8_t wasm_mutability_t;
153enum wasm_mutability_enum {
154 WASM_CONST,
155 WASM_VAR,
156};
157
158typedef struct wasm_limits_t {
159 uint32_t min;
160 uint32_t max;
162
163static const uint32_t wasm_limits_max_default = 0xffffffff;
164
165
166// Generic
167
168#define WASM_DECLARE_TYPE(name) \
169 WASM_DECLARE_OWN(name) \
170 WASM_DECLARE_VEC(name, *) \
171 \
172 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*);
173
174
175// Value Types
176
177WASM_DECLARE_TYPE(valtype)
178
179typedef uint8_t wasm_valkind_t;
180enum wasm_valkind_enum {
181 WASM_I32,
182 WASM_I64,
183 WASM_F32,
184 WASM_F64,
185 WASM_ANYREF = 128,
186 WASM_FUNCREF,
187};
188
190
192
193static inline bool wasm_valkind_is_num(wasm_valkind_t k) {
194 return k < WASM_ANYREF;
195}
196static inline bool wasm_valkind_is_ref(wasm_valkind_t k) {
197 return k >= WASM_ANYREF;
198}
199
200static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) {
201 return wasm_valkind_is_num(wasm_valtype_kind(t));
202}
203static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) {
204 return wasm_valkind_is_ref(wasm_valtype_kind(t));
205}
206
207
208// Function Types
209
210WASM_DECLARE_TYPE(functype)
211
213 own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results);
214
217
218
219// Global Types
220
221WASM_DECLARE_TYPE(globaltype)
222
225
228
229
230// Table Types
231
232WASM_DECLARE_TYPE(tabletype)
233
235 own wasm_valtype_t*, const wasm_limits_t*);
236
239
240
241// Memory Types
242
243WASM_DECLARE_TYPE(memorytype)
244
246
248
249
250// Extern Types
251
252WASM_DECLARE_TYPE(externtype)
253
254typedef uint8_t wasm_externkind_t;
255enum wasm_externkind_enum {
256 WASM_EXTERN_FUNC,
257 WASM_EXTERN_GLOBAL,
258 WASM_EXTERN_TABLE,
259 WASM_EXTERN_MEMORY,
260};
261
263
268
273
278
283
284
285// Import Types
286
287WASM_DECLARE_TYPE(importtype)
288
290 own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*);
291
295
296
297// Export Types
298
299WASM_DECLARE_TYPE(exporttype)
300
302 own wasm_name_t*, own wasm_externtype_t*);
303
306
307
309// Runtime Objects
310
311// Values
312
313struct wasm_ref_t;
314
315typedef struct wasm_val_t {
317 union {
318 int32_t i32;
319 int64_t i64;
320 float32_t f32;
321 float64_t f64;
322 struct wasm_ref_t* ref;
323 } of;
325
326WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
327WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);
328
329WASM_DECLARE_VEC(val, )
330
331
332// References
333
334#define WASM_DECLARE_REF_BASE(name) \
335 WASM_DECLARE_OWN(name) \
336 \
337 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
338 WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \
339 \
340 WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
341 WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
342 WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \
343 wasm_##name##_t*, void*, void (*)(void*));
344
345#define WASM_DECLARE_REF(name) \
346 WASM_DECLARE_REF_BASE(name) \
347 \
348 WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \
349 WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \
350 WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \
351 WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*);
352
353#define WASM_DECLARE_SHARABLE_REF(name) \
354 WASM_DECLARE_REF(name) \
355 WASM_DECLARE_OWN(shared_##name) \
356 \
357 WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \
358 WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*);
359
360
361WASM_DECLARE_REF_BASE(ref)
362
363
364// Frames
365
366WASM_DECLARE_OWN(frame)
367WASM_DECLARE_VEC(frame, *)
368WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*);
369
370WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*);
371WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*);
372WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*);
373WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*);
374
375
376// Traps
377
378typedef wasm_name_t wasm_message_t; // null terminated
379
380WASM_DECLARE_REF(trap)
381
382WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*);
383
384WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out);
385WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*);
386WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out);
387
388
389// Foreign Objects
390
391WASM_DECLARE_REF(foreign)
392
394
395
396// Modules
397
398WASM_DECLARE_SHARABLE_REF(module)
399
400WASM_API_EXTERN own wasm_module_t* wasm_module_new(
401 wasm_store_t*, const wasm_byte_vec_t* binary);
402
403WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary);
404
405WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out);
406WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out);
407
408WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out);
410
411
412// Function Instances
413
414WASM_DECLARE_REF(func)
415
417 const wasm_val_vec_t* args, own wasm_val_vec_t* results);
419 void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results);
420
421WASM_API_EXTERN own wasm_func_t* wasm_func_new(
425 void* env, void (*finalizer)(void*));
426
427WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*);
428WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*);
429WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*);
430
431WASM_API_EXTERN own wasm_trap_t* wasm_func_call(
432 const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results);
433
434
435// Global Instances
436
437WASM_DECLARE_REF(global)
438
439WASM_API_EXTERN own wasm_global_t* wasm_global_new(
440 wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*);
441
443
444WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out);
445WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*);
446
447
448// Table Instances
449
450WASM_DECLARE_REF(table)
451
452typedef uint32_t wasm_table_size_t;
453
454WASM_API_EXTERN own wasm_table_t* wasm_table_new(
456
457WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*);
458
459WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index);
461
463WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init);
464
465
466// Memory Instances
467
468WASM_DECLARE_REF(memory)
469
470typedef uint32_t wasm_memory_pages_t;
471
472static const size_t MEMORY_PAGE_SIZE = 0x10000;
473
475
477
479WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*);
480
483
484
485// Externals
486
487WASM_DECLARE_REF(extern)
488WASM_DECLARE_VEC(extern, *)
489
492
497
502
507
512
513
514// Module Instances
515
516WASM_DECLARE_REF(instance)
517
519 wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports,
520 own wasm_trap_t**
521);
522
523WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
524
525
527// Convenience
528
529// Vectors
530
531#define WASM_EMPTY_VEC {0, NULL}
532#define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array}
533
534
535// Value Type construction short-hands
536
537static inline own wasm_valtype_t* wasm_valtype_new_i32(void) {
538 return wasm_valtype_new(WASM_I32);
539}
540static inline own wasm_valtype_t* wasm_valtype_new_i64(void) {
541 return wasm_valtype_new(WASM_I64);
542}
543static inline own wasm_valtype_t* wasm_valtype_new_f32(void) {
544 return wasm_valtype_new(WASM_F32);
545}
546static inline own wasm_valtype_t* wasm_valtype_new_f64(void) {
547 return wasm_valtype_new(WASM_F64);
548}
549
550static inline own wasm_valtype_t* wasm_valtype_new_anyref(void) {
551 return wasm_valtype_new(WASM_ANYREF);
552}
553static inline own wasm_valtype_t* wasm_valtype_new_funcref(void) {
554 return wasm_valtype_new(WASM_FUNCREF);
555}
556
557
558// Function Types construction short-hands
559
560static inline own wasm_functype_t* wasm_functype_new_0_0(void) {
561 wasm_valtype_vec_t params, results;
564 return wasm_functype_new(&params, &results);
565}
566
567static inline own wasm_functype_t* wasm_functype_new_1_0(
568 own wasm_valtype_t* p
569) {
570 wasm_valtype_t* ps[1] = {p};
571 wasm_valtype_vec_t params, results;
572 wasm_valtype_vec_new(&params, 1, ps);
574 return wasm_functype_new(&params, &results);
575}
576
577static inline own wasm_functype_t* wasm_functype_new_2_0(
578 own wasm_valtype_t* p1, own wasm_valtype_t* p2
579) {
580 wasm_valtype_t* ps[2] = {p1, p2};
581 wasm_valtype_vec_t params, results;
582 wasm_valtype_vec_new(&params, 2, ps);
584 return wasm_functype_new(&params, &results);
585}
586
587static inline own wasm_functype_t* wasm_functype_new_3_0(
588 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3
589) {
590 wasm_valtype_t* ps[3] = {p1, p2, p3};
591 wasm_valtype_vec_t params, results;
592 wasm_valtype_vec_new(&params, 3, ps);
594 return wasm_functype_new(&params, &results);
595}
596
597static inline own wasm_functype_t* wasm_functype_new_0_1(
598 own wasm_valtype_t* r
599) {
600 wasm_valtype_t* rs[1] = {r};
601 wasm_valtype_vec_t params, results;
603 wasm_valtype_vec_new(&results, 1, rs);
604 return wasm_functype_new(&params, &results);
605}
606
607static inline own wasm_functype_t* wasm_functype_new_1_1(
608 own wasm_valtype_t* p, own wasm_valtype_t* r
609) {
610 wasm_valtype_t* ps[1] = {p};
611 wasm_valtype_t* rs[1] = {r};
612 wasm_valtype_vec_t params, results;
613 wasm_valtype_vec_new(&params, 1, ps);
614 wasm_valtype_vec_new(&results, 1, rs);
615 return wasm_functype_new(&params, &results);
616}
617
618static inline own wasm_functype_t* wasm_functype_new_2_1(
619 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r
620) {
621 wasm_valtype_t* ps[2] = {p1, p2};
622 wasm_valtype_t* rs[1] = {r};
623 wasm_valtype_vec_t params, results;
624 wasm_valtype_vec_new(&params, 2, ps);
625 wasm_valtype_vec_new(&results, 1, rs);
626 return wasm_functype_new(&params, &results);
627}
628
629static inline own wasm_functype_t* wasm_functype_new_3_1(
630 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
631 own wasm_valtype_t* r
632) {
633 wasm_valtype_t* ps[3] = {p1, p2, p3};
634 wasm_valtype_t* rs[1] = {r};
635 wasm_valtype_vec_t params, results;
636 wasm_valtype_vec_new(&params, 3, ps);
637 wasm_valtype_vec_new(&results, 1, rs);
638 return wasm_functype_new(&params, &results);
639}
640
641static inline own wasm_functype_t* wasm_functype_new_0_2(
642 own wasm_valtype_t* r1, own wasm_valtype_t* r2
643) {
644 wasm_valtype_t* rs[2] = {r1, r2};
645 wasm_valtype_vec_t params, results;
647 wasm_valtype_vec_new(&results, 2, rs);
648 return wasm_functype_new(&params, &results);
649}
650
651static inline own wasm_functype_t* wasm_functype_new_1_2(
652 own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2
653) {
654 wasm_valtype_t* ps[1] = {p};
655 wasm_valtype_t* rs[2] = {r1, r2};
656 wasm_valtype_vec_t params, results;
657 wasm_valtype_vec_new(&params, 1, ps);
658 wasm_valtype_vec_new(&results, 2, rs);
659 return wasm_functype_new(&params, &results);
660}
661
662static inline own wasm_functype_t* wasm_functype_new_2_2(
663 own wasm_valtype_t* p1, own wasm_valtype_t* p2,
664 own wasm_valtype_t* r1, own wasm_valtype_t* r2
665) {
666 wasm_valtype_t* ps[2] = {p1, p2};
667 wasm_valtype_t* rs[2] = {r1, r2};
668 wasm_valtype_vec_t params, results;
669 wasm_valtype_vec_new(&params, 2, ps);
670 wasm_valtype_vec_new(&results, 2, rs);
671 return wasm_functype_new(&params, &results);
672}
673
674static inline own wasm_functype_t* wasm_functype_new_3_2(
675 own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
676 own wasm_valtype_t* r1, own wasm_valtype_t* r2
677) {
678 wasm_valtype_t* ps[3] = {p1, p2, p3};
679 wasm_valtype_t* rs[2] = {r1, r2};
680 wasm_valtype_vec_t params, results;
681 wasm_valtype_vec_new(&params, 3, ps);
682 wasm_valtype_vec_new(&results, 2, rs);
683 return wasm_functype_new(&params, &results);
684}
685
686
687// Value construction short-hands
688
689static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) {
690#if UINTPTR_MAX == UINT32_MAX
691 out->kind = WASM_I32;
692 out->of.i32 = (intptr_t)p;
693#elif UINTPTR_MAX == UINT64_MAX
694 out->kind = WASM_I64;
695 out->of.i64 = (intptr_t)p;
696#endif
697}
698
699static inline void* wasm_val_ptr(const wasm_val_t* val) {
700#if UINTPTR_MAX == UINT32_MAX
701 return (void*)(intptr_t)val->of.i32;
702#elif UINTPTR_MAX == UINT64_MAX
703 return (void*)(intptr_t)val->of.i64;
704#endif
705}
706
707#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}}
708#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}}
709#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}}
710#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}}
711#define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .of = {.ref = r}}
712#define WASM_INIT_VAL {.kind = WASM_ANYREF, .of = {.ref = NULL}}
713
714
716
717#undef own
718
719#ifdef __cplusplus
720} // extern "C"
721#endif
722
723#endif // #ifdef WASM_H
A list of bytes.
Definition: wasm.h:96
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:299
Opaque struct representing a wasm external value.
A list of wasm_extern_t values.
Definition: wasm.h:488
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:367
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:287
Opaque struct representing a wasm instance.
Limits for tables/memories in wasm modules.
Definition: wasm.h:158
uint32_t min
Definition: wasm.h:159
uint32_t max
Definition: wasm.h:160
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:315
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:316
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:329
An object representing the type of a value.
A list of wasm_valtype_t values.
Definition: wasm.h:177
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:254
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:416
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:452
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:179
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:37
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:470
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:418
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:38
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:101
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:39
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:152
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:95
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.