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