Skip to content

Conversation

@kpreisser
Copy link
Contributor

@kpreisser kpreisser commented Oct 15, 2022

Hi, this PR adds new Int64-based APIs to Memory to allow to access memories with more than 32767 pages.

Fixes #165

I added a new method GetSpan(long address, int length) as well as GetSpan<T>(long address, int length) to retrieve a Span<byte> and Span<T> starting at the given Int64 address. Additionally, I added a GetLength() and GetPointer() methods for getting a raw pointer to the memory, and the memory length in bytes (in case you want to access the whole memory area at once, even if it exceeds a size of 2 GiB).

Additionally, for the ReadXyz()/WriteXyz() methods, I added new overloads taking an Int64 address, and fixed the existing (Int32-based) methods to not throw an OverflowException. The old (Int32-based) APIs have been removed as breaking change.

I also added an ObsoleteAttribute to the GetSpan() method to indicate that it will throw an OverflowException when the memory has more than 32767 pages, with a recommendation to use the GetSpan(long address, int length) method instead.

What do you think?

Thanks!

@kpreisser kpreisser changed the title Allow to access a Memory with more than 32767 pages Allow to access a Memory with more than 32767 pages Oct 15, 2022
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.

Thanks for this fix too!

Just a few minor nits and a more general comment regarding all the new long overloads for the memory accessor methods.

@peterhuene peterhuene merged commit 3b26938 into bytecodealliance:main Oct 21, 2022
@peterhuene
Copy link
Member

@kpreisser thanks for addressing this!

@kpreisser kpreisser deleted the largeMemoryAccess branch October 21, 2022 19:47
kpreisser added a commit to kpreisser/wasmtime-dotnet that referenced this pull request Oct 22, 2022
…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.
peterhuene pushed a commit that referenced this pull request Oct 31, 2022
* Add support for enabling the Memory64 proposal, which was added to the Wasmtime C API with bytecodealliance/wasmtime#3182.

Additionally, add tests to verify the new APIs added with #166 are able to access a memory beyond the 4 GiB area.

* Follow-Up: Adjust the API to match the new C API introduced with bytecodealliance/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).

* Follow-Up: Validate the arguments.

* Simplify.

* Simplify.
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.

Memory with more than 32767 pages cannot be accessed

2 participants