Skip to content

Commit 6329d4d

Browse files
committed
Fix WASM for LLVM6
1 parent 24a3824 commit 6329d4d

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

wee_alloc/src/imp_wasm32.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ use core::cell::UnsafeCell;
44
use units::Pages;
55

66
extern "C" {
7-
#[link_name = "llvm.wasm.current.memory.i32"]
8-
fn current_memory() -> usize;
9-
10-
// TODO: this intrinsic actually returns the previous limit, but LLVM
11-
// doesn't expose that right now. When we upgrade LLVM stop using
12-
// `current_memory` above. Also handle `-1` as an allocation failure.
137
#[link_name = "llvm.wasm.grow.memory.i32"]
14-
fn grow_memory(pages: usize);
15-
}
16-
17-
unsafe fn get_base_pointer() -> *mut u8 {
18-
(current_memory() * PAGE_SIZE.0) as _
8+
fn grow_memory(pages: usize) -> i32;
199
}
2010

2111
pub(crate) unsafe fn alloc_pages(n: Pages) -> *mut u8 {
22-
let ptr = get_base_pointer();
12+
let ptr = grow_memory(n.0);
13+
extra_assert!(ptr != -1);
14+
let ptr = (ptr as usize * PAGE_SIZE.0) as _;
2315
assert_is_word_aligned(ptr);
24-
extra_assert!(!ptr.is_null());
25-
grow_memory(n.0);
2616
ptr
2717
}
2818

0 commit comments

Comments
 (0)