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

Implement the Wasm custom-page-sizes proposal #1349

Merged
merged 17 commits into from
Feb 1, 2025

Conversation

Robbepop
Copy link
Member

@Robbepop Robbepop commented Jan 24, 2025

Closes #1197.

  • Introduces a MemoryTypeBuilder
    • The builder allows to set the Memory's page size.
  • Use u32 instead of Pages type for MemoryType::{initial_pages, maximum_pages} methods.
    • This aligns the API better with Wasmtime's API.
  • Now returns a proper error when the operating system ran out of heap memory to allocate in Memory::new and Memory::grow instead of panicking.
  • Add MemoryType::{page_size, page_size_log2} methods.

ToDo

  • Add Wasm spec tests for the Wasm custom-page-sizes proposal.
  • Rename MemoryType::initial_pages to minimum.
  • Rename MemoryType::maximum_pages to maximum.

Follow-Up Work

  • Add Memory page count check to instantiation.
  • Adjust Wasmi fuzzers to make use of custom-page-sizes.
  • Use u64 instead of u32 in ...
    • Memory::new for minimum and maximum parameters.
    • MemoryType::new for minimum and maximum parameters.
    • MemoryTypeBuilder::min parameter
    • MemoryTypeBuilder::max parameter
    • MemoryType::minimum return type
    • MemoryType::maximum return type
    • MemoryType::page_size return type
    • Note: This allows the host to specify host-based linear memory with u32::MAX+1 pages which is valid for a page size of 1 byte.

The u64 parameters are important to align Wasmi with Wasmtime so that it also works here:

#[test]
fn it_works() {
    let mut b = wasmtime::MemoryType::builder();
    b.min(u64::from(u32::MAX) + 1);
    b.page_size_log2(0);
    b.build().unwrap(); // works!
}

@Robbepop Robbepop marked this pull request as ready for review February 1, 2025 00:43
@Robbepop Robbepop changed the title wip: Implement Wasm custom-page-sizes proposal Implement Wasm custom-page-sizes proposal Feb 1, 2025
@Robbepop Robbepop changed the title Implement Wasm custom-page-sizes proposal Implement the Wasm custom-page-sizes proposal Feb 1, 2025
@Robbepop Robbepop merged commit 9447890 into main Feb 1, 2025
16 of 17 checks passed
@Robbepop Robbepop deleted the rf-implement-custom-page-sizes branch February 1, 2025 13:28
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.

Implement the Wasm custom-page-sizes proposal
1 participant