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