Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions wee_alloc/src/imp_wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@ use core::cell::UnsafeCell;
use units::Pages;

extern "C" {
#[link_name = "llvm.wasm.current.memory.i32"]
fn current_memory() -> usize;

// TODO: this intrinsic actually returns the previous limit, but LLVM
// doesn't expose that right now. When we upgrade LLVM stop using
// `current_memory` above. Also handle `-1` as an allocation failure.
#[link_name = "llvm.wasm.grow.memory.i32"]
fn grow_memory(pages: usize);
}

unsafe fn get_base_pointer() -> *mut u8 {
(current_memory() * PAGE_SIZE.0) as _
fn grow_memory(pages: usize) -> i32;
}

pub(crate) unsafe fn alloc_pages(n: Pages) -> *mut u8 {
let ptr = get_base_pointer();
let ptr = grow_memory(n.0);
extra_assert!(ptr != -1);
let ptr = (ptr as usize * PAGE_SIZE.0) as _;
assert_is_word_aligned(ptr);
extra_assert!(!ptr.is_null());
grow_memory(n.0);
ptr
}

Expand Down