Skip to content

Fix WASM for LLVM6 #17

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

Merged
merged 1 commit into from
Feb 12, 2018
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