bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.43k stars 1.31k forks source link

Add a type-level distinction between aligned and possibly-unaligned Mmaps #9639

Closed sunshowers closed 1 day ago

sunshowers commented 1 day ago

In the wasmtime codebase there are two kinds of mmaps: those that are always backed by anonymous memory and are always aligned, and those that are possibly file-backed and so the length might be unaligned. In https://github.com/bytecodealliance/wasmtime/pull/9620 I accidentally mixed the two up in a way that was a ticking time bomb.

To resolve this, add a type parameter to Mmap to distinguish between the cases. All of wasmtime's users are clearly either one or the other, so it's quite simple in the end.