-
Notifications
You must be signed in to change notification settings - Fork 1.4k
#[repr(align(...))] structures cause an out of bounds memory access #1435
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
Comments
How much memory is the wasm module allowed to use? The version with |
How should I check it? For reference, the original structure looks like this:
Switching to this defintion of |
FWIW: Lucet gets a HeapOutOfBounds fault running this module (as I compiled it locally with 1.40, we're still stuck on snapshot 0). |
Looks like this was a bug in the Rust standard library, fixed here. As a local workaround while we wait for that to propagate you can depend directly on # in Cargo.toml
[dependencies]
dlmalloc = { version = "0.1", features = ['global'] } #[global_allocator]
static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc;
#[repr(align(64))]
#[derive(Copy, Clone, Default, Debug)]
pub struct CacheBucket([CacheEntry; 3]);
#[repr(C)]
#[derive(Copy, Clone, Default, Debug)]
pub struct CacheEntry {
pub alpha: bool,
}
fn main() {
let buckets = 4194304;
let xd = vec![CacheBucket::default(); buckets];
let string = format!("{:?}", xd);
println!("{}", string.len());
} |
This works for me on nightly, so I guess we can close it. |
I'm not sure if I should report this issue here or in rust-lang/rust or even somewhere else.
Consider the following code:
compiled to wasm using
rustup run stable cargo build --target=wasm32-wasi
withrustc 1.42.0 (b8cedc004 2020-03-09)
Then run the wasm binary using wasmtime:
The code runs correctly if
buckets
is small (e.g. 4) or if#[repr(align(64))]
is removed.wasmtime master, 78772cf
The text was updated successfully, but these errors were encountered: