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

Fix note about unaligned references in WasmRef docs #4444

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

chipshort
Copy link
Contributor

Contrary to the current docs, WasmRef is not safe for unaligned references. This PR adjusts the docs.
Here's an example that shows the problem:

use wasmer::{Memory, MemoryType, Store, WasmPtr};

fn main() -> anyhow::Result<()> {
    let mut store = Store::default();
    let memory = Memory::new(&mut store, MemoryType::new(1, None, false))?;
    let memory = memory.view(&store);
    // write unaligned value into memory
    WasmPtr::<u32>::new(1).deref(&memory).write(42u32)?; // <- this panics with `misaligned pointer dereference`

    Ok(())
}

It would be possible to support this using write_unaligned, but that would require some refactoring, since it needs to be kept a pointer and not converted to a reference, as is currently done in WasmRefAccess::new.

@syrusakbary syrusakbary merged commit 323d7de into wasmerio:master Feb 7, 2024
52 checks passed
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