Skip to content

Commit

Permalink
c-api: Expose image_range for modules
Browse files Browse the repository at this point in the history
We're using this to monitor the amount of executable memory each module
needs.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
  • Loading branch information
rockwotj committed Sep 20, 2023
1 parent 3f07d27 commit 5d44836
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit 5d44836

Please sign in to comment.