wasmi_c_api/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use alloc::boxed::Box;
use wasmi::{CompilationMode, Config};

/// The Wasm configuration.
///
/// Wraps [`wasmi::Config`]
#[repr(C)]
#[derive(Clone)]
pub struct wasm_config_t {
    pub(crate) inner: Config,
}

wasmi_c_api_macros::declare_own!(wasm_config_t);

/// Creates a new default initialized [`wasm_config_t`].
///
/// The returned [`wasm_config_t`] must be freed using [`wasm_config_delete`]
/// or consumed by [`wasm_engine_new_with_config`].
///
/// Wraps [`wasmi::Config::default`].
///
/// [`wasm_engine_new_with_config`]: crate::wasm_engine_new_with_config
#[no_mangle]
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
    Box::new(wasm_config_t {
        inner: Config::default(),
    })
}

/// Enables or disables support for the Wasm [`mutable-global`] proposal.
///
/// Wraps [`wasmi::Config::wasm_multi_value`]
///
/// [`mutable-global`]: <https://github.com/WebAssembly/mutable-global>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_mutable_globals_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_mutable_global(enable);
}

/// Enables or disables support for the Wasm [`multi-value`] proposal.
///
/// Wraps [`wasmi::Config::wasm_multi_value`]
///
/// [`multi-value`]: <https://github.com/WebAssembly/multi-value>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_multi_value_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_multi_value(enable);
}

/// Enables or disables support for the Wasm [`sign-extension-ops`] proposal.
///
/// Wraps [`wasmi::Config::wasm_sign_extension`]
///
/// [`sign-extension-ops`]: <https://github.com/WebAssembly/sign-extension-ops>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_sign_extension_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_sign_extension(enable);
}

/// Enables or disables support for the Wasm [`nontrapping-float-to-int-conversions`] proposal.
///
/// Wraps [`wasmi::Config::wasm_saturating_float_to_int`]
///
/// [`nontrapping-float-to-int-conversions`]: <https://github.com/WebAssembly/nontrapping-float-to-int-conversions>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_saturating_float_to_int_set(
    c: &mut wasm_config_t,
    enable: bool,
) {
    c.inner.wasm_saturating_float_to_int(enable);
}

/// Enables or disables support for the Wasm [`bulk-memory-operations`] proposal.
///
/// Wraps [`wasmi::Config::wasm_bulk_memory`]
///
/// [`bulk-memory-operations`]: <https://github.com/WebAssembly/bulk-memory-operations>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_bulk_memory(enable);
}

/// Enables or disables support for the Wasm [`reference-types`] proposal.
///
/// Wraps [`wasmi::Config::wasm_reference_types`]
///
/// [`reference-types`]: <https://github.com/WebAssembly/reference-types>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_reference_types(enable);
}

/// Enables or disables support for the Wasm [`tail-call`] proposal.
///
/// Wraps [`wasmi::Config::wasm_tail_call`]
///
/// [`tail-call`]: <https://github.com/WebAssembly/tail-call>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_tail_call_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_tail_call(enable);
}

/// Enables or disables support for the Wasm [`extended-const`] proposal.
///
/// Wraps [`wasmi::Config::wasm_extended_const`]
///
/// [`extended-const`]: <https://github.com/WebAssembly/extended-const>
#[no_mangle]
pub extern "C" fn wasmi_config_wasm_extended_const_set(c: &mut wasm_config_t, enable: bool) {
    c.inner.wasm_extended_const(enable);
}

/// Enables or disables support for floating point numbers for the config.
///
/// Wraps [`wasmi::Config::floats`]
#[no_mangle]
pub extern "C" fn wasmi_config_floats_set(config: &mut wasm_config_t, enable: bool) {
    config.inner.floats(enable);
}

/// Enables or disables fuel consumption for the config.
///
/// Wraps [`wasmi::Config::consume_fuel`]
#[no_mangle]
pub extern "C" fn wasmi_config_consume_fuel_set(config: &mut wasm_config_t, enable: bool) {
    config.inner.consume_fuel(enable);
}

/// Compilation modes supported by the Wasmi execution engine.
///
/// Wraps [`wasmi::CompilationMode`]
#[repr(u8)]
#[derive(Clone)]
pub enum wasmi_compilation_mode_t {
    WASMI_COMPILATION_MODE_EAGER,
    WASMI_COMPILATION_MODE_LAZY_TRANSLATION,
    WASMI_COMPILATION_MODE_LAZY,
}

/// Sets the compilation mode for the config.
///
/// Wraps [`wasmi::Config::compilation_mode`]
#[no_mangle]
pub extern "C" fn wasmi_config_set_compilation_mode(
    config: &mut wasm_config_t,
    mode: wasmi_compilation_mode_t,
) {
    use wasmi_compilation_mode_t::*;
    config.inner.compilation_mode(match mode {
        WASMI_COMPILATION_MODE_EAGER => CompilationMode::Eager,
        WASMI_COMPILATION_MODE_LAZY_TRANSLATION => CompilationMode::LazyTranslation,
        WASMI_COMPILATION_MODE_LAZY => CompilationMode::Lazy,
    });
}

/// Enables or disables processing of Wasm custom sections.
///
/// Wraps [`wasmi::Config::ignore_custom_sections`]
#[no_mangle]
pub extern "C" fn wasmi_config_ignore_custom_sections_set(
    config: &mut wasm_config_t,
    enable: bool,
) {
    config.inner.ignore_custom_sections(enable);
}