mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 12:16:30 +00:00
Make emscripten data functions optional
This commit is contained in:
@ -96,16 +96,36 @@ pub struct EmscriptenData {
|
|||||||
impl EmscriptenData {
|
impl EmscriptenData {
|
||||||
pub fn new(instance: &mut Instance) -> Self {
|
pub fn new(instance: &mut Instance) -> Self {
|
||||||
unsafe {
|
unsafe {
|
||||||
let malloc_func = instance.func("_malloc").unwrap();
|
let malloc_func = instance.func("_malloc");
|
||||||
let malloc_addr = malloc_func.raw() as *const u8;
|
let malloc_addr = if let Ok(malloc_func) = malloc_func {
|
||||||
let free_func = instance.func("_free").unwrap();
|
malloc_func.raw() as *const u8
|
||||||
let free_addr = free_func.raw() as *const u8;
|
} else {
|
||||||
let memalign_func = instance.func("_memalign").unwrap();
|
0 as *const u8
|
||||||
let memalign_addr = memalign_func.raw() as *const u8;
|
};
|
||||||
let memset_func = instance.func("_memset").unwrap();
|
let free_func = instance.func("_free");
|
||||||
let memset_addr = memset_func.raw() as *const u8;
|
let free_addr = if let Ok(free_func) = free_func {
|
||||||
let stack_alloc_func = instance.func("stackAlloc").unwrap();
|
free_func.raw() as *const u8
|
||||||
let stack_alloc_addr = stack_alloc_func.raw() as *const u8;
|
} else {
|
||||||
|
0 as *const u8
|
||||||
|
};
|
||||||
|
let memalign_func = instance.func("_memalign");
|
||||||
|
let memalign_addr = if let Ok(memalign_func) = memalign_func {
|
||||||
|
memalign_func.raw() as *const u8
|
||||||
|
} else {
|
||||||
|
0 as *const u8
|
||||||
|
};
|
||||||
|
let memset_func = instance.func("_memset");
|
||||||
|
let memset_addr = if let Ok(memset_func) = memset_func {
|
||||||
|
memset_func.raw() as *const u8
|
||||||
|
} else {
|
||||||
|
0 as *const u8
|
||||||
|
};
|
||||||
|
let stack_alloc_func = instance.func("stackAlloc");
|
||||||
|
let stack_alloc_addr = if let Ok(stack_alloc_func) = stack_alloc_func {
|
||||||
|
stack_alloc_func.raw() as *const u8
|
||||||
|
} else {
|
||||||
|
0 as *const u8
|
||||||
|
};
|
||||||
|
|
||||||
EmscriptenData {
|
EmscriptenData {
|
||||||
malloc: mem::transmute(malloc_addr),
|
malloc: mem::transmute(malloc_addr),
|
||||||
|
Reference in New Issue
Block a user