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