From cea5d4d6eb5e208b7854f99b5c506135865bac23 Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Thu, 12 Oct 2023 11:44:22 -0500 Subject: [PATCH 1/2] c-api: expose memory_init_cow Signed-off-by: Tyler Rockwood --- crates/c-api/include/wasmtime/config.h | 16 ++++++++++++++++ crates/c-api/src/config.rs | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h index 38f1edc1b504..38429f84b952 100644 --- a/crates/c-api/include/wasmtime/config.h +++ b/crates/c-api/include/wasmtime/config.h @@ -460,6 +460,22 @@ WASM_API_EXTERN void wasmtime_config_host_memory_creator_set( wasm_config_t*, wasmtime_memory_creator_t*); +/** + * \brief Configures whether copy-on-write memory-mapped data is used to initialize a linear memory. + * + * Initializing linear memory via a copy-on-write mapping can drastically improve instantiation costs + * of a WebAssembly module because copying memory is deferred. Additionally if a page of memory is + * only ever read from WebAssembly and never written too then the same underlying page of data will + * be reused between all instantiations of a module meaning that if a module is instantiated many + * times this can lower the overall memory required needed to run that module. + * + * This option defaults to true. + * + * For more information see the Rust documentation at + * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_init_cow + */ +WASMTIME_CONFIG_PROP(void, memory_init_cow, bool) + #ifdef __cplusplus } // extern "C" #endif diff --git a/crates/c-api/src/config.rs b/crates/c-api/src/config.rs index bcf8acde6551..201e0519665e 100644 --- a/crates/c-api/src/config.rs +++ b/crates/c-api/src/config.rs @@ -424,3 +424,8 @@ pub unsafe extern "C" fn wasmtime_config_host_memory_creator_set( new_memory: creator.new_memory, })); } + +#[no_mangle] +pub extern "C" fn wasmtime_config_memory_init_cow_set(c: &mut wasm_config_t, enable: bool) { + c.config.memory_init_cow(enable); +} From d4a2b3be6c88ad7dbe1e36f747bfca87c3cfbebd Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Thu, 12 Oct 2023 12:32:54 -0500 Subject: [PATCH 2/2] c-api: fix type in async.h I really wish these were autogenerated :/ Signed-off-by: Tyler Rockwood --- crates/c-api/include/wasmtime/async.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/c-api/include/wasmtime/async.h b/crates/c-api/include/wasmtime/async.h index 3919dc3f1058..955944c72086 100644 --- a/crates/c-api/include/wasmtime/async.h +++ b/crates/c-api/include/wasmtime/async.h @@ -353,7 +353,7 @@ typedef struct { */ WASM_API_EXTERN void wasmtime_config_host_stack_creator_set( wasm_config_t*, - wasmtime_memory_creator_t*); + wasmtime_stack_creator_t*); #ifdef __cplusplus