mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-31 07:12:10 +00:00
Improved emscripten imported function arguments
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// use std::collections::HashMap;
|
// use std::collections::HashMap;
|
||||||
|
use wasmer_runtime_core::vm::Ctx;
|
||||||
|
|
||||||
pub extern "C" fn ___seterrno(value: i32) {
|
pub extern "C" fn ___seterrno(value: i32, _ctx: &mut Ctx) {
|
||||||
debug!("emscripten::___seterrno {}", value);
|
debug!("emscripten::___seterrno {}", value);
|
||||||
// TODO: Incomplete impl
|
// TODO: Incomplete impl
|
||||||
eprintln!("failed to set errno!");
|
eprintln!("failed to set errno!");
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
use libc::printf as _printf;
|
use libc::printf as _printf;
|
||||||
|
|
||||||
use wasmer_runtime_core::Instance;
|
use wasmer_runtime_core::vm::Ctx;
|
||||||
|
|
||||||
/// putchar
|
/// putchar
|
||||||
pub use libc::putchar;
|
pub use libc::putchar;
|
||||||
|
|
||||||
/// printf
|
/// printf
|
||||||
pub extern "C" fn printf(memory_offset: i32, extra: i32, instance: &Instance) -> i32 {
|
pub extern "C" fn printf(memory_offset: i32, extra: i32, ctx: &mut Ctx) -> i32 {
|
||||||
debug!("emscripten::printf {}, {}", memory_offset, extra);
|
debug!("emscripten::printf {}, {}", memory_offset, extra);
|
||||||
unsafe {
|
unsafe {
|
||||||
let addr = instance.memory_offset_addr(0, memory_offset as _) as _;
|
let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
|
||||||
_printf(addr, extra)
|
_printf(addr, extra)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
use wasmer_runtime_core::Instance;
|
use wasmer_runtime_core::vm::Ctx;
|
||||||
|
|
||||||
// TODO: Need to implement.
|
// TODO: Need to implement.
|
||||||
|
|
||||||
/// emscripten: dlopen(filename: *const c_char, flag: c_int) -> *mut c_void
|
/// emscripten: dlopen(filename: *const c_char, flag: c_int) -> *mut c_void
|
||||||
pub extern "C" fn _dlopen(filename: u32, flag: c_int) -> u32 {
|
pub extern "C" fn _dlopen(filename: u32, flag: c_int, _ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::_dlopen");
|
debug!("emscripten::_dlopen");
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: dlclose(handle: *mut c_void) -> c_int
|
/// emscripten: dlclose(handle: *mut c_void) -> c_int
|
||||||
pub extern "C" fn _dlclose(filename: u32) -> u32 {
|
pub extern "C" fn _dlclose(filename: u32, _ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::_dlclose");
|
debug!("emscripten::_dlclose");
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void
|
/// emscripten: dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void
|
||||||
pub extern "C" fn _dlsym(filepath: u32, symbol: u32) -> u32 {
|
pub extern "C" fn _dlsym(filepath: u32, symbol: u32, _ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::_dlerror");
|
debug!("emscripten::_dlerror");
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: dlerror() -> *mut c_char
|
/// emscripten: dlerror() -> *mut c_char
|
||||||
pub extern "C" fn _dlerror() -> u32 {
|
pub extern "C" fn _dlerror(_ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::_dlerror");
|
debug!("emscripten::_dlerror");
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,24 @@
|
|||||||
|
use wasmer_runtime_core::vm::Ctx;
|
||||||
|
|
||||||
/// emscripten: _llvm_log10_f64
|
/// emscripten: _llvm_log10_f64
|
||||||
pub extern "C" fn _llvm_log10_f64(value: f64) -> f64 {
|
pub extern "C" fn _llvm_log10_f64(value: f64, _ctx: &mut Ctx) -> f64 {
|
||||||
debug!("emscripten::_llvm_log10_f64");
|
debug!("emscripten::_llvm_log10_f64");
|
||||||
value.log10()
|
value.log10()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: _llvm_log2_f64
|
/// emscripten: _llvm_log2_f64
|
||||||
pub extern "C" fn _llvm_log2_f64(value: f64) -> f64 {
|
pub extern "C" fn _llvm_log2_f64(value: f64, _ctx: &mut Ctx) -> f64 {
|
||||||
debug!("emscripten::_llvm_log2_f64");
|
debug!("emscripten::_llvm_log2_f64");
|
||||||
value.log2()
|
value.log2()
|
||||||
}
|
}
|
||||||
|
|
||||||
// emscripten: f64-rem
|
// emscripten: f64-rem
|
||||||
pub extern "C" fn f64_rem(x: f64, y: f64) -> f64 {
|
pub extern "C" fn f64_rem(x: f64, y: f64, _ctx: &mut Ctx) -> f64 {
|
||||||
debug!("emscripten::f64-rem");
|
debug!("emscripten::f64-rem");
|
||||||
x % y
|
x % y
|
||||||
}
|
}
|
||||||
|
|
||||||
// emscripten: global.Math pow
|
// emscripten: global.Math pow
|
||||||
pub extern "C" fn pow(x: f64, y: f64) -> f64 {
|
pub extern "C" fn pow(x: f64, y: f64, _ctx: &mut Ctx) -> f64 {
|
||||||
x.powf(y)
|
x.powf(y)
|
||||||
}
|
}
|
||||||
|
@@ -33,14 +33,14 @@ pub extern "C" fn enlarge_memory(_ctx: &mut Ctx) -> u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: abortOnCannotGrowMemory
|
/// emscripten: abortOnCannotGrowMemory
|
||||||
pub extern "C" fn abort_on_cannot_grow_memory() -> u32 {
|
pub extern "C" fn abort_on_cannot_grow_memory(_ctx: &mut Ctx) -> u32 {
|
||||||
debug!("emscripten::abort_on_cannot_grow_memory");
|
debug!("emscripten::abort_on_cannot_grow_memory");
|
||||||
abort_with_message("Cannot enlarge memory arrays!");
|
abort_with_message("Cannot enlarge memory arrays!");
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: ___map_file
|
/// emscripten: ___map_file
|
||||||
pub extern "C" fn ___map_file() -> c_int {
|
pub extern "C" fn ___map_file(_ctx: &mut Ctx) -> c_int {
|
||||||
debug!("emscripten::___map_file");
|
debug!("emscripten::___map_file");
|
||||||
// NOTE: TODO: Em returns -1 here as well. May need to implement properly
|
// NOTE: TODO: Em returns -1 here as well. May need to implement properly
|
||||||
-1
|
-1
|
||||||
|
@@ -41,25 +41,25 @@ pub extern "C" fn em_abort(message: u32, ctx: &mut Ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn abort_stack_overflow(_what: c_int) {
|
pub extern "C" fn abort_stack_overflow(_what: c_int, _ctx: &mut Ctx) {
|
||||||
debug!("emscripten::abort_stack_overflow");
|
debug!("emscripten::abort_stack_overflow");
|
||||||
// TODO: Message incomplete. Need to finish em runtime data first
|
// TODO: Message incomplete. Need to finish em runtime data first
|
||||||
abort_with_message("Stack overflow! Attempted to allocate some bytes on the stack");
|
abort_with_message("Stack overflow! Attempted to allocate some bytes on the stack");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn _llvm_trap() {
|
pub extern "C" fn _llvm_trap(_ctx: &mut Ctx) {
|
||||||
debug!("emscripten::_llvm_trap");
|
debug!("emscripten::_llvm_trap");
|
||||||
abort_with_message("abort!");
|
abort_with_message("abort!");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn _system() -> c_int {
|
pub extern "C" fn _system(_ctx: &mut Ctx) -> c_int {
|
||||||
debug!("emscripten::_system");
|
debug!("emscripten::_system");
|
||||||
// TODO: May need to change this Em impl to a working version
|
// TODO: May need to change this Em impl to a working version
|
||||||
eprintln!("Can't call external programs");
|
eprintln!("Can't call external programs");
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn _popen() -> c_int {
|
pub extern "C" fn _popen(_ctx: &mut Ctx) -> c_int {
|
||||||
debug!("emscripten::_popen");
|
debug!("emscripten::_popen");
|
||||||
// TODO: May need to change this Em impl to a working version
|
// TODO: May need to change this Em impl to a working version
|
||||||
eprintln!("Missing function: popen");
|
eprintln!("Missing function: popen");
|
||||||
|
Reference in New Issue
Block a user