-
Notifications
You must be signed in to change notification settings - Fork 42
/
wasm.rs
57 lines (46 loc) · 1.33 KB
/
wasm.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
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 {
return (ptr::null_mut(), 0, 0);
}
((cur * page_size()) as *mut u8, pages * page_size(), 0)
}
pub unsafe fn remap(_ptr: *mut u8, _oldsize: usize, _newsize: usize, _can_move: bool)
-> *mut u8
{
// TODO: I think this can be implemented near the end?
ptr::null_mut()
}
pub unsafe fn free_part(_ptr: *mut u8, _oldsize: usize, _newsize: usize) -> bool {
false
}
pub unsafe fn free(_ptr: *mut u8, _size: usize) -> bool {
false
}
pub fn can_release_part(_flags: u32) -> bool {
false
}
pub fn acquire_global_lock() {
// single threaded, no need!
}
pub fn release_global_lock() {
// single threaded, no need!
}
pub fn allocates_zeros() -> bool {
true
}
pub fn page_size() -> usize {
64 * 1024
}