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 extern "C" fn wasmtime_config_asan_compatible_code_set(c: &mut wasm_config_t, enabled: bool) {
303 c.config.asan_compatible_code(enabled);
304}
305
306#[unsafe(no_mangle)]
307pub unsafe extern "C" fn wasmtime_config_target_set(
308 c: &mut wasm_config_t,
309 target: *const c_char,
310) -> Option<Box<wasmtime_error_t>> {
311 let target = CStr::from_ptr(target).to_str().expect("not valid utf-8");
312 handle_result(c.config.target(target), |_cfg| {})
313}
314
315#[unsafe(no_mangle)]
316pub extern "C" fn wasmtime_config_macos_use_mach_ports_set(c: &mut wasm_config_t, enabled: bool) {
317 c.config.macos_use_mach_ports(enabled);
318}
319
320#[unsafe(no_mangle)]
321pub extern "C" fn wasmtime_config_signals_based_traps_set(c: &mut wasm_config_t, enable: bool) {
322 c.config.signals_based_traps(enable);
323}
324
325#[unsafe(no_mangle)]
326#[cfg(any(feature = "cranelift", feature = "winch"))]
327pub unsafe extern "C" fn wasmtime_config_cranelift_flag_enable(
328 c: &mut wasm_config_t,
329 flag: *const c_char,
330) {
331 let flag = CStr::from_ptr(flag).to_str().expect("not valid utf-8");
332 c.config.cranelift_flag_enable(flag);
333}
334
335#[unsafe(no_mangle)]
336#[cfg(any(feature = "cranelift", feature = "winch"))]
337pub unsafe extern "C" fn wasmtime_config_cranelift_flag_set(
338 c: &mut wasm_config_t,
339 flag: *const c_char,
340 value: *const c_char,
341) {
342 let flag = CStr::from_ptr(flag).to_str().expect("not valid utf-8");
343 let value = CStr::from_ptr(value).to_str().expect("not valid utf-8");
344 c.config.cranelift_flag_set(flag, value);
345}
346
347pub type wasmtime_memory_get_callback_t = extern "C" fn(
348 env: *mut std::ffi::c_void,
349 byte_size: &mut usize,
350 maximum_byte_size: &mut usize,
351) -> *mut u8;
352
353pub type wasmtime_memory_grow_callback_t =
354 extern "C" fn(env: *mut std::ffi::c_void, new_size: usize) -> Option<Box<wasmtime_error_t>>;
355
356#[repr(C)]
357pub struct wasmtime_linear_memory_t {
358 env: *mut std::ffi::c_void,
359 get_memory: wasmtime_memory_get_callback_t,
360 grow_memory: wasmtime_memory_grow_callback_t,
361 finalizer: Option<extern "C" fn(arg1: *mut std::ffi::c_void)>,
362}
363
364pub type wasmtime_new_memory_callback_t = extern "C" fn(
365 env: *mut std::ffi::c_void,
366 ty: &wasm_memorytype_t,
367 minimum: usize,
368 maximum: usize,
369 reserved_size_in_bytes: usize,
370 guard_size_in_bytes: usize,
371 memory_ret: *mut wasmtime_linear_memory_t,
372) -> Option<Box<wasmtime_error_t>>;
373
374struct CHostLinearMemory {
375 foreign: crate::ForeignData,
376 get_memory: wasmtime_memory_get_callback_t,
377 grow_memory: wasmtime_memory_grow_callback_t,
378}
379
380unsafe impl LinearMemory for CHostLinearMemory {
381 fn byte_size(&self) -> usize {
382 let mut byte_size = 0;
383 let mut byte_capacity = 0;
384 let cb = self.get_memory;
385 cb(self.foreign.data, &mut byte_size, &mut byte_capacity);
386 return byte_size;
387 }
388 fn byte_capacity(&self) -> usize {
389 let mut byte_size = 0;
390 let mut byte_capacity = 0;
391 let cb = self.get_memory;
392 cb(self.foreign.data, &mut byte_size, &mut byte_capacity);
393 byte_capacity
394 }
395 fn as_ptr(&self) -> *mut u8 {
396 let mut byte_size = 0;
397 let mut byte_capacity = 0;
398 let cb = self.get_memory;
399 cb(self.foreign.data, &mut byte_size, &mut byte_capacity)
400 }
401 fn grow_to(&mut self, new_size: usize) -> Result<()> {
402 let cb = self.grow_memory;
403 let error = cb(self.foreign.data, new_size);
404 if let Some(err) = error {
405 Err((*err).into())
406 } else {
407 Ok(())
408 }
409 }
410}
411
412#[repr(C)]
413pub struct wasmtime_memory_creator_t {
414 env: *mut std::ffi::c_void,
415 new_memory: wasmtime_new_memory_callback_t,
416 finalizer: Option<extern "C" fn(arg1: *mut std::ffi::c_void)>,
417}
418
419struct CHostMemoryCreator {
420 foreign: crate::ForeignData,
421 new_memory: wasmtime_new_memory_callback_t,
422}
423unsafe impl Send for CHostMemoryCreator {}
424unsafe impl Sync for CHostMemoryCreator {}
425
426unsafe impl MemoryCreator for CHostMemoryCreator {
427 fn new_memory(
428 &self,
429 ty: wasmtime::MemoryType,
430 minimum: usize,
431 maximum: Option<usize>,
432 reserved_size_in_bytes: Option<usize>,
433 guard_size_in_bytes: usize,
434 ) -> Result<Box<dyn wasmtime::LinearMemory>, String> {
435 extern "C" fn panic_get_callback(
436 _env: *mut std::ffi::c_void,
437 _byte_size: &mut usize,
438 _maximum_byte_size: &mut usize,
439 ) -> *mut u8 {
440 panic!("a callback must be set");
441 }
442 extern "C" fn panic_grow_callback(
443 _env: *mut std::ffi::c_void,
444 _size: usize,
445 ) -> Option<Box<wasmtime_error_t>> {
446 panic!("a callback must be set");
447 }
448 let mut memory = wasmtime_linear_memory_t {
449 env: ptr::null_mut(),
450 get_memory: panic_get_callback,
451 grow_memory: panic_grow_callback,
452 finalizer: None,
453 };
454 let cb = self.new_memory;
455 let error = cb(
456 self.foreign.data,
457 &wasm_memorytype_t::new(ty),
458 minimum,
459 maximum.unwrap_or(usize::MAX),
460 reserved_size_in_bytes.unwrap_or(0),
461 guard_size_in_bytes,
462 &mut memory,
463 );
464 match error {
465 None => {
466 let foreign = crate::ForeignData {
467 data: memory.env,
468 finalizer: memory.finalizer,
469 };
470 Ok(Box::new(CHostLinearMemory {
471 foreign,
472 get_memory: memory.get_memory,
473 grow_memory: memory.grow_memory,
474 }))
475 }
476 Some(err) => {
477 let err: wasmtime::Error = (*err).into();
478 Err(format!("{err}"))
479 }
480 }
481 }
482}
483
484#[unsafe(no_mangle)]
485pub unsafe extern "C" fn wasmtime_config_host_memory_creator_set(
486 c: &mut wasm_config_t,
487 creator: &wasmtime_memory_creator_t,
488) {
489 c.config.with_host_memory(Arc::new(CHostMemoryCreator {
490 foreign: crate::ForeignData {
491 data: creator.env,
492 finalizer: creator.finalizer,
493 },
494 new_memory: creator.new_memory,
495 }));
496}
497
498#[unsafe(no_mangle)]
499pub extern "C" fn wasmtime_config_memory_init_cow_set(c: &mut wasm_config_t, enable: bool) {
500 c.config.memory_init_cow(enable);
501}
502
503#[unsafe(no_mangle)]
504pub extern "C" fn wasmtime_config_wasm_wide_arithmetic_set(c: &mut wasm_config_t, enable: bool) {
505 c.config.wasm_wide_arithmetic(enable);
506}
507
508#[unsafe(no_mangle)]
509pub extern "C" fn wasmtime_config_wasm_branch_hinting_set(c: &mut wasm_config_t, enable: bool) {
510 c.config.wasm_branch_hinting(enable);
511}
512
513#[unsafe(no_mangle)]
514#[cfg(feature = "gc")]
515pub extern "C" fn wasmtime_config_wasm_exceptions_set(c: &mut wasm_config_t, enable: bool) {
516 c.config.wasm_exceptions(enable);
517}
518
519#[unsafe(no_mangle)]
520pub extern "C" fn wasmtime_config_wasm_custom_page_sizes_set(c: &mut wasm_config_t, enable: bool) {
521 c.config.wasm_custom_page_sizes(enable);
522}
523
524#[unsafe(no_mangle)]
525pub extern "C" fn wasmtime_config_wasm_compact_imports_set(c: &mut wasm_config_t, enable: bool) {
526 c.config.wasm_compact_imports(enable);
527}
528
529#[repr(C)]
530#[derive(Clone)]
531#[cfg(feature = "pooling-allocator")]
532pub struct wasmtime_pooling_allocation_config_t {
533 pub(crate) config: PoolingAllocationConfig,
534}
535
536#[unsafe(no_mangle)]
537#[cfg(feature = "pooling-allocator")]
538pub extern "C" fn wasmtime_pooling_allocation_config_new()
539-> Box<wasmtime_pooling_allocation_config_t> {
540 Box::new(wasmtime_pooling_allocation_config_t {
541 config: PoolingAllocationConfig::default(),
542 })
543}
544
545#[unsafe(no_mangle)]
546#[cfg(feature = "pooling-allocator")]
547pub extern "C" fn wasmtime_pooling_allocation_config_delete(
548 _: Box<wasmtime_pooling_allocation_config_t>,
549) {
550}
551
552#[unsafe(no_mangle)]
553#[cfg(feature = "pooling-allocator")]
554pub extern "C" fn wasmtime_pooling_allocation_config_max_unused_warm_slots_set(
555 c: &mut wasmtime_pooling_allocation_config_t,
556 max: u32,
557) {
558 c.config.max_unused_warm_slots(max);
559}
560
561#[unsafe(no_mangle)]
562#[cfg(feature = "pooling-allocator")]
563pub extern "C" fn wasmtime_pooling_allocation_config_decommit_batch_size_set(
564 c: &mut wasmtime_pooling_allocation_config_t,
565 batch_size: usize,
566) {
567 c.config.decommit_batch_size(batch_size);
568}
569
570#[unsafe(no_mangle)]
571#[cfg(all(feature = "pooling-allocator", feature = "async"))]
572pub extern "C" fn wasmtime_pooling_allocation_config_async_stack_keep_resident_set(
573 c: &mut wasmtime_pooling_allocation_config_t,
574 size: usize,
575) {
576 c.config.async_stack_keep_resident(size);
577}
578
579#[unsafe(no_mangle)]
580#[cfg(feature = "pooling-allocator")]
581pub extern "C" fn wasmtime_pooling_allocation_config_linear_memory_keep_resident_set(
582 c: &mut wasmtime_pooling_allocation_config_t,
583 size: usize,
584) {
585 c.config.linear_memory_keep_resident(size);
586}
587
588#[unsafe(no_mangle)]
589#[cfg(feature = "pooling-allocator")]
590pub extern "C" fn wasmtime_pooling_allocation_config_table_keep_resident_set(
591 c: &mut wasmtime_pooling_allocation_config_t,
592 size: usize,
593) {
594 c.config.table_keep_resident(size);
595}
596
597#[unsafe(no_mangle)]
598#[cfg(feature = "pooling-allocator")]
599pub extern "C" fn wasmtime_pooling_allocation_config_total_component_instances_set(
600 c: &mut wasmtime_pooling_allocation_config_t,
601 count: u32,
602) {
603 c.config.total_component_instances(count);
604}
605
606#[unsafe(no_mangle)]
607#[cfg(feature = "pooling-allocator")]
608pub extern "C" fn wasmtime_pooling_allocation_config_max_component_instance_size_set(
609 c: &mut wasmtime_pooling_allocation_config_t,
610 size: usize,
611) {
612 c.config.max_component_instance_size(size);
613}
614
615#[unsafe(no_mangle)]
616#[cfg(feature = "pooling-allocator")]
617pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instances_per_component_set(
618 c: &mut wasmtime_pooling_allocation_config_t,
619 count: u32,
620) {
621 c.config.max_core_instances_per_component(count);
622}
623
624#[unsafe(no_mangle)]
625#[cfg(feature = "pooling-allocator")]
626pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_component_set(
627 c: &mut wasmtime_pooling_allocation_config_t,
628 count: u32,
629) {
630 c.config.max_memories_per_component(count);
631}
632
633#[unsafe(no_mangle)]
634#[cfg(feature = "pooling-allocator")]
635pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_component_set(
636 c: &mut wasmtime_pooling_allocation_config_t,
637 count: u32,
638) {
639 c.config.max_tables_per_component(count);
640}
641
642#[unsafe(no_mangle)]
643#[cfg(feature = "pooling-allocator")]
644pub extern "C" fn wasmtime_pooling_allocation_config_total_memories_set(
645 c: &mut wasmtime_pooling_allocation_config_t,
646 count: u32,
647) {
648 c.config.total_memories(count);
649}
650
651#[unsafe(no_mangle)]
652#[cfg(feature = "pooling-allocator")]
653pub extern "C" fn wasmtime_pooling_allocation_config_total_tables_set(
654 c: &mut wasmtime_pooling_allocation_config_t,
655 count: u32,
656) {
657 c.config.total_tables(count);
658}
659
660#[unsafe(no_mangle)]
661#[cfg(all(feature = "pooling-allocator", feature = "async"))]
662pub extern "C" fn wasmtime_pooling_allocation_config_total_stacks_set(
663 c: &mut wasmtime_pooling_allocation_config_t,
664 count: u32,
665) {
666 c.config.total_stacks(count);
667}
668
669#[unsafe(no_mangle)]
670#[cfg(feature = "pooling-allocator")]
671pub extern "C" fn wasmtime_pooling_allocation_config_total_core_instances_set(
672 c: &mut wasmtime_pooling_allocation_config_t,
673 count: u32,
674) {
675 c.config.total_core_instances(count);
676}
677
678#[unsafe(no_mangle)]
679#[cfg(feature = "pooling-allocator")]
680pub extern "C" fn wasmtime_pooling_allocation_config_max_core_instance_size_set(
681 c: &mut wasmtime_pooling_allocation_config_t,
682 size: usize,
683) {
684 c.config.max_core_instance_size(size);
685}
686
687#[unsafe(no_mangle)]
688#[cfg(feature = "pooling-allocator")]
689pub extern "C" fn wasmtime_pooling_allocation_config_max_tables_per_module_set(
690 c: &mut wasmtime_pooling_allocation_config_t,
691 tables: u32,
692) {
693 c.config.max_tables_per_module(tables);
694}
695
696#[unsafe(no_mangle)]
697#[cfg(feature = "pooling-allocator")]
698pub extern "C" fn wasmtime_pooling_allocation_config_table_elements_set(
699 c: &mut wasmtime_pooling_allocation_config_t,
700 elements: usize,
701) {
702 c.config.table_elements(elements);
703}
704
705#[unsafe(no_mangle)]
706#[cfg(feature = "pooling-allocator")]
707pub extern "C" fn wasmtime_pooling_allocation_config_max_memories_per_module_set(
708 c: &mut wasmtime_pooling_allocation_config_t,
709 memories: u32,
710) {
711 c.config.max_memories_per_module(memories);
712}
713
714#[unsafe(no_mangle)]
715#[cfg(feature = "pooling-allocator")]
716pub extern "C" fn wasmtime_pooling_allocation_config_max_memory_size_set(
717 c: &mut wasmtime_pooling_allocation_config_t,
718 bytes: usize,
719) {
720 c.config.max_memory_size(bytes);
721}
722
723#[unsafe(no_mangle)]
724#[cfg(all(feature = "pooling-allocator", feature = "gc"))]
725pub extern "C" fn wasmtime_pooling_allocation_config_total_gc_heaps_set(
726 c: &mut wasmtime_pooling_allocation_config_t,
727 count: u32,
728) {
729 c.config.total_gc_heaps(count);
730}
731
732#[unsafe(no_mangle)]
733#[cfg(feature = "pooling-allocator")]
734pub extern "C" fn wasmtime_pooling_allocation_strategy_set(
735 c: &mut wasm_config_t,
736 pc: &wasmtime_pooling_allocation_config_t,
737) {
738 c.config
739 .allocation_strategy(wasmtime::InstanceAllocationStrategy::Pooling(
740 pc.config.clone(),
741 ));
742}
743
744#[unsafe(no_mangle)]
745pub extern "C" fn wasmtime_config_concurrency_support_set(c: &mut wasm_config_t, enable: bool) {
746 c.config.concurrency_support(enable);
747}