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#[repr(C)]
520#[derive(Clone)]
521#[cfg(feature = "pooling-allocator")]
522pub struct wasmtime_pooling_allocation_config_t {
523    pub(crate) config: PoolingAllocationConfig,
524}
525
526#[unsafe(no_mangle)]
527#[cfg(feature = "pooling-allocator")]
528pub extern "C" fn wasmtime_pooling_allocation_config_new()
529-> Box<wasmtime_pooling_allocation_config_t> {
530    Box::new(wasmtime_pooling_allocation_config_t {
531        config: PoolingAllocationConfig::default(),
532    })
533}
534
535#[unsafe(no_mangle)]
536#[cfg(feature = "pooling-allocator")]
537pub extern "C" fn wasmtime_pooling_allocation_config_delete(
538    _: Box<wasmtime_pooling_allocation_config_t>,
539) {
540}
541
542#[unsafe(no_mangle)]
543#[cfg(feature = "pooling-allocator")]
544pub extern "C" fn wasmtime_pooling_allocation_config_max_unused_warm_slots_set(
545    c: &mut wasmtime_pooling_allocation_config_t,
546    max: u32,
547) {
548    c.config.max_unused_warm_slots(max);
549}
550
551#[unsafe(no_mangle)]
552#[cfg(feature = "pooling-allocator")]
553pub extern "C" fn wasmtime_pooling_allocation_config_decommit_batch_size_set(
554    c: &mut wasmtime_pooling_allocation_config_t,
555    batch_size: usize,
556) {
557    c.config.decommit_batch_size(batch_size);
558}
559
560#[unsafe(no_mangle)]
561#[cfg(all(feature = "pooling-allocator", feature = "async"))]
562pub extern "C" fn wasmtime_pooling_allocation_config_async_stack_keep_resident_set(
563    c: &mut wasmtime_pooling_allocation_config_t,
564    size: usize,
565) {
566    c.config.async_stack_keep_resident(size);
567}
568
569#[unsafe(no_mangle)]
570#[cfg(feature = "pooling-allocator")]
571pub extern "C" fn wasmtime_pooling_allocation_config_linear_memory_keep_resident_set(
572    c: &mut wasmtime_pooling_allocation_config_t,
573    size: usize,
574) {
575    c.config.linear_memory_keep_resident(size);
576}
577
578#[unsafe(no_mangle)]
579#[cfg(feature = "pooling-allocator")]
580pub extern "C" fn wasmtime_pooling_allocation_config_table_keep_resident_set(
581    c: &mut wasmtime_pooling_allocation_config_t,
582    size: usize,
583) {
584    c.config.table_keep_resident(size);
585}
586
587#[unsafe(no_mangle)]
588#[cfg(feature = "pooling-allocator")]
589pub extern "C" fn wasmtime_pooling_allocation_config_total_component_instances_set(
590    c: &mut wasmtime_pooling_allocation_config_t,
591    count: u32,
592) {
593    c.config.total_component_instances(count);
594}
595
596#[unsafe(no_mangle)]
597#[cfg(feature = "pooling-allocator")]
598pub extern "C" fn wasmtime_pooling_allocation_config_max_component_instance_size_set(
599    c: &mut wasmtime_pooling_allocation_config_t,
600    size: usize,
601) {
602    c.config.max_component_instance_size(size);
603}
604
605#[unsafe(no_mangle)]
606#[cfg(feature = "pooling-allocator")]
607pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instances_per_component_set(
608    c: &mut wasmtime_pooling_allocation_config_t,
609    count: u32,
610) {
611    c.config.max_core_instances_per_component(count);
612}
613
614#[unsafe(no_mangle)]
615#[cfg(feature = "pooling-allocator")]
616pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_component_set(
617    c: &mut wasmtime_pooling_allocation_config_t,
618    count: u32,
619) {
620    c.config.max_memories_per_component(count);
621}
622
623#[unsafe(no_mangle)]
624#[cfg(feature = "pooling-allocator")]
625pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_component_set(
626    c: &mut wasmtime_pooling_allocation_config_t,
627    count: u32,
628) {
629    c.config.max_tables_per_component(count);
630}
631
632#[unsafe(no_mangle)]
633#[cfg(feature = "pooling-allocator")]
634pub extern "C" fn wasmtime_pooling_allocation_config_total_memories_set(
635    c: &mut wasmtime_pooling_allocation_config_t,
636    count: u32,
637) {
638    c.config.total_memories(count);
639}
640
641#[unsafe(no_mangle)]
642#[cfg(feature = "pooling-allocator")]
643pub extern "C" fn wasmtime_pooling_allocation_config_total_tables_set(
644    c: &mut wasmtime_pooling_allocation_config_t,
645    count: u32,
646) {
647    c.config.total_tables(count);
648}
649
650#[unsafe(no_mangle)]
651#[cfg(all(feature = "pooling-allocator", feature = "async"))]
652pub extern "C" fn wasmtime_pooling_allocation_config_total_stacks_set(
653    c: &mut wasmtime_pooling_allocation_config_t,
654    count: u32,
655) {
656    c.config.total_stacks(count);
657}
658
659#[unsafe(no_mangle)]
660#[cfg(feature = "pooling-allocator")]
661pub extern "C" fn wasmtime_pooling_allocation_config_total_core_instances_set(
662    c: &mut wasmtime_pooling_allocation_config_t,
663    count: u32,
664) {
665    c.config.total_core_instances(count);
666}
667
668#[unsafe(no_mangle)]
669#[cfg(feature = "pooling-allocator")]
670pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instance_size_set(
671    c: &mut wasmtime_pooling_allocation_config_t,
672    size: usize,
673) {
674    c.config.max_core_instance_size(size);
675}
676
677#[unsafe(no_mangle)]
678#[cfg(feature = "pooling-allocator")]
679pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_module_set(
680    c: &mut wasmtime_pooling_allocation_config_t,
681    tables: u32,
682) {
683    c.config.max_tables_per_module(tables);
684}
685
686#[unsafe(no_mangle)]
687#[cfg(feature = "pooling-allocator")]
688pub extern "C" fn wasmtime_pooling_allocation_config_table_elements_set(
689    c: &mut wasmtime_pooling_allocation_config_t,
690    elements: usize,
691) {
692    c.config.table_elements(elements);
693}
694
695#[unsafe(no_mangle)]
696#[cfg(feature = "pooling-allocator")]
697pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_module_set(
698    c: &mut wasmtime_pooling_allocation_config_t,
699    memories: u32,
700) {
701    c.config.max_memories_per_module(memories);
702}
703
704#[unsafe(no_mangle)]
705#[cfg(feature = "pooling-allocator")]
706pub extern "C" fn wasmtime_pooling_allocation_config_max_memory_size_set(
707    c: &mut wasmtime_pooling_allocation_config_t,
708    bytes: usize,
709) {
710    c.config.max_memory_size(bytes);
711}
712
713#[unsafe(no_mangle)]
714#[cfg(all(feature = "pooling-allocator", feature = "gc"))]
715pub extern "C" fn wasmtime_pooling_allocation_config_total_gc_heaps_set(
716    c: &mut wasmtime_pooling_allocation_config_t,
717    count: u32,
718) {
719    c.config.total_gc_heaps(count);
720}
721
722#[unsafe(no_mangle)]
723#[cfg(feature = "pooling-allocator")]
724pub extern "C" fn wasmtime_pooling_allocation_strategy_set(
725    c: &mut wasm_config_t,
726    pc: &wasmtime_pooling_allocation_config_t,
727) {
728    c.config
729        .allocation_strategy(wasmtime::InstanceAllocationStrategy::Pooling(
730            pc.config.clone(),
731        ));
732}
733
734#[unsafe(no_mangle)]
735pub extern "C" fn wasmtime_config_concurrency_support_set(c: &mut wasm_config_t, enable: bool) {
736    c.config.concurrency_support(enable);
737}