Stream: git-wasmtime

Topic: wasmtime / issue #6636 Provide wasmtime_config_with_host_...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 16:43):

basvandijk opened issue #6636:

Feature

We're working on a Haskell binding to wasmtime called wasmtime-hs.

In our project we would like to have access to the Config::with_host_memory(...) functionality.
Could this function be provided in the C API?

Benefit

At the moment this functionality is only available in the Rust library. It would be nice if other languages have access to the same functionality.

Implementation

Do you have an implementation plan, and/or ideas for data structures or
algorithms to use?

Not yet, it probably has to look something like this but I haven't thought about it too much yet:

#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_with_host_memory(
    c: &mut wasm_config_t,
    mem_creator_callback: wasmtime_new_memory_callback_t,
) {
    c.config.with_host_memory(...);
}

pub type wasmtime_new_memory_callback_t = extern "C" fn(
    ty: &wasm_memorytype_t,
    minimum: u64,
    maximum_specified: bool,
    maximum: u64,
    reserved_size_in_bytes_specified: bool,
    reserved_size_in_bytes: u64,
    guard_size_in_bytes: bool,
) -> Box<dyn LinearMemory>

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 17:32):

jameysharp labeled issue #6636:

Feature

We're working on a Haskell binding to wasmtime called wasmtime-hs.

In our project we would like to have access to the Config::with_host_memory(...) functionality.
Could this function be provided in the C API?

Benefit

At the moment this functionality is only available in the Rust library. It would be nice if other languages have access to the same functionality.

Implementation

Do you have an implementation plan, and/or ideas for data structures or
algorithms to use?

Not yet, it probably has to look something like this but I haven't thought about it too much yet:

#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_with_host_memory(
    c: &mut wasm_config_t,
    mem_creator_callback: wasmtime_new_memory_callback_t,
) {
    c.config.with_host_memory(...);
}

pub type wasmtime_new_memory_callback_t = extern "C" fn(
    ty: &wasm_memorytype_t,
    minimum: u64,
    maximum_specified: bool,
    maximum: u64,
    reserved_size_in_bytes_specified: bool,
    reserved_size_in_bytes: u64,
    guard_size_in_bytes: bool,
) -> Box<dyn LinearMemory>

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 17:32):

jameysharp labeled issue #6636:

Feature

We're working on a Haskell binding to wasmtime called wasmtime-hs.

In our project we would like to have access to the Config::with_host_memory(...) functionality.
Could this function be provided in the C API?

Benefit

At the moment this functionality is only available in the Rust library. It would be nice if other languages have access to the same functionality.

Implementation

Do you have an implementation plan, and/or ideas for data structures or
algorithms to use?

Not yet, it probably has to look something like this but I haven't thought about it too much yet:

#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_with_host_memory(
    c: &mut wasm_config_t,
    mem_creator_callback: wasmtime_new_memory_callback_t,
) {
    c.config.with_host_memory(...);
}

pub type wasmtime_new_memory_callback_t = extern "C" fn(
    ty: &wasm_memorytype_t,
    minimum: u64,
    maximum_specified: bool,
    maximum: u64,
    reserved_size_in_bytes_specified: bool,
    reserved_size_in_bytes: u64,
    guard_size_in_bytes: bool,
) -> Box<dyn LinearMemory>

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 17:33):

github-actions[bot] commented on issue #6636:

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html


<details>

To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.

To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.

Learn more.

</details>

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 17:38):

jameysharp commented on issue #6636:

This sounds reasonable to me but I'm not sure what design principles we're following for Wasmtime's C API, so I'd like to get opinions from @alexcrichton or @fitzgen on what this should look like.

Huh, maybe I shouldn't have used the wasmtime:config label. I wasn't expecting that particular auto-reply.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 17:42):

alexcrichton commented on issue #6636:

This was discussed a bit on Zulip as well and my strawman there was:

typedef wasmtime_error_t *(*wasmtime_new_memory_t)(
    wasm_memorytype_t *ty,
    size_t minimum,
    size_t maximum,
    size_t reserved_size_in_bytes,
    size_t guard_size_in_bytes,
    void **ret);

typedef void *(*wasmtime_memory_get_t)(
    void *ptr,
    size_t *byte_size,
    size_t *maximum_byte_size);

typedef wasmtime_error_t *(*wasmtime_memory_grow_t)(
    void *ptr,
    size_t new_size);

typedef struct {
  wasmtime_new_memory_t new_memory;
  wasmtime_memory_get_t get_memory;
  wasmtime_memory_grow_t grow_memory;
} wasmtime_memory_creator_t;

void wasmtime_config_memory_creator_set(wasmtime_config_t *config, wasmtime_memory_creator_t *creator);

Personally I don't think the details matter too too much so long as it all works for your use case, we can always iterate over time as necessary.

Note though that in the original suggestion an extern "C" fn can't return Box<dyn LinearMemory> because that's a Rust-defined structure which C can't mirror, so you'll need to package up those callbacks in addition to the wasmtime_new_memory_callback_t type

view this post on Zulip Wasmtime GitHub notifications bot (Jun 23 2023 at 23:12):

basvandijk commented on issue #6636:

@alexcrichton thanks, I wasn't aware of that chat by my colleague :). But your strawman looks like a great start!

view this post on Zulip Wasmtime GitHub notifications bot (Oct 02 2023 at 17:13):

alexcrichton closed issue #6636:

Feature

We're working on a Haskell binding to wasmtime called wasmtime-hs.

In our project we would like to have access to the Config::with_host_memory(...) functionality.
Could this function be provided in the C API?

Benefit

At the moment this functionality is only available in the Rust library. It would be nice if other languages have access to the same functionality.

Implementation

Do you have an implementation plan, and/or ideas for data structures or
algorithms to use?

Not yet, it probably has to look something like this but I haven't thought about it too much yet:

#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_with_host_memory(
    c: &mut wasm_config_t,
    mem_creator_callback: wasmtime_new_memory_callback_t,
) {
    c.config.with_host_memory(...);
}

pub type wasmtime_new_memory_callback_t = extern "C" fn(
    ty: &wasm_memorytype_t,
    minimum: u64,
    maximum_specified: bool,
    maximum: u64,
    reserved_size_in_bytes_specified: bool,
    reserved_size_in_bytes: u64,
    guard_size_in_bytes: bool,
) -> Box<dyn LinearMemory>

Last updated: Oct 23 2024 at 20:03 UTC