-
Notifications
You must be signed in to change notification settings - Fork 40
/
wasm.rs
51 lines (41 loc) · 1.03 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
use core::ptr;
extern {
#[link_name = "llvm.wasm.grow.memory.i32"]
fn grow_memory(pages: u32) -> i32;
}
pub unsafe fn alloc(size: usize) -> (*mut u8, usize, u32) {
let pages = size / page_size();
let prev = grow_memory(pages as u32);
if prev == -1 {
return (ptr::null_mut(), 0, 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)
-> *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
}