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 image_range for modules #7064

Merged
merged 1 commit into from
Sep 20, 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
15 changes: 15 additions & 0 deletions crates/c-api/include/wasmtime/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_module_deserialize_file(
wasmtime_module_t **ret
);


/**
* \brief Returns the range of bytes in memory where this module’s compilation image resides.
*
* The compilation image for a module contains executable code, data, debug information, etc.
* This is roughly the same as the wasmtime_module_serialize but not the exact same.
*
* For more details see: https://docs.wasmtime.dev/api/wasmtime/struct.Module.html#method.image_range
*/
WASM_API_EXTERN void wasmtime_module_image_range(
const wasm_module_t *module,
size_t *start,
size_t *end
);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
11 changes: 11 additions & 0 deletions crates/c-api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ pub extern "C" fn wasmtime_module_serialize(
handle_result(module.module.serialize(), |buf| ret.set_buffer(buf))
}

#[no_mangle]
pub extern "C" fn wasmtime_module_image_range(
module: &wasmtime_module_t,
start: &mut usize,
end: &mut usize,
) {
let range = module.module.image_range();
*start = range.start;
*end = range.end;
}

#[no_mangle]
pub unsafe extern "C" fn wasmtime_module_deserialize(
engine: &wasm_engine_t,
Expand Down