1
0
mirror of https://github.com/fluencelabs/wasmer synced 2025-03-31 15:01:03 +00:00

Merge branch 'master' into feat-runtime-c-api-cache

This commit is contained in:
Ivan Enderlin 2019-03-16 14:10:44 +01:00 committed by GitHub
commit 212591b908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 71 additions and 46 deletions
lib
clif-backend/src/signal
emscripten/src
runtime-core/src/memory
win-exception-handler

@ -4,13 +4,9 @@ use crate::trampoline::Trampoline;
use std::cell::Cell; use std::cell::Cell;
use std::ffi::c_void; use std::ffi::c_void;
use std::ptr; use std::ptr;
use wasmer_runtime_core::error::{RuntimeError, RuntimeResult};
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
use wasmer_runtime_core::vm::Func; use wasmer_runtime_core::vm::Func;
use wasmer_runtime_core::{
error::{RuntimeError, RuntimeResult},
structures::TypedIndex,
types::{MemoryIndex, TableIndex},
};
use wasmer_win_exception_handler::CallProtectedData; use wasmer_win_exception_handler::CallProtectedData;
pub use wasmer_win_exception_handler::_call_protected; pub use wasmer_win_exception_handler::_call_protected;
use winapi::shared::minwindef::DWORD; use winapi::shared::minwindef::DWORD;
@ -47,8 +43,8 @@ pub fn call_protected(
let CallProtectedData { let CallProtectedData {
code: signum, code: signum,
exceptionAddress: exception_address, exception_address,
instructionPointer: instruction_pointer, instruction_pointer,
} = result.unwrap_err(); } = result.unwrap_err();
if let Some(TrapData { if let Some(TrapData {

@ -66,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: c_int) -> c_int {
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr); debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(feature = "debug")]
let _ = name_ptr;
#[repr(C)] #[repr(C)]
struct GuestPasswd { struct GuestPasswd {

@ -7,7 +7,6 @@ use std::os::raw::c_char;
use crate::env::call_malloc; use crate::env::call_malloc;
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
extern "C" { extern "C" {
@ -29,10 +28,8 @@ pub fn _getenv(ctx: &mut Ctx, name: u32) -> u32 {
} }
/// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int); /// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int);
pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int { pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, _overwrite: u32) -> c_int {
debug!("emscripten::_setenv"); debug!("emscripten::_setenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name);
let value_addr = emscripten_memory_pointer!(ctx.memory(0), value);
// setenv does not exist on windows, so we hack it with _putenv // setenv does not exist on windows, so we hack it with _putenv
let name = read_string_from_wasm(ctx.memory(0), name); let name = read_string_from_wasm(ctx.memory(0), name);
let value = read_string_from_wasm(ctx.memory(0), value); let value = read_string_from_wasm(ctx.memory(0), value);
@ -47,17 +44,16 @@ pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int {
/// emscripten: _putenv // (name: *const char); /// emscripten: _putenv // (name: *const char);
pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int {
debug!("emscripten::_putenv"); debug!("emscripten::_putenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char;
debug!("=> name({:?})", unsafe {
debug!("=> name({:?})", unsafe { CStr::from_ptr(name_addr) }); std::ffi::CStr::from_ptr(name_addr)
});
unsafe { putenv(name_addr) } unsafe { putenv(name_addr) }
} }
/// emscripten: _unsetenv // (name: *const char); /// emscripten: _unsetenv // (name: *const char);
pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int { pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int {
debug!("emscripten::_unsetenv"); debug!("emscripten::_unsetenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name);
let name = read_string_from_wasm(ctx.memory(0), name); let name = read_string_from_wasm(ctx.memory(0), name);
// no unsetenv on windows, so use putenv with an empty value // no unsetenv on windows, so use putenv with an empty value
let unsetenv_string = format!("{}=", name); let unsetenv_string = format!("{}=", name);
@ -70,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int {
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr); debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
#[repr(C)] #[repr(C)]
struct GuestPasswd { struct GuestPasswd {
@ -102,6 +100,8 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr); debug!("emscripten::_getgrnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
#[repr(C)] #[repr(C)]
struct GuestGroup { struct GuestGroup {
@ -126,6 +126,8 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long { pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long {
debug!("emscripten::_sysconf {}", name); debug!("emscripten::_sysconf {}", name);
#[cfg(not(feature = "debug"))]
let _ = name;
// stub because sysconf is not valid on windows // stub because sysconf is not valid on windows
0 0
} }

@ -1,4 +1,3 @@
use libc::{c_char, c_int};
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
// This may be problematic for msvc which uses inline functions for the printf family // This may be problematic for msvc which uses inline functions for the printf family
@ -15,13 +14,18 @@ use wasmer_runtime_core::vm::Ctx;
//} //}
/// putchar /// putchar
pub fn putchar(ctx: &mut Ctx, chr: i32) { pub fn putchar(_ctx: &mut Ctx, chr: i32) {
unsafe { libc::putchar(chr) }; unsafe { libc::putchar(chr) };
} }
/// printf /// printf
pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra); debug!("emscripten::printf {}, {}", memory_offset, extra);
#[cfg(not(feature = "debug"))]
{
let _ = memory_offset;
let _ = extra;
}
// unsafe { // unsafe {
// let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _; // let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
// _printf(addr, extra) // _printf(addr, extra)

@ -1,10 +1,9 @@
use libc::{abort, c_char, c_int, exit, EAGAIN}; use libc::{abort, c_char, c_int, exit, EAGAIN};
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
use libc::pid_t; type PidT = libc::pid_t;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
type pid_t = c_int; type PidT = c_int;
use std::ffi::CStr; use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
@ -22,7 +21,7 @@ pub fn _abort(_ctx: &mut Ctx) {
} }
} }
pub fn _fork(_ctx: &mut Ctx) -> pid_t { pub fn _fork(_ctx: &mut Ctx) -> PidT {
debug!("emscripten::_fork"); debug!("emscripten::_fork");
// unsafe { // unsafe {
// fork() // fork()

@ -15,7 +15,7 @@ pub struct StdioCapturer {
use libc::{STDERR_FILENO, STDOUT_FILENO}; use libc::{STDERR_FILENO, STDOUT_FILENO};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
const STDIN_FILENO: libc::c_int = 0; const _STDIN_FILENO: libc::c_int = 0;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
const STDOUT_FILENO: libc::c_int = 1; const STDOUT_FILENO: libc::c_int = 1;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]

@ -4,18 +4,20 @@ use libc::mkdir;
use libc::open; use libc::open;
use rand::Rng; use rand::Rng;
use std::env; use std::env;
use std::ffi::CStr;
use std::ffi::CString; use std::ffi::CString;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use std::os::raw::c_int; use std::os::raw::c_int;
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
#[allow(non_camel_case_types)]
type pid_t = c_int; type pid_t = c_int;
/// open /// open
pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall5 (open) {}", which); debug!("emscripten::___syscall5 (open) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
let pathname: u32 = varargs.get(ctx); let pathname: u32 = varargs.get(ctx);
let flags: i32 = varargs.get(ctx); let flags: i32 = varargs.get(ctx);
let mode: u32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx);
@ -33,7 +35,7 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
let mut urandom_file = File::create(tmp_dir).unwrap(); let mut urandom_file = File::create(tmp_dir).unwrap();
// create some random bytes and put them into the file // create some random bytes and put them into the file
let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); let random_bytes = rand::thread_rng().gen::<[u8; 32]>();
urandom_file.write_all(&random_bytes); let _ = urandom_file.write_all(&random_bytes).unwrap();
// put the file path string into wasm memory // put the file path string into wasm memory
let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx, ptr) }; let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx, ptr) };
let raw_pointer_to_urandom_file = let raw_pointer_to_urandom_file =
@ -57,16 +59,19 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
} }
// chown // chown
pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", which); debug!("emscripten::___syscall212 (chown) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
// mkdir // mkdir
pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall39 (mkdir) {}", which); debug!("emscripten::___syscall39 (mkdir) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
let pathname: u32 = varargs.get(ctx); let pathname: u32 = varargs.get(ctx);
let mode: u32 = varargs.get(ctx);
let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8;
unsafe { mkdir(pathname_addr) } unsafe { mkdir(pathname_addr) }
} }
@ -85,59 +90,73 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
} }
/// dup3 /// dup3
pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall330 (dup3)"); debug!("emscripten::___syscall330 (dup3)");
-1 -1
} }
/// ioctl /// ioctl
pub fn ___syscall54(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall54 (ioctl) {}", which); debug!("emscripten::___syscall54 (ioctl) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
// socketcall // socketcall
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall102 (socketcall) {}", which); debug!("emscripten::___syscall102 (socketcall) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
// pread // pread
pub fn ___syscall180(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall180 (pread) {}", which); debug!("emscripten::___syscall180 (pread) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
// pwrite // pwrite
pub fn ___syscall181(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall181 (pwrite) {}", which); debug!("emscripten::___syscall181 (pwrite) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
/// wait4 /// wait4
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { pub fn ___syscall114(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall114 (wait4)"); debug!("emscripten::___syscall114 (wait4)");
-1 -1
} }
// select // select
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall142(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall142 (newselect) {}", which); debug!("emscripten::___syscall142 (newselect) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
// setpgid // setpgid
pub fn ___syscall57(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall57 (setpgid) {}", which); debug!("emscripten::___syscall57 (setpgid) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }
/// uname /// uname
// NOTE: Wondering if we should return custom utsname, like Emscripten. // NOTE: Wondering if we should return custom utsname, like Emscripten.
pub fn ___syscall122(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall122 (uname) {}", which); debug!("emscripten::___syscall122 (uname) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
-1 -1
} }

@ -10,6 +10,7 @@ use libc::{clockid_t, time as libc_time};
use libc::time_t; use libc::time_t;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
#[allow(non_camel_case_types)]
type clockid_t = c_int; type clockid_t = c_int;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]

@ -90,6 +90,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a
(offset, slice) (offset, slice)
} }
#[cfg(not(target_os = "windows"))]
pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 { pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 {
let _total_num = { let _total_num = {
let mut ptr = cstrs; let mut ptr = cstrs;

@ -284,6 +284,7 @@ impl Clone for UnsharedMemory {
} }
pub struct SharedMemory { pub struct SharedMemory {
#[allow(dead_code)]
desc: MemoryDescriptor, desc: MemoryDescriptor,
} }

@ -67,16 +67,16 @@ uint8_t callProtected(trampoline_t trampoline,
savedStackPointer = get_callee_frame_address(); savedStackPointer = get_callee_frame_address();
trampoline(ctx, func, param_vec, return_vec); trampoline(ctx, func, param_vec, return_vec);
out_result->code = 0; out_result->code = 0;
out_result->exceptionAddress = 0; out_result->exception_address = 0;
out_result->instructionPointer = 0; out_result->instruction_pointer = 0;
removeExceptionHandler(); removeExceptionHandler();
return TRUE; return TRUE;
} }
out_result->code = (uint64_t)signum; out_result->code = (uint64_t)signum;
out_result->exceptionAddress = (uint64_t)caughtExceptionAddress; out_result->exception_address = (uint64_t)caughtExceptionAddress;
out_result->instructionPointer = caughtInstructionPointer; out_result->instruction_pointer = caughtInstructionPointer;
caughtExceptionAddress = 0; caughtExceptionAddress = 0;
caughtInstructionPointer = 0; caughtInstructionPointer = 0;

@ -10,8 +10,8 @@ typedef void(*trampoline_t)(struct wasmer_instance_context_t*, const struct fun
struct call_protected_result_t { struct call_protected_result_t {
uint64_t code; uint64_t code;
uint64_t exceptionAddress; uint64_t exception_address;
uint64_t instructionPointer; uint64_t instruction_pointer;
}; };
uint8_t callProtected( uint8_t callProtected(

@ -7,8 +7,8 @@ type CallProtectedResult = Result<(), CallProtectedData>;
#[repr(C)] #[repr(C)]
pub struct CallProtectedData { pub struct CallProtectedData {
pub code: u64, pub code: u64,
pub exceptionAddress: u64, pub exception_address: u64,
pub instructionPointer: u64, pub instruction_pointer: u64,
} }
extern "C" { extern "C" {
@ -32,8 +32,8 @@ pub fn _call_protected(
) -> CallProtectedResult { ) -> CallProtectedResult {
let mut out_result = CallProtectedData { let mut out_result = CallProtectedData {
code: 0, code: 0,
exceptionAddress: 0, exception_address: 0,
instructionPointer: 0, instruction_pointer: 0,
}; };
let result = unsafe { let result = unsafe {
__call_protected( __call_protected(