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