Skip to content

Commit

Permalink
Rollup merge of #70585 - alexcrichton:fix-wasi-align-alloc, r=Mark-Si…
Browse files Browse the repository at this point in the history
…mulacrum

std: Fix over-aligned allocations on wasm32-wasi

The wasm32-wasi target delegates its malloc implementation to the
functions in wasi-libc, but the invocation of `aligned_alloc` was
incorrect by passing the number of bytes requested first rather than the
alignment. This commit swaps the order of these two arguments to ensure
that we allocate over-aligned memory correctly.
  • Loading branch information
Centril authored Mar 31, 2020
2 parents 3ef70fe + ab2998b commit cd4d1c7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/sys/wasi/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unsafe impl GlobalAlloc for System {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
libc::malloc(layout.size()) as *mut u8
} else {
libc::aligned_alloc(layout.size(), layout.align()) as *mut u8
libc::aligned_alloc(layout.align(), layout.size()) as *mut u8
}
}

Expand Down

0 comments on commit cd4d1c7

Please sign in to comment.