Skip to content

Commit

Permalink
Merge #328
Browse files Browse the repository at this point in the history
328: fix master; add some emscripten calls r=MarkMcCaskey a=MarkMcCaskey

notified by #327 ;
that program when compiled now outputs 
`"RuntimeError: WebAssembly trap occured during runtime: memory out-of-bounds access"` ;

which may have been broken by #326 

resolves #327

Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
  • Loading branch information
3 people committed Apr 5, 2019
2 parents d9114e4 + 221e909 commit dcbb8d5
Show file tree
Hide file tree
Showing 57 changed files with 271 additions and 89 deletions.
71 changes: 56 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added lib/emscripten/a.txt
Empty file.
56 changes: 36 additions & 20 deletions lib/emscripten/build/emtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,42 @@ pub fn compile(file: &str, ignores: &Vec<String>) -> Option<String> {
output_path.set_extension("js");
let output_str = output_path.to_str().unwrap();

// Compile to wasm
let _wasm_compilation = Command::new("emcc")
.arg(file)
.arg("-s")
.arg("WASM=1")
.arg("-o")
.arg(output_str)
.output()
.expect("failed to execute process");

// panic!("{:?}", wasm_compilation);
// if output.stderr {
// panic!("{}", output.stderr);
// }
// Remove js file

if Path::new(output_str).is_file() {
fs::remove_file(output_str).unwrap();
} else {
println!("Output JS not found: {}", output_str);
let wasm_file_metadata = {
let mut wasm_file_path = PathBuf::from(file);
wasm_file_path.set_extension("wasm");
if let Ok(wasm_file) = File::open(wasm_file_path) {
Some(wasm_file.metadata().unwrap())
} else {
None
}
};

let real_file = File::open(file).unwrap();
let file_metadata = real_file.metadata().unwrap();
if wasm_file_metadata.is_none()
|| file_metadata.modified().unwrap() >= wasm_file_metadata.unwrap().modified().unwrap()
{
// Compile to wasm
let _wasm_compilation = Command::new("emcc")
.arg(file)
.arg("-s")
.arg("WASM=1")
.arg("-o")
.arg(output_str)
.output()
.expect("failed to execute process");

// panic!("{:?}", wasm_compilation);
// if output.stderr {
// panic!("{}", output.stderr);
// }
// Remove js file

if Path::new(output_str).is_file() {
fs::remove_file(output_str).unwrap();
} else {
println!("Output JS not found: {}", output_str);
}
}

let mut output_path = PathBuf::from(file);
Expand Down
4 changes: 4 additions & 0 deletions lib/emscripten/emtests/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <iostream>
int main() {
std::cout << "hello world\n";
}
2 changes: 2 additions & 0 deletions lib/emscripten/emtests/hello.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello world

Binary file added lib/emscripten/emtests/hello.wasm
Binary file not shown.
45 changes: 44 additions & 1 deletion lib/emscripten/emtests/ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,47 @@ test_wprintf
test_std_cout_new
test_strptime_reentrant
test_gmtime
test_time_c
test_time_c
test_execvp
test_nl_types
test_phiundef
test_pipe
test_printf_2
test_printf_more
test_regex
test_relocatable_void_function
test_rounding
test_set_align
test_sintvars
test_sizeof
test_sscanf
test_sscanf_3
test_sscanf_4
test_sscanf_5
test_sscanf_6
test_sscanf_caps
test_sscanf_float
test_sscanf_n
test_strcasecmp
test_strcmp_uni
test_strndup
test_strstr
test_strtod
test_strtok
test_strtol_bin
test_strtol_dec
test_strtol_hex
test_strtol_oct
test_strtoll_bin
test_strtoll_dec
test_strtoll_hex
test_strtoll_oct
test_struct_varargs
test_transtrcase
test_trickystring
test_unary_literal
test_vfs
test_vprintf
test_vsnprintf
test_write_stdout_fileno
test_zerodiv
Empty file added lib/emscripten/foo.txt
Empty file.
5 changes: 5 additions & 0 deletions lib/emscripten/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
debug!("emscripten::___cxa_end_catch");
}

pub fn ___cxa_uncaught_exception(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::___cxa_uncaught_exception");
-1
}
10 changes: 9 additions & 1 deletion lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ pub fn run_emscripten_instance(
let data_ptr = &mut data as *mut _ as *mut c_void;
instance.context_mut().data = data_ptr;

// ATINIT
// (used by C++)
if let Ok(_func) = instance.dyn_func("globalCtors") {
instance.call("globalCtors", &[])?;
}

if let Ok(_func) = instance.dyn_func("___emscripten_environ_constructor") {
instance.call("___emscripten_environ_constructor", &[])?;
}
Expand All @@ -269,7 +275,7 @@ pub fn run_emscripten_instance(
),
};

// TODO atinit and atexit for emscripten
// TODO atexit for emscripten
// println!("{:?}", data);
Ok(())
}
Expand Down Expand Up @@ -607,6 +613,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___cxa_throw" => func!(crate::exception::___cxa_throw),
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
"___cxa_uncaught_exception" => func!(crate::exception::___cxa_uncaught_exception),

// Time
"_gettimeofday" => func!(crate::time::_gettimeofday),
Expand All @@ -619,6 +626,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_localtime" => func!(crate::time::_localtime),
"_time" => func!(crate::time::_time),
"_strftime" => func!(crate::time::_strftime),
"_strftime_l" => func!(crate::time::_strftime_l),
"_localtime_r" => func!(crate::time::_localtime_r),
"_gmtime_r" => func!(crate::time::_gmtime_r),
"_mktime" => func!(crate::time::_mktime),
Expand Down
17 changes: 17 additions & 0 deletions lib/emscripten/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,20 @@ pub fn _strftime(
);
0
}

/// emscripten: _strftime_l
pub fn _strftime_l(
ctx: &mut Ctx,
s_ptr: c_int,
maxsize: u32,
format_ptr: c_int,
tm_ptr: c_int,
_last: c_int,
) -> i32 {
debug!(
"emscripten::_strftime_l {} {} {} {}",
s_ptr, maxsize, format_ptr, tm_ptr
);

_strftime(ctx, s_ptr, maxsize, format_ptr, tm_ptr)
}
Loading

0 comments on commit dcbb8d5

Please sign in to comment.