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