Skip to main content

wasmtime_c_api/
config.rs

1// Don't worry about unused imports if we're frobbing features, only worry about
2// them with the default set of features enabled.
3#![cfg_attr(not(feature = "cache"), allow(unused_imports))]
4
5use crate::{handle_result, wasm_memorytype_t, wasmtime_error_t};
6use std::os::raw::c_char;
7use std::ptr;
8use std::{ffi::CStr, sync::Arc};
9use wasmtime::{
10    Config, LinearMemory, MemoryCreator, OptLevel, ProfilingStrategy, RegallocAlgorithm, Result,
11    Strategy,
12};
13
14#[cfg(feature = "pooling-allocator")]
15use wasmtime::PoolingAllocationConfig;
16
17#[repr(C)]
18#[derive(Clone)]
19pub struct wasm_config_t {
20    pub(crate) config: Config,
21}
22
23wasmtime_c_api_macros::declare_own!(wasm_config_t);
24
25#[repr(u8)]
26#[derive(Clone)]
27pub enum wasmtime_strategy_t {
28    WASMTIME_STRATEGY_AUTO,
29    WASMTIME_STRATEGY_CRANELIFT,
30    WASMTIME_STRATEGY_WINCH,
31}
32
33#[repr(u8)]
34#[derive(Clone)]
35pub enum wasmtime_opt_level_t {
36    WASMTIME_OPT_LEVEL_NONE,
37    WASMTIME_OPT_LEVEL_SPEED,
38    WASMTIME_OPT_LEVEL_SPEED_AND_SIZE,
39}
40
41#[repr(u8)]
42#[derive(Clone)]
43pub enum wasmtime_profiling_strategy_t {
44    WASMTIME_PROFILING_STRATEGY_NONE,
45    WASMTIME_PROFILING_STRATEGY_JITDUMP,
46    WASMTIME_PROFILING_STRATEGY_VTUNE,
47    WASMTIME_PROFILING_STRATEGY_PERFMAP,
48}
49
50#[repr(u8)]
51#[derive(Clone)]
52pub enum wasmtime_regalloc_algorithm_t {
53    WASMTIME_REGALLOC_BACKTRACKING,
54    WASMTIME_REGALLOC_SINGLE_PASS,
55}
56
57#[unsafe(no_mangle)]
58pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
59    Box::new(wasm_config_t {
60        config: Config::default(),
61    })
62}
63
64#[unsafe(no_mangle)]
65pub extern "C" fn wasmtime_config_debug_info_set(c: &mut wasm_config_t, enable: bool) {
66    c.config.debug_info(enable);
67}
68
69#[unsafe(no_mangle)]
70pub extern "C" fn wasmtime_config_consume_fuel_set(c: &mut wasm_config_t, enable: bool) {
71    c.config.consume_fuel(enable);
72}
73
74#[unsafe(no_mangle)]
75pub extern "C" fn wasmtime_config_epoch_interruption_set(c: &mut wasm_config_t, enable: bool) {
76    c.config.epoch_interruption(enable);
77}
78
79#[unsafe(no_mangle)]
80pub extern "C" fn wasmtime_config_max_wasm_stack_set(c: &mut wasm_config_t, size: usize) {
81    c.config.max_wasm_stack(size);
82}
83
84#[unsafe(no_mangle)]
85#[cfg(feature = "threads")]
86pub extern "C" fn wasmtime_config_wasm_threads_set(c: &mut wasm_config_t, enable: bool) {
87    c.config.wasm_threads(enable);
88}
89
90#[unsafe(no_mangle)]
91pub extern "C" fn wasmtime_config_shared_memory_set(c: &mut wasm_config_t, enable: bool) {
92    c.config.shared_memory(enable);
93}
94
95#[unsafe(no_mangle)]
96pub extern "C" fn wasmtime_config_wasm_tail_call_set(c: &mut wasm_config_t, enable: bool) {
97    c.config.wasm_tail_call(enable);
98}
99
100#[unsafe(no_mangle)]
101#[cfg(feature = "gc")]
102pub extern "C" fn wasmtime_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
103    c.config.wasm_reference_types(enable);
104}
105
106#[unsafe(no_mangle)]
107#[cfg(feature = "gc")]
108pub extern "C" fn wasmtime_config_wasm_function_references_set(
109    c: &mut wasm_config_t,
110    enable: bool,
111) {
112    c.config.wasm_function_references(enable);
113}
114
115#[unsafe(no_mangle)]
116#[cfg(feature = "gc")]
117pub extern "C" fn wasmtime_config_wasm_gc_set(c: &mut wasm_config_t, enable: bool) {
118    c.config.wasm_gc(enable);
119}
120
121#[unsafe(no_mangle)]
122pub extern "C" fn wasmtime_config_gc_support_set(c: &mut wasm_config_t, enable: bool) {
123    c.config.gc_support(enable);
124}
125
126#[unsafe(no_mangle)]
127pub extern "C" fn wasmtime_config_wasm_simd_set(c: &mut wasm_config_t, enable: bool) {
128    c.config.wasm_simd(enable);
129}
130
131#[unsafe(no_mangle)]
132pub extern "C" fn wasmtime_config_wasm_relaxed_simd_set(c: &mut wasm_config_t, enable: bool) {
133    c.config.wasm_relaxed_simd(enable);
134}
135
136#[unsafe(no_mangle)]
137pub extern "C" fn wasmtime_config_wasm_relaxed_simd_deterministic_set(
138    c: &mut wasm_config_t,
139    enable: bool,
140) {
141    c.config.relaxed_simd_deterministic(enable);
142}
143
144#[unsafe(no_mangle)]
145pub extern "C" fn wasmtime_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enable: bool) {
146    c.config.wasm_bulk_memory(enable);
147}
148
149#[unsafe(no_mangle)]
150pub extern "C" fn wasmtime_config_wasm_multi_value_set(c: &mut wasm_config_t, enable: bool) {
151    c.config.wasm_multi_value(enable);
152}
153
154#[unsafe(no_mangle)]
155pub extern "C" fn wasmtime_config_wasm_multi_memory_set(c: &mut wasm_config_t, enable: bool) {
156    c.config.wasm_multi_memory(enable);
157}
158
159#[unsafe(no_mangle)]
160pub extern "C" fn wasmtime_config_wasm_memory64_set(c: &mut wasm_config_t, enable: bool) {
161    c.config.wasm_memory64(enable);
162}
163
164#[unsafe(no_mangle)]
165pub extern "C" fn wasmtime_config_wasm_stack_switching_set(c: &mut wasm_config_t, enable: bool) {
166    c.config.wasm_stack_switching(enable);
167}
168
169#[unsafe(no_mangle)]
170#[cfg(any(feature = "cranelift", feature = "winch"))]
171pub extern "C" fn wasmtime_config_strategy_set(
172    c: &mut wasm_config_t,
173    strategy: wasmtime_strategy_t,
174) {
175    use wasmtime_strategy_t::*;
176    c.config.strategy(match strategy {
177        WASMTIME_STRATEGY_AUTO => Strategy::Auto,
178        WASMTIME_STRATEGY_CRANELIFT => Strategy::Cranelift,
179        WASMTIME_STRATEGY_WINCH => Strategy::Winch,
180    });
181}
182
183#[unsafe(no_mangle)]
184#[cfg(feature = "parallel-compilation")]
185pub extern "C" fn wasmtime_config_parallel_compilation_set(c: &mut wasm_config_t, enable: bool) {
186    c.config.parallel_compilation(enable);
187}
188
189#[unsafe(no_mangle)]
190#[cfg(any(feature = "cranelift", feature = "winch"))]
191pub extern "C" fn wasmtime_config_cranelift_debug_verifier_set(
192    c: &mut wasm_config_t,
193    enable: bool,
194) {
195    c.config.cranelift_debug_verifier(enable);
196}
197
198#[unsafe(no_mangle)]
199#[cfg(any(feature = "cranelift", feature = "winch"))]
200pub extern "C" fn wasmtime_config_cranelift_nan_canonicalization_set(
201    c: &mut wasm_config_t,
202    enable: bool,
203) {
204    c.config.cranelift_nan_canonicalization(enable);
205}
206
207#[unsafe(no_mangle)]
208#[cfg(any(feature = "cranelift", feature = "winch"))]
209pub extern "C" fn wasmtime_config_cranelift_opt_level_set(
210    c: &mut wasm_config_t,
211    opt_level: wasmtime_opt_level_t,
212) {
213    use wasmtime_opt_level_t::*;
214    c.config.cranelift_opt_level(match opt_level {
215        WASMTIME_OPT_LEVEL_NONE => OptLevel::None,
216        WASMTIME_OPT_LEVEL_SPEED => OptLevel::Speed,
217        WASMTIME_OPT_LEVEL_SPEED_AND_SIZE => OptLevel::SpeedAndSize,
218    });
219}
220
221#[unsafe(no_mangle)]
222#[cfg(any(feature = "cranelift", feature = "winch"))]
223pub extern "C" fn wasmtime_config_cranelift_regalloc_algorithm_set(
224    c: &mut wasm_config_t,
225    algo: wasmtime_regalloc_algorithm_t,
226) {
227    use wasmtime_regalloc_algorithm_t::*;
228    c.config.cranelift_regalloc_algorithm(match algo {
229        WASMTIME_REGALLOC_BACKTRACKING => RegallocAlgorithm::Backtracking,
230        WASMTIME_REGALLOC_SINGLE_PASS => RegallocAlgorithm::SinglePass,
231    });
232}
233
234#[unsafe(no_mangle)]
235pub extern "C" fn wasmtime_config_profiler_set(
236    c: &mut wasm_config_t,
237    strategy: wasmtime_profiling_strategy_t,
238) {
239    use wasmtime_profiling_strategy_t::*;
240    c.config.profiler(match strategy {
241        WASMTIME_PROFILING_STRATEGY_NONE => ProfilingStrategy::None,
242        WASMTIME_PROFILING_STRATEGY_JITDUMP => ProfilingStrategy::JitDump,
243        WASMTIME_PROFILING_STRATEGY_VTUNE => ProfilingStrategy::VTune,
244        WASMTIME_PROFILING_STRATEGY_PERFMAP => ProfilingStrategy::PerfMap,
245    });
246}
247
248#[unsafe(no_mangle)]
249#[cfg(feature = "cache")]
250pub unsafe extern "C" fn wasmtime_config_cache_config_load(
251    c: &mut wasm_config_t,
252    filename: *const c_char,
253) -> Option<Box<wasmtime_error_t>> {
254    use std::path::Path;
255
256    use wasmtime::Cache;
257
258    handle_result(
259        if filename.is_null() {
260            Cache::from_file(None).map(|cache| c.config.cache(Some(cache)))
261        } else {
262            match CStr::from_ptr(filename).to_str() {
263                Ok(s) => {
264                    Cache::from_file(Some(&Path::new(s))).map(|cache| c.config.cache(Some(cache)))
265                }
266                Err(e) => Err(e.into()),
267            }
268        },
269        |_cfg| {},
270    )
271}
272
273#[unsafe(no_mangle)]
274pub extern "C" fn wasmtime_config_memory_may_move_set(c: &mut wasm_config_t, enable: bool) {
275    c.config.memory_may_move(enable);
276}
277
278#[unsafe(no_mangle)]
279pub extern "C" fn wasmtime_config_memory_reservation_set(c: &mut wasm_config_t, size: u64) {
280    c.config.memory_reservation(size);
281}
282
283#[unsafe(no_mangle)]
284pub extern "C" fn wasmtime_config_memory_guard_size_set(c: &mut wasm_config_t, size: u64) {
285    c.config.memory_guard_size(size);
286}
287
288#[unsafe(no_mangle)]
289pub extern "C" fn wasmtime_config_memory_reservation_for_growth_set(
290    c: &mut wasm_config_t,
291    size: u64,
292) {
293    c.config.memory_reservation_for_growth(size);
294}
295
296#[unsafe(no_mangle)]
297pub extern "C" fn wasmtime_config_native_unwind_info_set(c: &mut wasm_config_t, enabled: bool) {
298    c.config.native_unwind_info(enabled);
299}
300
301#[unsafe(no_mangle)]
302pub unsafe extern "C" fn wasmtime_config_target_set(
303    c: &mut wasm_config_t,
304    target: *const c_char,
305) -> Option<Box<wasmtime_error_t>> {
306    let target = CStr::from_ptr(target).to_str().expect("not valid utf-8");
307    handle_result(c.config.target(target), |_cfg| {})
308}
309
310#[unsafe(no_mangle)]
311pub extern "C" fn wasmtime_config_macos_use_mach_ports_set(c: &mut wasm_config_t, enabled: bool) {
312    c.config.macos_use_mach_ports(enabled);
313}
314
315#[unsafe(no_mangle)]
316pub extern "C" fn wasmtime_config_signals_based_traps_set(c: &mut wasm_config_t, enable: bool) {
317    c.config.signals_based_traps(enable);
318}
319
320#[unsafe(no_mangle)]
321#[cfg(any(feature = "cranelift", feature = "winch"))]
322pub unsafe extern "C" fn wasmtime_config_cranelift_flag_enable(
323    c: &mut wasm_config_t,
324    flag: *const c_char,
325) {
326    let flag = CStr::from_ptr(flag).to_str().expect("not valid utf-8");
327    c.config.cranelift_flag_enable(flag);
328}
329
330#[unsafe(no_mangle)]
331#[cfg(any(feature = "cranelift", feature = "winch"))]
332pub unsafe extern "C" fn wasmtime_config_cranelift_flag_set(
333    c: &mut wasm_config_t,
334    flag: *const c_char,
335    value: *const c_char,
336) {
337    let flag = CStr::from_ptr(flag).to_str().expect("not valid utf-8");
338    let value = CStr::from_ptr(value).to_str().expect("not valid utf-8");
339    c.config.cranelift_flag_set(flag, value);
340}
341
342pub type wasmtime_memory_get_callback_t = extern "C" fn(
343    env: *mut std::ffi::c_void,
344    byte_size: &mut usize,
345    maximum_byte_size: &mut usize,
346) -> *mut u8;
347
348pub type wasmtime_memory_grow_callback_t =
349    extern "C" fn(env: *mut std::ffi::c_void, new_size: usize) -> Option<Box<wasmtime_error_t>>;
350
351#[repr(C)]
352pub struct wasmtime_linear_memory_t {
353    env: *mut std::ffi::c_void,
354    get_memory: wasmtime_memory_get_callback_t,
355    grow_memory: wasmtime_memory_grow_callback_t,
356    finalizer: Option<extern "C" fn(arg1: *mut std::ffi::c_void)>,
357}
358
359pub type wasmtime_new_memory_callback_t = extern "C" fn(
360    env: *mut std::ffi::c_void,
361    ty: &wasm_memorytype_t,
362    minimum: usize,
363    maximum: usize,
364    reserved_size_in_bytes: usize,
365    guard_size_in_bytes: usize,
366    memory_ret: *mut wasmtime_linear_memory_t,
367) -> Option<Box<wasmtime_error_t>>;
368
369struct CHostLinearMemory {
370    foreign: crate::ForeignData,
371    get_memory: wasmtime_memory_get_callback_t,
372    grow_memory: wasmtime_memory_grow_callback_t,
373}
374
375unsafe impl LinearMemory for CHostLinearMemory {
376    fn byte_size(&self) -> usize {
377        let mut byte_size = 0;
378        let mut byte_capacity = 0;
379        let cb = self.get_memory;
380        cb(self.foreign.data, &mut byte_size, &mut byte_capacity);
381        return byte_size;
382    }
383    fn byte_capacity(&self) -> usize {
384        let mut byte_size = 0;
385        let mut byte_capacity = 0;
386        let cb = self.get_memory;
387        cb(self.foreign.data, &mut byte_size, &mut byte_capacity);
388        byte_capacity
389    }
390    fn as_ptr(&self) -> *mut u8 {
391        let mut byte_size = 0;
392        let mut byte_capacity = 0;
393        let cb = self.get_memory;
394        cb(self.foreign.data, &mut byte_size, &mut byte_capacity)
395    }
396    fn grow_to(&mut self, new_size: usize) -> Result<()> {
397        let cb = self.grow_memory;
398        let error = cb(self.foreign.data, new_size);
399        if let Some(err) = error {
400            Err((*err).into())
401        } else {
402            Ok(())
403        }
404    }
405}
406
407#[repr(C)]
408pub struct wasmtime_memory_creator_t {
409    env: *mut std::ffi::c_void,
410    new_memory: wasmtime_new_memory_callback_t,
411    finalizer: Option<extern "C" fn(arg1: *mut std::ffi::c_void)>,
412}
413
414struct CHostMemoryCreator {
415    foreign: crate::ForeignData,
416    new_memory: wasmtime_new_memory_callback_t,
417}
418unsafe impl Send for CHostMemoryCreator {}
419unsafe impl Sync for CHostMemoryCreator {}
420
421unsafe impl MemoryCreator for CHostMemoryCreator {
422    fn new_memory(
423        &self,
424        ty: wasmtime::MemoryType,
425        minimum: usize,
426        maximum: Option<usize>,
427        reserved_size_in_bytes: Option<usize>,
428        guard_size_in_bytes: usize,
429    ) -> Result<Box<dyn wasmtime::LinearMemory>, String> {
430        extern "C" fn panic_get_callback(
431            _env: *mut std::ffi::c_void,
432            _byte_size: &mut usize,
433            _maximum_byte_size: &mut usize,
434        ) -> *mut u8 {
435            panic!("a callback must be set");
436        }
437        extern "C" fn panic_grow_callback(
438            _env: *mut std::ffi::c_void,
439            _size: usize,
440        ) -> Option<Box<wasmtime_error_t>> {
441            panic!("a callback must be set");
442        }
443        let mut memory = wasmtime_linear_memory_t {
444            env: ptr::null_mut(),
445            get_memory: panic_get_callback,
446            grow_memory: panic_grow_callback,
447            finalizer: None,
448        };
449        let cb = self.new_memory;
450        let error = cb(
451            self.foreign.data,
452            &wasm_memorytype_t::new(ty),
453            minimum,
454            maximum.unwrap_or(usize::MAX),
455            reserved_size_in_bytes.unwrap_or(0),
456            guard_size_in_bytes,
457            &mut memory,
458        );
459        match error {
460            None => {
461                let foreign = crate::ForeignData {
462                    data: memory.env,
463                    finalizer: memory.finalizer,
464                };
465                Ok(Box::new(CHostLinearMemory {
466                    foreign,
467                    get_memory: memory.get_memory,
468                    grow_memory: memory.grow_memory,
469                }))
470            }
471            Some(err) => {
472                let err: wasmtime::Error = (*err).into();
473                Err(format!("{err}"))
474            }
475        }
476    }
477}
478
479#[unsafe(no_mangle)]
480pub unsafe extern "C" fn wasmtime_config_host_memory_creator_set(
481    c: &mut wasm_config_t,
482    creator: &wasmtime_memory_creator_t,
483) {
484    c.config.with_host_memory(Arc::new(CHostMemoryCreator {
485        foreign: crate::ForeignData {
486            data: creator.env,
487            finalizer: creator.finalizer,
488        },
489        new_memory: creator.new_memory,
490    }));
491}
492
493#[unsafe(no_mangle)]
494pub extern "C" fn wasmtime_config_memory_init_cow_set(c: &mut wasm_config_t, enable: bool) {
495    c.config.memory_init_cow(enable);
496}
497
498#[unsafe(no_mangle)]
499pub extern "C" fn wasmtime_config_wasm_wide_arithmetic_set(c: &mut wasm_config_t, enable: bool) {
500    c.config.wasm_wide_arithmetic(enable);
501}
502
503#[unsafe(no_mangle)]
504pub extern "C" fn wasmtime_config_wasm_branch_hinting_set(c: &mut wasm_config_t, enable: bool) {
505    c.config.wasm_branch_hinting(enable);
506}
507
508#[unsafe(no_mangle)]
509#[cfg(feature = "gc")]
510pub extern "C" fn wasmtime_config_wasm_exceptions_set(c: &mut wasm_config_t, enable: bool) {
511    c.config.wasm_exceptions(enable);
512}
513
514#[unsafe(no_mangle)]
515pub extern "C" fn wasmtime_config_wasm_custom_page_sizes_set(c: &mut wasm_config_t, enable: bool) {
516    c.config.wasm_custom_page_sizes(enable);
517}
518
519#[unsafe(no_mangle)]
520pub extern "C" fn wasmtime_config_wasm_compact_imports_set(c: &mut wasm_config_t, enable: bool) {
521    c.config.wasm_compact_imports(enable);
522}
523
524#[repr(C)]
525#[derive(Clone)]
526#[cfg(feature = "pooling-allocator")]
527pub struct wasmtime_pooling_allocation_config_t {
528    pub(crate) config: PoolingAllocationConfig,
529}
530
531#[unsafe(no_mangle)]
532#[cfg(feature = "pooling-allocator")]
533pub extern "C" fn wasmtime_pooling_allocation_config_new()
534-> Box<wasmtime_pooling_allocation_config_t> {
535    Box::new(wasmtime_pooling_allocation_config_t {
536        config: PoolingAllocationConfig::default(),
537    })
538}
539
540#[unsafe(no_mangle)]
541#[cfg(feature = "pooling-allocator")]
542pub extern "C" fn wasmtime_pooling_allocation_config_delete(
543    _: Box<wasmtime_pooling_allocation_config_t>,
544) {
545}
546
547#[unsafe(no_mangle)]
548#[cfg(feature = "pooling-allocator")]
549pub extern "C" fn wasmtime_pooling_allocation_config_max_unused_warm_slots_set(
550    c: &mut wasmtime_pooling_allocation_config_t,
551    max: u32,
552) {
553    c.config.max_unused_warm_slots(max);
554}
555
556#[unsafe(no_mangle)]
557#[cfg(feature = "pooling-allocator")]
558pub extern "C" fn wasmtime_pooling_allocation_config_decommit_batch_size_set(
559    c: &mut wasmtime_pooling_allocation_config_t,
560    batch_size: usize,
561) {
562    c.config.decommit_batch_size(batch_size);
563}
564
565#[unsafe(no_mangle)]
566#[cfg(all(feature = "pooling-allocator", feature = "async"))]
567pub extern "C" fn wasmtime_pooling_allocation_config_async_stack_keep_resident_set(
568    c: &mut wasmtime_pooling_allocation_config_t,
569    size: usize,
570) {
571    c.config.async_stack_keep_resident(size);
572}
573
574#[unsafe(no_mangle)]
575#[cfg(feature = "pooling-allocator")]
576pub extern "C" fn wasmtime_pooling_allocation_config_linear_memory_keep_resident_set(
577    c: &mut wasmtime_pooling_allocation_config_t,
578    size: usize,
579) {
580    c.config.linear_memory_keep_resident(size);
581}
582
583#[unsafe(no_mangle)]
584#[cfg(feature = "pooling-allocator")]
585pub extern "C" fn wasmtime_pooling_allocation_config_table_keep_resident_set(
586    c: &mut wasmtime_pooling_allocation_config_t,
587    size: usize,
588) {
589    c.config.table_keep_resident(size);
590}
591
592#[unsafe(no_mangle)]
593#[cfg(feature = "pooling-allocator")]
594pub extern "C" fn wasmtime_pooling_allocation_config_total_component_instances_set(
595    c: &mut wasmtime_pooling_allocation_config_t,
596    count: u32,
597) {
598    c.config.total_component_instances(count);
599}
600
601#[unsafe(no_mangle)]
602#[cfg(feature = "pooling-allocator")]
603pub extern "C" fn wasmtime_pooling_allocation_config_max_component_instance_size_set(
604    c: &mut wasmtime_pooling_allocation_config_t,
605    size: usize,
606) {
607    c.config.max_component_instance_size(size);
608}
609
610#[unsafe(no_mangle)]
611#[cfg(feature = "pooling-allocator")]
612pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instances_per_component_set(
613    c: &mut wasmtime_pooling_allocation_config_t,
614    count: u32,
615) {
616    c.config.max_core_instances_per_component(count);
617}
618
619#[unsafe(no_mangle)]
620#[cfg(feature = "pooling-allocator")]
621pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_component_set(
622    c: &mut wasmtime_pooling_allocation_config_t,
623    count: u32,
624) {
625    c.config.max_memories_per_component(count);
626}
627
628#[unsafe(no_mangle)]
629#[cfg(feature = "pooling-allocator")]
630pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_component_set(
631    c: &mut wasmtime_pooling_allocation_config_t,
632    count: u32,
633) {
634    c.config.max_tables_per_component(count);
635}
636
637#[unsafe(no_mangle)]
638#[cfg(feature = "pooling-allocator")]
639pub extern "C" fn wasmtime_pooling_allocation_config_total_memories_set(
640    c: &mut wasmtime_pooling_allocation_config_t,
641    count: u32,
642) {
643    c.config.total_memories(count);
644}
645
646#[unsafe(no_mangle)]
647#[cfg(feature = "pooling-allocator")]
648pub extern "C" fn wasmtime_pooling_allocation_config_total_tables_set(
649    c: &mut wasmtime_pooling_allocation_config_t,
650    count: u32,
651) {
652    c.config.total_tables(count);
653}
654
655#[unsafe(no_mangle)]
656#[cfg(all(feature = "pooling-allocator", feature = "async"))]
657pub extern "C" fn wasmtime_pooling_allocation_config_total_stacks_set(
658    c: &mut wasmtime_pooling_allocation_config_t,
659    count: u32,
660) {
661    c.config.total_stacks(count);
662}
663
664#[unsafe(no_mangle)]
665#[cfg(feature = "pooling-allocator")]
666pub extern "C" fn wasmtime_pooling_allocation_config_total_core_instances_set(
667    c: &mut wasmtime_pooling_allocation_config_t,
668    count: u32,
669) {
670    c.config.total_core_instances(count);
671}
672
673#[unsafe(no_mangle)]
674#[cfg(feature = "pooling-allocator")]
675pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instance_size_set(
676    c: &mut wasmtime_pooling_allocation_config_t,
677    size: usize,
678) {
679    c.config.max_core_instance_size(size);
680}
681
682#[unsafe(no_mangle)]
683#[cfg(feature = "pooling-allocator")]
684pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_module_set(
685    c: &mut wasmtime_pooling_allocation_config_t,
686    tables: u32,
687) {
688    c.config.max_tables_per_module(tables);
689}
690
691#[unsafe(no_mangle)]
692#[cfg(feature = "pooling-allocator")]
693pub extern "C" fn wasmtime_pooling_allocation_config_table_elements_set(
694    c: &mut wasmtime_pooling_allocation_config_t,
695    elements: usize,
696) {
697    c.config.table_elements(elements);
698}
699
700#[unsafe(no_mangle)]
701#[cfg(feature = "pooling-allocator")]
702pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_module_set(
703    c: &mut wasmtime_pooling_allocation_config_t,
704    memories: u32,
705) {
706    c.config.max_memories_per_module(memories);
707}
708
709#[unsafe(no_mangle)]
710#[cfg(feature = "pooling-allocator")]
711pub extern "C" fn wasmtime_pooling_allocation_config_max_memory_size_set(
712    c: &mut wasmtime_pooling_allocation_config_t,
713    bytes: usize,
714) {
715    c.config.max_memory_size(bytes);
716}
717
718#[unsafe(no_mangle)]
719#[cfg(all(feature = "pooling-allocator", feature = "gc"))]
720pub extern "C" fn wasmtime_pooling_allocation_config_total_gc_heaps_set(
721    c: &mut wasmtime_pooling_allocation_config_t,
722    count: u32,
723) {
724    c.config.total_gc_heaps(count);
725}
726
727#[unsafe(no_mangle)]
728#[cfg(feature = "pooling-allocator")]
729pub extern "C" fn wasmtime_pooling_allocation_strategy_set(
730    c: &mut wasm_config_t,
731    pc: &wasmtime_pooling_allocation_config_t,
732) {
733    c.config
734        .allocation_strategy(wasmtime::InstanceAllocationStrategy::Pooling(
735            pc.config.clone(),
736        ));
737}
738
739#[unsafe(no_mangle)]
740pub extern "C" fn wasmtime_config_concurrency_support_set(c: &mut wasm_config_t, enable: bool) {
741    c.config.concurrency_support(enable);
742}