Skip to content

Commit

Permalink
Merge branch 'llvm5'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 10, 2018
2 parents 8c3141d + a2b424b commit 9b2dcac
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
use core::ptr;

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

// 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: u32);
fn grow_memory(pages: u32) -> i32;
}

pub unsafe fn alloc(size: usize) -> (*mut u8, usize, u32) {
let pages = size / page_size();
let cur = current_memory() as usize;
grow_memory(pages as u32);
if current_memory() as usize == cur {
let prev = grow_memory(pages as u32);
if prev == -1 {
return (ptr::null_mut(), 0, 0);
}
((cur * page_size()) as *mut u8, pages * page_size(), 0)
let prev = prev as usize;
((prev * page_size()) as *mut u8, pages * page_size(), 0)
}

pub unsafe fn remap(_ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool)
Expand Down

0 comments on commit 9b2dcac

Please sign in to comment.