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