Skip to content

Commit

Permalink
Merge pull request #48 from daniel-wong-dfinity-org/round-UP-when-div…
Browse files Browse the repository at this point in the history
…iding-size-by-page-size

For WASM, `alloc` rounds UP when dividing size by page size.
  • Loading branch information
alexcrichton authored Feb 12, 2025
2 parents fb11660 + 07c57ef commit 1006940
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl System {

unsafe impl Allocator for System {
fn alloc(&self, size: usize) -> (*mut u8, usize, u32) {
let pages = size / self.page_size();
let pages = size.div_ceil(self.page_size());
let prev = wasm::memory_grow(0, pages);
if prev == usize::max_value() {
return (ptr::null_mut(), 0, 0);
Expand Down

0 comments on commit 1006940

Please sign in to comment.