Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c-api: expose memory_init_cow #7227

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/c-api/include/wasmtime/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions crates/c-api/include/wasmtime/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}