-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from wasmerio/feature/run-lua-wasm
Running Lua
- Loading branch information
Showing
17 changed files
with
454 additions
and
126 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use super::process::_abort; | ||
use crate::webassembly::Instance; | ||
|
||
/// emscripten: ___cxa_allocate_exception | ||
pub extern "C" fn ___cxa_allocate_exception(size: u32, instance: &mut Instance) -> u32 { | ||
debug!("emscripten::___cxa_allocate_exception"); | ||
(instance.emscripten_data.as_ref().unwrap().malloc)(size as _, instance) | ||
} | ||
|
||
/// emscripten: ___cxa_throw | ||
/// TODO: We don't have support for exceptions yet | ||
pub extern "C" fn ___cxa_throw(ptr: u32, ty: u32, destructor: u32, instance: &mut Instance) { | ||
debug!("emscripten::___cxa_throw"); | ||
_abort(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::webassembly::Instance; | ||
use libc::{c_int, c_void}; | ||
use std::cell::UnsafeCell; | ||
|
||
/// setjmp | ||
pub extern "C" fn __setjmp(env_addr: u32, instance: &mut Instance) -> c_int { | ||
debug!("emscripten::__setjmp (setjmp)"); | ||
unsafe { | ||
// Rather than using the env as the holder of the jump buffer pointer, | ||
// we use the environment address to store the index relative to jumps | ||
// so the address of the jump it's outside the wasm memory itself. | ||
let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8; | ||
// We create the jump buffer outside of the wasm memory | ||
let jump_buf: UnsafeCell<[c_int; 27]> = UnsafeCell::new([0; 27]); | ||
let mut jumps = &mut instance.emscripten_data.as_mut().unwrap().jumps; | ||
let result = setjmp(jump_buf.get() as _); | ||
// We set the jump index to be the last value of jumps | ||
*jump_index = jumps.len() as _; | ||
// We hold the reference of the jump buffer | ||
jumps.push(jump_buf); | ||
result | ||
} | ||
} | ||
|
||
/// longjmp | ||
pub extern "C" fn __longjmp(env_addr: u32, val: c_int, instance: &mut Instance) -> ! { | ||
debug!("emscripten::__longjmp (longjmp) {}", val); | ||
unsafe { | ||
// We retrieve the jump index from the env address | ||
let jump_index = instance.memory_offset_addr(0, env_addr as usize) as *mut i8; | ||
let mut jumps = &mut instance.emscripten_data.as_mut().unwrap().jumps; | ||
// We get the real jump buffer from the jumps vector, using the retrieved index | ||
let mut jump_buf = &jumps[*jump_index as usize]; | ||
longjmp(jump_buf.get() as _, val) | ||
}; | ||
} | ||
|
||
extern "C" { | ||
fn setjmp(env: *mut c_void) -> c_int; | ||
fn longjmp(env: *mut c_void, val: c_int) -> !; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::webassembly::Instance; | ||
|
||
// TODO: Need to implement. | ||
|
||
/// emscripten: dlopen(filename: *const c_char, flag: c_int) -> *mut c_void | ||
pub extern "C" fn _dlopen(filename: u32, flag: c_int) -> u32 { | ||
debug!("emscripten::_dlopen"); | ||
-1 | ||
} | ||
|
||
/// emscripten: dlclose(handle: *mut c_void) -> c_int | ||
pub extern "C" fn _dlclose(filename: u32) -> u32 { | ||
debug!("emscripten::_dlclose"); | ||
-1 | ||
} | ||
|
||
/// emscripten: dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void | ||
pub extern "C" fn _dlsym(filepath: u32, symbol: u32) -> u32 { | ||
debug!("emscripten::_dlerror"); | ||
-1 | ||
} | ||
|
||
/// emscripten: dlerror() -> *mut c_char | ||
pub extern "C" fn _dlerror() -> u32 { | ||
debug!("emscripten::_dlerror"); | ||
-1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::webassembly::Instance; | ||
|
||
/// emscripten: _llvm_log10_f64 | ||
pub extern "C" fn _llvm_log10_f64(value: f64) -> f64 { | ||
debug!("emscripten::_llvm_log10_f64"); | ||
value.log10() | ||
} | ||
|
||
/// emscripten: _llvm_log2_f64 | ||
pub extern "C" fn _llvm_log2_f64(value: f64) -> f64 { | ||
debug!("emscripten::_llvm_log2_f64"); | ||
value.log2() | ||
} | ||
|
||
// emscripten: f64-rem | ||
pub extern "C" fn f64_rem(x: f64, y: f64) -> f64 { | ||
debug!("emscripten::f64-rem"); | ||
x % y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.