Skip to content

Conversation

@kpreisser
Copy link
Contributor

@kpreisser kpreisser commented Oct 22, 2022

Hi, this PR adds support for 64-bit memories, by adjusting the APIs to match the C API introduced with bytecodealliance/wasmtime#3153 and bytecodealliance/wasmtime#3182.

It contains the following changes:

  • Add Config.WithMemory64() for enabling the Memory64 proposal.
  • Change properties/parameters in Memory, MemoryExport and MemoryImport that work with pages (like Minimum, Maximum, Grow()) to use a long instead of uint. (I chose long instead of ulong because memory pages cannot exceed 2**48, and because ulong isn't CLS-compliant.)
    (This will be a breaking change.)
    • Added an Is64Bit property that specifies whether the memory is a 64-bit memory.
  • Add tests to verify the new APIs added with Allow to access a Memory with more than 32767 pages #166 are able to access a memory beyond the 4 GiB area, and that the new APIs correctly retrieve the memory type definitions.

Additionally, this fixes previously incorrect definitions of native functions wasmtime_memory_size and wasmtime_memory_grow, where the parameter incorrectly used uint instead of ulong after the changes introduced in the Wasmtime C API.
Also, I noticed that for native Config functions taking a C bool parameter, the [MarshalAs] attribute was missing, which meant these parameter were marshaled by .NET as 4-byte BOOL instead of an 1-byte value.

What do you think?

Thanks!

…e Wasmtime C API with bytecodealliance/wasmtime#3182.

Additionally, add tests to verify the new APIs added with bytecodealliance#166 are able to access a memory beyond the 4 GiB area.
@kpreisser kpreisser changed the title Add support for enabling the Memory64 proposal Add Config.WithMemory64() to allow to enable the Memory64 Oct 22, 2022
@kpreisser kpreisser changed the title Add Config.WithMemory64() to allow to enable the Memory64 Add Config.WithMemory64() for enabling the Memory64 proposal Oct 22, 2022
@kpreisser kpreisser marked this pull request as draft October 23, 2022 08:26
…codealliance/wasmtime#3153, in order to support 64-bit memory.

This also fixes the definition of native functions wasmtime_memory_size and wasmtime_memory_grow, which previously incorrectly used a UInt32 instead of UInt64, and config functions taking a bool parameter, which were previously missing the MarshalAsAttribute (to marshal a Boolean as 1 byte instead of 4 bytes).
@kpreisser kpreisser changed the title Add Config.WithMemory64() for enabling the Memory64 proposal Add support for 64-bit Memory Oct 23, 2022
@kpreisser kpreisser marked this pull request as ready for review October 23, 2022 10:14
@peterhuene peterhuene self-requested a review October 31, 2022 23:45
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great! Thanks for taking the opportunity to implement this feature along with the fixes.

@peterhuene peterhuene merged commit 7307841 into bytecodealliance:main Oct 31, 2022
@kpreisser kpreisser deleted the memory64 branch November 1, 2022 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants